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
a26714ca
Commit
a26714ca
authored
Mar 14, 2022
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address MR review comments
parent
3cc8ae45
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
45 deletions
+22
-45
app/services/ci/runners/reset_registration_token_service.rb
app/services/ci/runners/reset_registration_token_service.rb
+1
-3
spec/services/ci/runners/reset_registration_token_service_spec.rb
...vices/ci/runners/reset_registration_token_service_spec.rb
+21
-42
No files found.
app/services/ci/runners/reset_registration_token_service.rb
View file @
a26714ca
...
...
@@ -11,7 +11,7 @@ module Ci
end
def
execute
return
false
unless
@user
.
present?
&&
@user
.
can?
(
:update_runners_registration_token
,
scope
)
return
unless
@user
.
present?
&&
@user
.
can?
(
:update_runners_registration_token
,
scope
)
case
scope
when
::
ApplicationSetting
...
...
@@ -29,5 +29,3 @@ module Ci
end
end
end
Ci
::
Runners
::
AssignRunnerService
.
prepend_mod
spec/services/ci/runners/reset_registration_token_service_spec.rb
View file @
a26714ca
...
...
@@ -6,26 +6,26 @@ RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute' do
subject
{
described_class
.
new
(
scope
,
current_user
).
execute
}
let_it_be
(
:user
)
{
build
(
:user
)
}
let_it_be
(
:admin_user
)
{
create
_default
(
:user
,
:admin
)
}
let_it_be
(
:admin_user
)
{
create
(
:user
,
:admin
)
}
shared_examples
'a registration token reset operation'
do
context
'without user'
do
let
(
:current_user
)
{
nil
}
it
'does not reset registration token and returns
false
'
do
expect
(
scope
).
not_to
receive
(
:reset_runners_token!
)
it
'does not reset registration token and returns
nil
'
do
expect
(
scope
).
not_to
receive
(
token_reset_method_name
)
is_expected
.
to
eq
(
false
)
is_expected
.
to
be_nil
end
end
context
'with unauthorized user'
do
let
(
:current_user
)
{
user
}
it
'does not reset registration token and returns
false
'
do
expect
(
scope
).
not_to
receive
(
:reset_runners_token!
)
it
'does not reset registration token and returns
nil
'
do
expect
(
scope
).
not_to
receive
(
token_reset_method_name
)
is_expected
.
to
eq
(
false
)
is_expected
.
to
be_nil
end
end
...
...
@@ -33,11 +33,11 @@ RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute' do
let
(
:current_user
)
{
admin_user
}
it
'resets registration token and returns value unchanged'
do
expect
(
scope
).
to
receive
(
:reset_runners_token!
).
once
do
expect
(
scope
).
to
receive
(
:runners_token
).
once
.
and_return
(
'runners_token return value'
)
expect
(
scope
).
to
receive
(
token_reset_method_name
).
once
do
expect
(
scope
).
to
receive
(
token_method_name
).
once
.
and_return
(
"
#{
token_method_name
}
return value"
)
end
is_expected
.
to
eq
(
'runners_token return value'
)
is_expected
.
to
eq
(
"
#{
token_method_name
}
return value"
)
end
end
end
...
...
@@ -50,48 +50,27 @@ RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute' do
allow
(
ApplicationSetting
).
to
receive
(
:current_without_cache
).
and_return
(
scope
)
end
context
'without user'
do
let
(
:current_user
)
{
nil
}
it
'does not reset registration token and returns false'
do
expect
(
scope
).
not_to
receive
(
:reset_runners_registration_token!
)
is_expected
.
to
eq
(
false
)
end
end
context
'with unauthorized user'
do
let
(
:current_user
)
{
user
}
it
'calls assign_to on runner and returns value unchanged'
do
expect
(
scope
).
not_to
receive
(
:reset_runners_registration_token!
)
is_expected
.
to
eq
(
false
)
end
end
context
'with admin user'
,
:enable_admin_mode
do
let
(
:current_user
)
{
admin_user
}
it
'resets registration token and returns value unchanged'
do
expect
(
scope
).
to
receive
(
:reset_runners_registration_token!
).
once
do
expect
(
scope
).
to
receive
(
:runners_registration_token
).
once
.
and_return
(
'runners_registration_token return value'
)
end
is_expected
.
to
eq
(
'runners_registration_token return value'
)
end
it_behaves_like
'a registration token reset operation'
do
let
(
:token_method_name
)
{
:runners_registration_token
}
let
(
:token_reset_method_name
)
{
:reset_runners_registration_token!
}
end
end
context
'with group scope'
do
let_it_be
(
:scope
)
{
create
(
:group
)
}
it_behaves_like
'a registration token reset operation'
it_behaves_like
'a registration token reset operation'
do
let
(
:token_method_name
)
{
:runners_token
}
let
(
:token_reset_method_name
)
{
:reset_runners_token!
}
end
end
context
'with project scope'
do
let_it_be
(
:scope
)
{
create
(
:project
)
}
it_behaves_like
'a registration token reset operation'
it_behaves_like
'a registration token reset operation'
do
let
(
:token_method_name
)
{
:runners_token
}
let
(
:token_reset_method_name
)
{
:reset_runners_token!
}
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