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
24836acd
Commit
24836acd
authored
Feb 21, 2022
by
Max Woolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend reviewer suggestions applied
parent
6d982667
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
6 deletions
+27
-6
app/finders/personal_access_tokens_finder.rb
app/finders/personal_access_tokens_finder.rb
+10
-0
ee/app/controllers/concerns/credentials_inventory_actions.rb
ee/app/controllers/concerns/credentials_inventory_actions.rb
+1
-1
spec/finders/personal_access_tokens_finder_spec.rb
spec/finders/personal_access_tokens_finder_spec.rb
+16
-5
No files found.
app/finders/personal_access_tokens_finder.rb
View file @
24836acd
...
...
@@ -17,6 +17,7 @@ class PersonalAccessTokensFinder
tokens
=
by_users
(
tokens
)
tokens
=
by_impersonation
(
tokens
)
tokens
=
by_state
(
tokens
)
tokens
=
by_owner_type
(
tokens
)
sort
(
tokens
)
end
...
...
@@ -32,6 +33,15 @@ class PersonalAccessTokensFinder
tokens
end
def
by_owner_type
(
tokens
)
case
@params
[
:owner_type
]
when
'human'
tokens
.
owner_is_human
else
tokens
end
end
def
by_user
(
tokens
)
return
tokens
unless
@params
[
:user
]
...
...
ee/app/controllers/concerns/credentials_inventory_actions.rb
View file @
24836acd
...
...
@@ -49,7 +49,7 @@ module CredentialsInventoryActions
def
filter_credentials
if
show_personal_access_tokens?
::
PersonalAccessTokensFinder
.
new
({
users:
users
,
impersonation:
false
,
sort:
'id_desc'
}).
execute
.
owner_is_human
::
PersonalAccessTokensFinder
.
new
({
users:
users
,
impersonation:
false
,
sort:
'id_desc'
,
owner_type:
'human'
}).
execute
elsif
show_ssh_keys?
::
KeysFinder
.
new
({
users:
users
,
key_type:
'ssh'
}).
execute
elsif
show_project_access_tokens?
...
...
spec/finders/personal_access_tokens_finder_spec.rb
View file @
24836acd
...
...
@@ -17,6 +17,9 @@ RSpec.describe PersonalAccessTokensFinder do
let!
(
:active_impersonation_token
)
{
create
(
:personal_access_token
,
:impersonation
,
user:
user
)
}
let!
(
:expired_impersonation_token
)
{
create
(
:personal_access_token
,
:expired
,
:impersonation
,
user:
user
)
}
let!
(
:revoked_impersonation_token
)
{
create
(
:personal_access_token
,
:revoked
,
:impersonation
,
user:
user
)
}
let!
(
:project_bot
)
{
create
(
:user
,
:project_bot
)
}
let!
(
:project_member
)
{
create
(
:project_member
,
user:
project_bot
)
}
let!
(
:project_access_token
)
{
create
(
:personal_access_token
,
user:
project_bot
)
}
subject
{
finder
(
params
,
current_user
).
execute
}
...
...
@@ -44,7 +47,7 @@ RSpec.describe PersonalAccessTokensFinder do
it
do
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
active_impersonation_token
,
revoked_personal_access_token
,
expired_personal_access_token
,
revoked_impersonation_token
,
expired_impersonation_token
)
revoked_impersonation_token
,
expired_impersonation_token
,
project_access_token
)
end
context
'when current_user is not an administrator'
do
...
...
@@ -59,7 +62,7 @@ RSpec.describe PersonalAccessTokensFinder do
it
do
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
active_impersonation_token
,
revoked_personal_access_token
,
expired_personal_access_token
,
revoked_impersonation_token
,
expired_impersonation_token
)
revoked_impersonation_token
,
expired_impersonation_token
,
project_access_token
)
end
describe
'with users'
do
...
...
@@ -98,14 +101,14 @@ RSpec.describe PersonalAccessTokensFinder do
params
[
:impersonation
]
=
false
end
it
{
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
revoked_personal_access_token
,
expired_personal_access_token
)
}
it
{
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
revoked_personal_access_token
,
expired_personal_access_token
,
project_access_token
)
}
describe
'with active state'
do
before
do
params
[
:state
]
=
'active'
end
it
{
is_expected
.
to
contain_exactly
(
active_personal_access_token
)
}
it
{
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
project_access_token
)
}
end
describe
'with inactive state'
do
...
...
@@ -146,7 +149,7 @@ RSpec.describe PersonalAccessTokensFinder do
params
[
:state
]
=
'active'
end
it
{
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
active_impersonation_token
)
}
it
{
is_expected
.
to
contain_exactly
(
active_personal_access_token
,
active_impersonation_token
,
project_access_token
)
}
end
describe
'with inactive state'
do
...
...
@@ -208,6 +211,14 @@ RSpec.describe PersonalAccessTokensFinder do
revoked_impersonation_token
,
expired_impersonation_token
)
end
describe
'filtering human tokens'
do
before
do
params
[
:owner_type
]
=
'human'
end
it
{
is_expected
.
not_to
include
(
project_access_token
)
}
end
describe
'without impersonation'
do
before
do
params
[
:impersonation
]
=
false
...
...
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