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
e1d060e3
Commit
e1d060e3
authored
Sep 27, 2021
by
Andrejs Cunskis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
E2E: Do not assign nil value to token attribute when creating PAT
parent
369af359
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
32 deletions
+49
-32
qa/qa/resource/personal_access_token.rb
qa/qa/resource/personal_access_token.rb
+5
-3
qa/qa/runtime/api/client.rb
qa/qa/runtime/api/client.rb
+44
-29
No files found.
qa/qa/resource/personal_access_token.rb
View file @
e1d060e3
...
@@ -8,7 +8,7 @@ module QA
...
@@ -8,7 +8,7 @@ module QA
attr_accessor
:name
attr_accessor
:name
# The user for which the personal access token is to be created
# The user for which the personal access token is to be created
# This *could* be different than the api_client.user or the api_user provided by the QA::Resource::ApiFabricator
module
# This *could* be different than the api_client.user or the api_user provided by the QA::Resource::ApiFabricator
attr_writer
:user
attr_writer
:user
attribute
:token
attribute
:token
...
@@ -17,7 +17,9 @@ module QA
...
@@ -17,7 +17,9 @@ module QA
# If Runtime::Env.admin_personal_access_token is provided, fabricate via the API,
# If Runtime::Env.admin_personal_access_token is provided, fabricate via the API,
# else, fabricate via the browser.
# else, fabricate via the browser.
def
fabricate_via_api!
def
fabricate_via_api!
@token
=
QA
::
Resource
::
PersonalAccessTokenCache
.
get_token_for_username
(
user
.
username
)
QA
::
Resource
::
PersonalAccessTokenCache
.
get_token_for_username
(
user
.
username
).
tap
do
|
cached_token
|
@token
=
cached_token
if
cached_token
end
return
if
@token
return
if
@token
resource
=
if
Runtime
::
Env
.
admin_personal_access_token
&&
!
@user
.
nil?
resource
=
if
Runtime
::
Env
.
admin_personal_access_token
&&
!
@user
.
nil?
...
@@ -28,7 +30,7 @@ module QA
...
@@ -28,7 +30,7 @@ module QA
fabricate!
fabricate!
end
end
QA
::
Resource
::
PersonalAccessTokenCache
.
set_token_for_username
(
user
.
username
,
self
.
token
)
QA
::
Resource
::
PersonalAccessTokenCache
.
set_token_for_username
(
user
.
username
,
token
)
resource
resource
end
end
...
...
qa/qa/runtime/api/client.rb
View file @
e1d060e3
...
@@ -16,17 +16,21 @@ module QA
...
@@ -16,17 +16,21 @@ module QA
enable_ip_limits
if
ip_limits
enable_ip_limits
if
ip_limits
end
end
# Personal access token
#
# It is possible to set the environment variable GITLAB_QA_ACCESS_TOKEN
# to use a specific access token rather than create one from the UI
# unless a specific user has been passed
#
# @return [String]
def
personal_access_token
def
personal_access_token
@personal_access_token
||=
begin
@personal_access_token
||=
if
user
.
nil?
# you can set the environment variable GITLAB_QA_ACCESS_TOKEN
Runtime
::
Env
.
personal_access_token
||=
create_personal_access_token
# to use a specific access token rather than create one from the UI
else
# unless a specific user has been passed
create_personal_access_token
@user
.
nil?
?
Runtime
::
Env
.
personal_access_token
||=
create_personal_access_token
:
create_personal_access_token
end
end
if
@user
&
.
admin?
Runtime
::
Env
.
admin_personal_access_token
=
@personal_access_token
if
user
&
.
admin?
# rubocop:disable Cop/UserAdmin
Runtime
::
Env
.
admin_personal_access_token
=
@personal_access_token
end
@personal_access_token
@personal_access_token
end
end
...
@@ -82,27 +86,38 @@ module QA
...
@@ -82,27 +86,38 @@ module QA
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
end
end
# Create PAT
#
# Use api if admin personal access token is present and skip any UI actions otherwise perform creation via UI
#
# @return [String]
def
create_personal_access_token
def
create_personal_access_token
signed_in_initially
=
Page
::
Main
::
Menu
.
perform
(
&
:signed_in?
)
if
Runtime
::
Env
.
admin_personal_access_token
Resource
::
PersonalAccessToken
.
fabricate_via_api!
do
|
pat
|
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
if
@is_new_session
&&
signed_in_initially
pat
.
user
=
user
end
.
token
token
=
Resource
::
PersonalAccessToken
.
fabricate!
do
|
pat
|
else
pat
.
user
=
user
signed_in_initially
=
Page
::
Main
::
Menu
.
perform
(
&
:signed_in?
)
end
.
token
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
if
@is_new_session
&&
signed_in_initially
# If this is a new session, that tests that follow could fail if they
# try to sign in without starting a new session.
token
=
Resource
::
PersonalAccessToken
.
fabricate!
do
|
pat
|
# Also, if the browser wasn't already signed in, leaving it
pat
.
user
=
user
# signed in could cause tests to fail when they try to sign
end
.
token
# in again. For example, that would happen if a test has a
# before(:context) block that fabricates via the API, and
# If this is a new session, that tests that follow could fail if they
# it's the first test to run so it creates an access token
# try to sign in without starting a new session.
#
# Also, if the browser wasn't already signed in, leaving it
# Sign out so the tests can successfully sign in
# signed in could cause tests to fail when they try to sign
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
if
@is_new_session
||
!
signed_in_initially
# in again. For example, that would happen if a test has a
# before(:context) block that fabricates via the API, and
token
# it's the first test to run so it creates an access token
#
# Sign out so the tests can successfully sign in
Page
::
Main
::
Menu
.
perform
(
&
:sign_out
)
if
@is_new_session
||
!
signed_in_initially
token
end
end
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