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
515c81cf
Commit
515c81cf
authored
Jul 29, 2021
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cr remarks
parent
49f1fc83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
+51
-2
lib/gitlab/auth/result.rb
lib/gitlab/auth/result.rb
+2
-0
spec/lib/gitlab/auth/result_spec.rb
spec/lib/gitlab/auth/result_spec.rb
+49
-2
No files found.
lib/gitlab/auth/result.rb
View file @
515c81cf
...
...
@@ -39,6 +39,8 @@ module Gitlab
end
def
authentication_abilities_include?
(
ability
)
return
false
if
authentication_abilities
.
blank?
authentication_abilities
.
include?
(
ability
)
end
end
...
...
spec/lib/gitlab/auth/result_spec.rb
View file @
515c81cf
...
...
@@ -3,10 +3,11 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Auth
::
Result
do
let_it_be
(
:actor
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
actor
,
nil
,
nil
,
[])
}
context
'when actor is User'
do
let
(
:actor
)
{
create
(
:user
)
}
let
_it_be
(
:actor
)
{
create
(
:user
)
}
it
'returns auth_user'
do
expect
(
subject
.
auth_user
).
to
eq
(
actor
)
...
...
@@ -18,7 +19,7 @@ RSpec.describe Gitlab::Auth::Result do
end
context
'when actor is Deploy token'
do
let
(
:actor
)
{
create
(
:deploy_token
)
}
let
_it_be
(
:actor
)
{
create
(
:deploy_token
)
}
it
'returns deploy token'
do
expect
(
subject
.
deploy_token
).
to
eq
(
actor
)
...
...
@@ -28,4 +29,50 @@ RSpec.describe Gitlab::Auth::Result do
expect
(
subject
.
auth_user
).
to
be_nil
end
end
describe
'#authentication_abilities_include?'
do
context
'when authentication abilities are empty'
do
it
'returns false'
do
expect
(
subject
.
authentication_abilities_include?
(
:read_code
)).
to
be_falsey
end
end
context
'when authentication abilities are not empty'
do
subject
{
described_class
.
new
(
actor
,
nil
,
nil
,
[
:push_code
])
}
it
'returns false when ability is not allowed'
do
expect
(
subject
.
authentication_abilities_include?
(
:read_code
)).
to
be_falsey
end
it
'returns true when ability is allowed'
do
expect
(
subject
.
authentication_abilities_include?
(
:push_code
)).
to
be_truthy
end
end
end
describe
'#can_perform_action_on_project?'
do
let
(
:project
)
{
double
}
it
'returns if actor can do perform given action on given project'
do
expect
(
Ability
).
to
receive
(
:allowed?
).
with
(
actor
,
:push_code
,
project
).
and_return
(
true
)
expect
(
subject
.
can_perform_action_on_project?
(
:push_code
,
project
)).
to
be_truthy
end
it
'returns if actor cannot do perform given action on given project'
do
expect
(
Ability
).
to
receive
(
:allowed?
).
with
(
actor
,
:push_code
,
project
).
and_return
(
false
)
expect
(
subject
.
can_perform_action_on_project?
(
:push_code
,
project
)).
to
be_falsey
end
end
describe
'#can?'
do
it
'returns if actor can do perform given action on given project'
do
expect
(
actor
).
to
receive
(
:can?
).
with
(
:push_code
).
and_return
(
true
)
expect
(
subject
.
can?
(
:push_code
)).
to
be_truthy
end
it
'returns if actor cannot do perform given action on given project'
do
expect
(
actor
).
to
receive
(
:can?
).
with
(
:push_code
).
and_return
(
false
)
expect
(
subject
.
can?
(
:push_code
)).
to
be_falsey
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