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
Léo-Paul Géneau
gitlab-ce
Commits
43337c12
Commit
43337c12
authored
Jun 15, 2017
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test the "Remember Me" flow for OAuth-based login.
parent
e936db96
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
3 deletions
+68
-3
spec/features/oauth_login_spec.rb
spec/features/oauth_login_spec.rb
+59
-2
spec/support/capybara_helpers.rb
spec/support/capybara_helpers.rb
+5
-0
spec/support/login_helpers.rb
spec/support/login_helpers.rb
+4
-1
No files found.
spec/features/oauth_login_spec.rb
View file @
43337c12
...
@@ -19,7 +19,7 @@ feature 'OAuth Login', feature: true, js: true do
...
@@ -19,7 +19,7 @@ feature 'OAuth Login', feature: true, js: true do
providers
=
[
:github
,
:twitter
,
:bitbucket
,
:gitlab
,
:google_oauth2
,
:facebook
]
providers
=
[
:github
,
:twitter
,
:bitbucket
,
:gitlab
,
:google_oauth2
,
:facebook
]
before
do
before
do
OmniAuth
.
config
.
full_host
=
->
(
request
)
{
request
[
'REQUEST_URI'
].
sub
(
request
[
'REQUEST_PATH'
]
,
''
)
}
OmniAuth
.
config
.
full_host
=
->
(
request
)
{
request
[
'REQUEST_URI'
].
sub
(
/
#{
request
[
'REQUEST_PATH'
]
}
.*/
,
''
)
}
messages
=
{
messages
=
{
enabled:
true
,
enabled:
true
,
...
@@ -39,7 +39,6 @@ feature 'OAuth Login', feature: true, js: true do
...
@@ -39,7 +39,6 @@ feature 'OAuth Login', feature: true, js: true do
login_via
(
provider
.
to_s
,
user
,
'my-uid'
)
login_via
(
provider
.
to_s
,
user
,
'my-uid'
)
expect
(
current_path
).
to
eq
root_path
expect
(
current_path
).
to
eq
root_path
save_screenshot
end
end
end
end
...
@@ -53,6 +52,64 @@ feature 'OAuth Login', feature: true, js: true do
...
@@ -53,6 +52,64 @@ feature 'OAuth Login', feature: true, js: true do
expect
(
current_path
).
to
eq
root_path
expect
(
current_path
).
to
eq
root_path
end
end
end
end
context
'when "remember me" is checked'
do
context
"when two-factor authentication is disabled"
do
it
'remembers the user after a browser restart'
do
stub_omniauth_config
(
provider
)
user
=
create
(
:omniauth_user
,
extern_uid:
'my-uid'
,
provider:
provider
.
to_s
)
login_via
(
provider
.
to_s
,
user
,
'my-uid'
,
remember_me:
true
)
restart_browser
visit
(
root_path
)
expect
(
current_path
).
to
eq
root_path
end
end
context
"when two-factor authentication is enabled"
do
it
'remembers the user after a browser restart'
do
stub_omniauth_config
(
provider
)
user
=
create
(
:omniauth_user
,
:two_factor
,
extern_uid:
'my-uid'
,
provider:
provider
.
to_s
)
login_via
(
provider
.
to_s
,
user
,
'my-uid'
,
remember_me:
true
)
enter_code
(
user
.
current_otp
)
restart_browser
visit
(
root_path
)
expect
(
current_path
).
to
eq
root_path
end
end
end
context
'when "remember me" is not checked'
do
context
"when two-factor authentication is disabled"
do
it
'does not remember the user after a browser restart'
do
stub_omniauth_config
(
provider
)
user
=
create
(
:omniauth_user
,
extern_uid:
'my-uid'
,
provider:
provider
.
to_s
)
login_via
(
provider
.
to_s
,
user
,
'my-uid'
,
remember_me:
false
)
restart_browser
visit
(
root_path
)
expect
(
current_path
).
to
eq
new_user_session_path
end
end
context
"when two-factor authentication is enabled"
do
it
'remembers the user after a browser restart'
do
stub_omniauth_config
(
provider
)
user
=
create
(
:omniauth_user
,
:two_factor
,
extern_uid:
'my-uid'
,
provider:
provider
.
to_s
)
login_via
(
provider
.
to_s
,
user
,
'my-uid'
,
remember_me:
false
)
enter_code
(
user
.
current_otp
)
restart_browser
visit
(
root_path
)
expect
(
current_path
).
to
eq
new_user_session_path
end
end
end
end
end
end
end
end
end
spec/support/capybara_helpers.rb
View file @
43337c12
...
@@ -35,6 +35,11 @@ module CapybaraHelpers
...
@@ -35,6 +35,11 @@ module CapybaraHelpers
visit
'about:blank'
visit
'about:blank'
visit
url
visit
url
end
end
# Simulate a browser restart by clearing the session cookie.
def
restart_browser
page
.
driver
.
remove_cookie
(
'_gitlab_session'
)
end
end
end
RSpec
.
configure
do
|
config
|
RSpec
.
configure
do
|
config
|
...
...
spec/support/login_helpers.rb
View file @
43337c12
...
@@ -62,10 +62,13 @@ module LoginHelpers
...
@@ -62,10 +62,13 @@ module LoginHelpers
Thread
.
current
[
:current_user
]
=
user
Thread
.
current
[
:current_user
]
=
user
end
end
def
login_via
(
provider
,
user
,
uid
)
def
login_via
(
provider
,
user
,
uid
,
remember_me:
false
)
mock_auth_hash
(
provider
,
uid
,
user
.
email
)
mock_auth_hash
(
provider
,
uid
,
user
.
email
)
visit
new_user_session_path
visit
new_user_session_path
expect
(
page
).
to
have_content
(
'Sign in with'
)
expect
(
page
).
to
have_content
(
'Sign in with'
)
check
"Remember Me"
if
remember_me
click_link
"oauth-login-
#{
provider
}
"
click_link
"oauth-login-
#{
provider
}
"
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