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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
dd8e7ede
Commit
dd8e7ede
authored
May 30, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve specs for `geo/oauth_session`
parent
ded62383
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
14 deletions
+19
-14
ee/spec/lib/gitlab/geo/oauth_session_spec.rb
ee/spec/lib/gitlab/geo/oauth_session_spec.rb
+19
-14
No files found.
ee/spec/lib/gitlab/geo/oauth_session_spec.rb
View file @
dd8e7ede
...
...
@@ -3,14 +3,14 @@ require 'spec_helper'
describe
Gitlab
::
Geo
::
OauthSession
do
subject
{
described_class
.
new
}
let
(
:oauth_app
)
{
FactoryBot
.
create
(
:doorkeeper_application
)
}
let
(
:oauth_return_to
)
{
'http://
localhost:3000
/oauth/geo/callback'
}
let
(
:oauth_return_to
)
{
'http://
secondary
/oauth/geo/callback'
}
let
(
:dummy_state
)
{
'salt:hmac:return_to'
}
let
(
:valid_state
)
{
described_class
.
new
(
return_to:
oauth_return_to
).
generate_oauth_state
}
let
(
:access_token
)
{
FactoryBot
.
create
(
:doorkeeper_access_token
).
token
}
before
do
allow
(
subject
).
to
receive
(
:oauth_app
)
{
oauth_app
}
allow
(
subject
).
to
receive
(
:primary_node_url
)
{
'http://
localhost:3001
/'
}
allow
(
subject
).
to
receive
(
:primary_node_url
)
{
'http://
primary
/'
}
end
describe
'#oauth_state_valid?'
do
...
...
@@ -107,31 +107,36 @@ describe Gitlab::Geo::OauthSession do
it
'returns a valid url'
do
expect
(
subject
.
authorize_url
).
to
be_a
String
expect
(
subject
.
authorize_url
).
to
include
(
'http://
localhost:3001
/'
)
expect
(
subject
.
authorize_url
).
to
include
(
'http://
primary
/'
)
end
end
describe
'#authenticate_with_gitlab'
do
let
(
:response
)
{
double
}
let
(
:api_url
)
{
'http://primary/api/v4/user'
}
let
(
:user_json
)
{
ActiveSupport
::
JSON
.
encode
({
id:
555
,
email:
'user@example.com'
}.
as_json
)
}
context
'on success'
do
before
do
allow_any_instance_of
(
OAuth2
::
AccessToken
).
to
receive
(
:get
)
{
response
}
stub_request
(
:get
,
api_url
).
to_return
(
body:
user_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
end
context
'on success'
do
it
'returns hashed user data'
do
allow
(
response
).
to
receive
(
:status
)
{
200
}
allow
(
response
).
to
receive
(
:parsed
)
{
attributes_for
(
:user
)
}
parsed_json
=
JSON
.
parse
(
user_json
)
subject
.
authenticate_with_gitlab
(
access_toke
n
)
expect
(
subject
.
authenticate_with_gitlab
(
access_token
)).
to
eq
(
parsed_jso
n
)
end
end
context
'on invalid token'
do
it
'raises exception'
do
allow
(
response
).
to
receive
(
:status
)
{
401
}
before
do
stub_request
(
:get
,
api_url
).
to_return
(
status:
[
401
,
"Unauthorized"
])
end
expect
{
subject
.
authenticate_with_gitlab
(
access_token
)
}.
to
raise_error
it
'raises exception'
do
expect
{
subject
.
authenticate_with_gitlab
(
access_token
)
}.
to
raise_error
(
OAuth2
::
Error
)
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