Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
a31cdb29
Commit
a31cdb29
authored
Dec 15, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve session tests
parent
f11caaf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
45 deletions
+74
-45
lib/mattermost/session.rb
lib/mattermost/session.rb
+6
-3
spec/lib/mattermost/mattermost_spec.rb
spec/lib/mattermost/mattermost_spec.rb
+0
-42
spec/lib/mattermost/session_spec.rb
spec/lib/mattermost/session_spec.rb
+68
-0
No files found.
lib/mattermost/
mattermost
.rb
→
lib/mattermost/
session
.rb
View file @
a31cdb29
...
@@ -13,13 +13,14 @@ module Mattermost
...
@@ -13,13 +13,14 @@ module Mattermost
# This class however skips the button click, and also the approval phase to
# This class however skips the button click, and also the approval phase to
# speed up the process and keep it without manual action and get a session
# speed up the process and keep it without manual action and get a session
# going.
# going.
class
Mattermost
class
Session
include
Doorkeeper
::
Helpers
::
Controller
include
Doorkeeper
::
Helpers
::
Controller
include
HTTParty
include
HTTParty
attr_accessor
:current_resource_owner
attr_accessor
:current_resource_owner
def
initialize
(
uri
,
current_user
)
def
initialize
(
uri
,
current_user
)
# Sets the base uri for HTTParty, so we can use paths
self
.
class
.
base_uri
(
uri
)
self
.
class
.
base_uri
(
uri
)
@current_resource_owner
=
current_user
@current_resource_owner
=
current_user
...
@@ -27,8 +28,10 @@ module Mattermost
...
@@ -27,8 +28,10 @@ module Mattermost
def
with_session
def
with_session
raise
NoSessionError
unless
create
raise
NoSessionError
unless
create
yield
result
=
yield
destroy
destroy
result
end
end
# Next methods are needed for Doorkeeper
# Next methods are needed for Doorkeeper
...
@@ -85,7 +88,7 @@ module Mattermost
...
@@ -85,7 +88,7 @@ module Mattermost
end
end
def
request_token
def
request_token
@request_token
||=
if
@token_uri
@request_token
||=
begin
response
=
get
(
@token_uri
,
follow_redirects:
false
)
response
=
get
(
@token_uri
,
follow_redirects:
false
)
response
.
headers
[
'token'
]
if
200
<=
response
.
code
&&
response
.
code
<
400
response
.
headers
[
'token'
]
if
200
<=
response
.
code
&&
response
.
code
<
400
end
end
...
...
spec/lib/mattermost/mattermost_spec.rb
deleted
100644 → 0
View file @
f11caaf4
require
'spec_helper'
describe
Mattermost
::
Mattermost
do
let
(
:user
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
'http://localhost:8065'
,
user
)
}
# Needed for doorman to function
it
{
is_expected
.
to
respond_to
(
:current_resource_owner
)
}
it
{
is_expected
.
to
respond_to
(
:request
)
}
it
{
is_expected
.
to
respond_to
(
:authorization
)
}
it
{
is_expected
.
to
respond_to
(
:strategy
)
}
describe
'#with session'
do
let!
(
:stub
)
do
WebMock
.
stub_request
(
:get
,
'http://localhost:8065/api/v3/oauth/gitlab/login'
).
to_return
(
headers:
{
'location'
=>
'http://mylocation.com'
},
status:
307
)
end
context
'without oauth uri'
do
it
'makes a request to the oauth uri'
do
expect
{
subject
.
with_session
}.
to
raise_error
(
Mattermost
::
NoSessionError
)
end
context
'with oauth_uri'
do
let!
(
:doorkeeper
)
do
Doorkeeper
::
Application
.
create
(
name:
"GitLab Mattermost"
,
redirect_uri:
"http://localhost:8065/signup/gitlab/complete
\n
http://localhost:8065/login/gitlab/complete"
,
scopes:
""
)
end
context
'without token_uri'
do
it
'can not create a session'
do
expect
do
subject
.
with_session
end
.
to
raise_error
(
Mattermost
::
NoSessionError
)
end
end
end
end
end
end
spec/lib/mattermost/session_spec.rb
0 → 100644
View file @
a31cdb29
require
'spec_helper'
describe
Mattermost
::
Session
do
let
(
:user
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
'http://localhost:8065'
,
user
)
}
# Needed for doorkeeper to function
it
{
is_expected
.
to
respond_to
(
:current_resource_owner
)
}
it
{
is_expected
.
to
respond_to
(
:request
)
}
it
{
is_expected
.
to
respond_to
(
:authorization
)
}
it
{
is_expected
.
to
respond_to
(
:strategy
)
}
describe
'#with session'
do
let
(
:location
)
{
'http://location.tld'
}
let!
(
:stub
)
do
WebMock
.
stub_request
(
:get
,
'http://localhost:8065/api/v3/oauth/gitlab/login'
).
to_return
(
headers:
{
'location'
=>
location
},
status:
307
)
end
context
'without oauth uri'
do
it
'makes a request to the oauth uri'
do
expect
{
subject
.
with_session
}.
to
raise_error
(
Mattermost
::
NoSessionError
)
end
end
context
'with oauth_uri'
do
let!
(
:doorkeeper
)
do
Doorkeeper
::
Application
.
create
(
name:
"GitLab Mattermost"
,
redirect_uri:
"http://localhost:8065/signup/gitlab/complete
\n
http://localhost:8065/login/gitlab/complete"
,
scopes:
""
)
end
context
'without token_uri'
do
it
'can not create a session'
do
expect
do
subject
.
with_session
end
.
to
raise_error
(
Mattermost
::
NoSessionError
)
end
end
context
'with token_uri'
do
let
(
:state
)
{
"eyJhY3Rpb24iOiJsb2dpbiIsImhhc2giOiIkMmEkMTAkVC9wYVlEaTdIUS8vcWdKRmdOOUllZUptaUNJWUlvNVNtNEcwU2NBMXFqelNOVmVPZ1cxWUsifQ%3D%3D"
}
let
(
:location
)
{
"http://locahost:8065/oauth/authorize?response_type=code&client_id=
#{
doorkeeper
.
uid
}
&redirect_uri=http%3A%2F%2Flocalhost:8065%2Fsignup%2Fgitlab%2Fcomplete&state=
#{
state
}
"
}
before
do
WebMock
.
stub_request
(
:get
,
/http:\/\/localhost:8065\/signup\/gitlab\/complete*/
).
to_return
(
headers:
{
'token'
=>
'thisworksnow'
},
status:
202
)
end
it
'can setup a session'
do
expect
(
subject
).
to
receive
(
:destroy
)
subject
.
with_session
{
1
+
1
}
end
it
'returns the value of the block'
do
WebMock
.
stub_request
(
:post
,
"http://localhost:8065/api/v3/users/logout"
).
to_return
(
headers:
{
'token'
=>
'thisworksnow'
},
status:
200
)
value
=
subject
.
with_session
{
1
+
1
}
expect
(
value
).
to
be
(
2
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment