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
02020053
Commit
02020053
authored
Dec 15, 2021
by
dcouture
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix false positives in graphql tests
parent
43b6f69c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
34 deletions
+85
-34
ee/spec/support/shared_examples/graphql/mutations/epics/permission_check_shared_examples.rb
...aphql/mutations/epics/permission_check_shared_examples.rb
+9
-16
spec/support/shared_examples/graphql/mutations/issues/permission_check_shared_examples.rb
...phql/mutations/issues/permission_check_shared_examples.rb
+35
-9
spec/support/shared_examples/graphql/mutations/merge_requests/permission_check_shared_examples.rb
...ations/merge_requests/permission_check_shared_examples.rb
+41
-9
No files found.
ee/spec/support/shared_examples/graphql/mutations/epics/permission_check_shared_examples.rb
View file @
02020053
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'permission level for epic mutation is correctly verified'
do
RSpec
.
shared_examples
'permission level for epic mutation is correctly verified'
do
before
do
let
(
:other_user_author
)
{
create
(
:user
)
}
stub_licensed_features
(
epics:
true
)
end
shared_examples_for
'when the user does not have access to the resource'
do
shared_examples_for
'when the user does not have access to the resource'
do
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
context
'even if author of the epic'
do
before
do
before
do
epic
.
author
=
user
stub_licensed_features
(
epics:
true
)
epic
.
update!
(
author:
other_user_author
)
end
end
it
'raises an error'
do
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
end
context
'even if a
ssigned to the issue
'
do
context
'even if a
uthor of the epic
'
do
before
do
before
do
issue
.
assignees
.
push
(
user
)
epic
.
update!
(
author:
user
)
end
end
it
'raises an error'
do
it
'raises an error'
do
...
@@ -30,9 +23,9 @@ RSpec.shared_examples 'permission level for epic mutation is correctly verified'
...
@@ -30,9 +23,9 @@ RSpec.shared_examples 'permission level for epic mutation is correctly verified'
end
end
end
end
context
'even if a
uthor of the issue
'
do
context
'even if a
ssigned to the epic
'
do
before
do
before
do
issue
.
author
=
user
epic
.
assignees
.
push
(
user
)
end
end
it
'raises an error'
do
it
'raises an error'
do
...
...
spec/support/shared_examples/graphql/mutations/issues/permission_check_shared_examples.rb
View file @
02020053
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'permission level for issue mutation is correctly verified'
do
|
raises_for_all_errors
=
false
|
RSpec
.
shared_examples
'permission level for issue mutation is correctly verified'
do
|
raises_for_all_errors
=
false
|
let_it_be
(
:other_user_author
)
{
create
(
:user
)
}
def
issue_attributes
(
issue
)
issue
.
attributes
.
except
(
# Description and title can be updated by authors and assignees of the issues
'description'
,
'title'
,
# Those fields are calculated or expected to be modified during the mutations
'author_id'
,
'updated_at'
,
'updated_by_id'
,
'last_edited_at'
,
'last_edited_by_id'
,
'lock_version'
,
# There were spec failures due to nano-second comparisons
# this property isn't changed by any mutation so we don't have to verify it
'created_at'
)
end
let
(
:expected
)
{
issue_attributes
(
issue
)
}
shared_examples_for
'when the user does not have access to the resource'
do
|
raise_for_assigned_and_author
|
before
do
before
do
issue
.
assignees
=
[]
issue
.
assignees
=
[]
issue
.
author
=
user
issue
.
update!
(
author:
other_user_author
)
end
end
shared_examples_for
'when the user does not have access to the resource'
do
|
raise_for_assigned
|
it
'raises an error'
do
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
...
@@ -17,21 +39,25 @@ RSpec.shared_examples 'permission level for issue mutation is correctly verified
...
@@ -17,21 +39,25 @@ RSpec.shared_examples 'permission level for issue mutation is correctly verified
end
end
it
'does not modify issue'
do
it
'does not modify issue'
do
if
raises_for_all_errors
||
raise_for_assigned
if
raises_for_all_errors
||
raise_for_assigned
_and_author
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
else
else
expect
(
subject
[
:issue
]).
to
eq
issue
expect
(
issue_attributes
(
subject
[
:issue
])).
to
eq
expected
end
end
end
end
end
end
context
'even if author of the issue'
do
context
'even if author of the issue'
do
before
do
before
do
issue
.
author
=
user
issue
.
update!
(
author:
user
)
end
end
it
'raises an error'
do
it
'does not modify issue'
do
if
raises_for_all_errors
||
raise_for_assigned_and_author
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
else
expect
(
issue_attributes
(
subject
[
:issue
])).
to
eq
expected
end
end
end
end
end
end
end
...
...
spec/support/shared_examples/graphql/mutations/merge_requests/permission_check_shared_examples.rb
View file @
02020053
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'permission level for merge request mutation is correctly verified'
do
RSpec
.
shared_examples
'permission level for merge request mutation is correctly verified'
do
let
(
:other_user_author
)
{
create
(
:user
)
}
def
mr_attributes
(
mr
)
mr
.
attributes
.
except
(
# Authors and assignees can edit title, description, target branch and draft status
'title'
,
'description'
,
'target_branch'
,
'draft'
,
# Those fields are calculated or expected to be modified during the mutations
'author_id'
,
'latest_merge_request_diff_id'
,
'last_edited_at'
,
'last_edited_by_id'
,
'lock_version'
,
'updated_at'
,
'updated_by_id'
,
'merge_status'
,
# There were spec failures due to nano-second comparisons
# this property isn't changed by any mutation so we don't have to verify it
'created_at'
)
end
let
(
:expected
)
{
mr_attributes
(
merge_request
)
}
shared_examples_for
'when the user does not have access to the resource'
do
|
raise_for_assigned_and_author
|
before
do
before
do
merge_request
.
assignees
=
[]
merge_request
.
assignees
=
[]
merge_request
.
reviewers
=
[]
merge_request
.
reviewers
=
[]
merge_request
.
author
=
nil
merge_request
.
update!
(
author:
other_user_author
)
end
end
shared_examples_for
'when the user does not have access to the resource'
do
|
raise_for_assigned
|
it
'raises an error'
do
it
'raises an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
end
end
...
@@ -18,12 +44,12 @@ RSpec.shared_examples 'permission level for merge request mutation is correctly
...
@@ -18,12 +44,12 @@ RSpec.shared_examples 'permission level for merge request mutation is correctly
end
end
it
'does not modify merge request'
do
it
'does not modify merge request'
do
if
raise_for_assigned
if
raise_for_assigned
_and_author
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
else
else
# In some cases we simply do nothing instead of raising
# In some cases we simply do nothing instead of raising
# https://gitlab.com/gitlab-org/gitlab/-/issues/196241
# https://gitlab.com/gitlab-org/gitlab/-/issues/196241
expect
(
subject
[
:merge_request
]).
to
eq
merge_request
expect
(
mr_attributes
(
subject
[
:merge_request
])).
to
eq
expected
end
end
end
end
end
end
...
@@ -40,11 +66,17 @@ RSpec.shared_examples 'permission level for merge request mutation is correctly
...
@@ -40,11 +66,17 @@ RSpec.shared_examples 'permission level for merge request mutation is correctly
context
'even if author of the merge request'
do
context
'even if author of the merge request'
do
before
do
before
do
merge_request
.
author
=
user
merge_request
.
update!
(
author:
user
)
end
end
it
'raises an error'
do
it
'raises an error'
do
if
raise_for_assigned_and_author
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ResourceNotAvailable
)
else
# In some cases we simply do nothing instead of raising
# https://gitlab.com/gitlab-org/gitlab/-/issues/196241
expect
(
mr_attributes
(
subject
[
:merge_request
])).
to
eq
expected
end
end
end
end
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