Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
a26714ca
Verified
Commit
a26714ca
authored
2 years ago
by
Pedro Pombeiro
Browse files
Options
Downloads
Patches
Plain Diff
Address MR review comments
parent
3cc8ae45
No related branches found
No related tags found
1 merge request
!82721
Extract service to reset runner registration tokens
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/services/ci/runners/reset_registration_token_service.rb
+1
-3
1 addition, 3 deletions
app/services/ci/runners/reset_registration_token_service.rb
spec/services/ci/runners/reset_registration_token_service_spec.rb
+21
-42
21 additions, 42 deletions
...vices/ci/runners/reset_registration_token_service_spec.rb
with
22 additions
and
45 deletions
app/services/ci/runners/reset_registration_token_service.rb
+
1
−
3
View file @
a26714ca
...
...
@@ -11,7 +11,7 @@ def initialize(scope, user)
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 @@ def execute
end
end
end
Ci
::
Runners
::
AssignRunnerService
.
prepend_mod
This diff is collapsed.
Click to expand it.
spec/services/ci/runners/reset_registration_token_service_spec.rb
+
21
−
42
View file @
a26714ca
...
...
@@ -6,26 +6,26 @@
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 @@
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 @@
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment