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
5f4afef6
Commit
5f4afef6
authored
Nov 26, 2020
by
Saikat Sarkar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid unnecessary Sidekiq retries for Security::TokenRevocationService
parent
84947413
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
26 deletions
+34
-26
ee/app/services/security/token_revocation_service.rb
ee/app/services/security/token_revocation_service.rb
+23
-20
ee/changelogs/unreleased/reduce_redundent_api_call.yml
ee/changelogs/unreleased/reduce_redundent_api_call.yml
+5
-0
ee/spec/services/security/token_revocation_service_spec.rb
ee/spec/services/security/token_revocation_service_spec.rb
+6
-6
No files found.
ee/app/services/security/token_revocation_service.rb
View file @
5f4afef6
...
...
@@ -11,7 +11,10 @@ module Security
end
def
execute
raise
RevocationFailedError
,
'Missing revocation token data'
if
missing_token_data?
return
error
(
'Token revocation is disabled'
)
unless
token_revocation_enabled?
return
success
if
revoke_token_body
.
blank?
response
=
revoke_tokens
response
.
success?
?
success
:
error
(
'Failed to revoke tokens'
)
...
...
@@ -29,11 +32,9 @@ module Security
end
def
revoke_tokens
raise
RevocationFailedError
,
'Missing revocation tokens data'
if
missing_token_data?
::
Gitlab
::
HTTP
.
post
(
token_revocation_url
,
body:
message
,
body:
revoke_token_body
,
headers:
{
'Content-Type'
=>
'application/json'
,
'Authorization'
=>
revocation_api_token
...
...
@@ -54,7 +55,8 @@ module Security
)
end
def
message
def
revoke_token_body
@revoke_token_body
||=
begin
response
=
::
Gitlab
::
HTTP
.
get
(
token_types_url
,
headers:
{
...
...
@@ -65,13 +67,14 @@ module Security
raise
RevocationFailedError
,
'Failed to get revocation token types'
unless
response
.
success?
token_types
=
::
Gitlab
::
Json
.
parse
(
response
.
body
)[
'types'
]
raise
RevocationFailedError
,
'No token type is available'
if
token_types
.
blank?
return
if
token_types
.
blank?
@revocable_keys
.
filter!
{
|
key
|
token_types
.
include?
(
key
[
:type
])
}
raise
RevocationFailedError
,
'No revocable key is present'
if
@revocable_keys
.
blank?
return
if
@revocable_keys
.
blank?
@revocable_keys
.
to_json
end
end
def
token_types_url
::
Gitlab
::
CurrentSettings
.
secret_detection_revocation_token_types_url
...
...
ee/changelogs/unreleased/reduce_redundent_api_call.yml
0 → 100644
View file @
5f4afef6
---
title
:
Avoid unnecessary Sidekiq retries for Security::TokenRevocationService
merge_request
:
48636
author
:
type
:
performance
ee/spec/services/security/token_revocation_service_spec.rb
View file @
5f4afef6
...
...
@@ -49,13 +49,13 @@ RSpec.describe Security::TokenRevocationService, '#execute' do
end
end
context
'when revocation token
API returns invalid token
types'
do
context
'when revocation token
types API returns empty list of
types'
do
before
do
stub_application_setting
(
secret_detection_token_revocation_enabled:
true
)
stub_invalid_token_types_api_with_success
end
specify
{
expect
(
subject
).
to
eql
({
message:
'No token type is available'
,
status: :error
})
}
specify
{
expect
(
subject
).
to
eql
({
status: :success
})
}
end
context
'when revocation service is disabled'
do
...
...
@@ -84,7 +84,7 @@ RSpec.describe Security::TokenRevocationService, '#execute' do
end
end
specify
{
expect
(
subject
).
to
eql
({
message:
'Missing revocation token
s
data'
,
status: :error
})
}
specify
{
expect
(
subject
).
to
eql
({
message:
'Missing revocation token data'
,
status: :error
})
}
end
context
'when token_types_url is missing'
do
...
...
@@ -94,7 +94,7 @@ RSpec.describe Security::TokenRevocationService, '#execute' do
end
end
specify
{
expect
(
subject
).
to
eql
({
message:
'Missing revocation token
s
data'
,
status: :error
})
}
specify
{
expect
(
subject
).
to
eql
({
message:
'Missing revocation token data'
,
status: :error
})
}
end
context
'when revocation_api_token is missing'
do
...
...
@@ -104,7 +104,7 @@ RSpec.describe Security::TokenRevocationService, '#execute' do
end
end
specify
{
expect
(
subject
).
to
eql
({
message:
'Missing revocation token
s
data'
,
status: :error
})
}
specify
{
expect
(
subject
).
to
eql
({
message:
'Missing revocation token data'
,
status: :error
})
}
end
context
'when there is no token to be revoked'
do
...
...
@@ -112,7 +112,7 @@ RSpec.describe Security::TokenRevocationService, '#execute' do
{
'types'
:
%w()
}
end
specify
{
expect
(
subject
).
to
eql
({
message:
'No token type is available'
,
status: :error
})
}
specify
{
expect
(
subject
).
to
eql
({
status: :success
})
}
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