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
0e2f0750
Commit
0e2f0750
authored
Jun 29, 2020
by
Max Woolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds AuthorizeTypes cop to EE-only GraphQL types
parent
e80b3b81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
75 deletions
+46
-75
.rubocop.yml
.rubocop.yml
+3
-0
rubocop/cop/graphql/authorize_types.rb
rubocop/cop/graphql/authorize_types.rb
+0
-9
spec/rubocop/cop/graphql/authorize_types_spec.rb
spec/rubocop/cop/graphql/authorize_types_spec.rb
+43
-66
No files found.
.rubocop.yml
View file @
0e2f0750
...
...
@@ -316,6 +316,9 @@ Cop/SidekiqOptionsQueue:
Graphql/AuthorizeTypes
:
Enabled
:
true
Include
:
-
'
app/graphql/types/**/*'
-
'
ee/app/graphql/types/**/*'
Exclude
:
-
'
spec/**/*.rb'
-
'
ee/spec/**/*.rb'
...
...
rubocop/cop/graphql/authorize_types.rb
View file @
0e2f0750
...
...
@@ -7,8 +7,6 @@ module RuboCop
MSG
=
'Add an `authorize :ability` call to the type: '
\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
TYPES_DIR
=
'app/graphql/types'
# We want to exclude our own basetypes and scalars
WHITELISTED_TYPES
=
%w[BaseEnum BaseScalar BasePermissionType MutationType
QueryType GraphQL::Schema BaseUnion]
.
freeze
...
...
@@ -18,7 +16,6 @@ module RuboCop
PATTERN
def
on_class
(
node
)
return
unless
in_type?
(
node
)
return
if
whitelisted?
(
class_constant
(
node
))
return
if
whitelisted?
(
superclass_constant
(
node
))
...
...
@@ -27,12 +24,6 @@ module RuboCop
private
def
in_type?
(
node
)
path
=
node
.
location
.
expression
.
source_buffer
.
name
path
.
include?
TYPES_DIR
end
def
whitelisted?
(
class_node
)
class_const
=
class_node
&
.
const_name
...
...
spec/rubocop/cop/graphql/authorize_types_spec.rb
View file @
0e2f0750
...
...
@@ -10,83 +10,60 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do
subject
(
:cop
)
{
described_class
.
new
}
context
'when NOT in a type folder'
do
before
do
allow
(
cop
).
to
receive
(
:in_type?
).
and_return
(
false
)
end
it
'does not add an offense even though there is no authorize call'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
module Types
class AType < BaseObject
field :a_thing
field :another_thing
end
end
TYPE
end
end
context
'when in a type folder'
do
before
do
allow
(
cop
).
to
receive
(
:in_type?
).
and_return
(
true
)
end
it
'adds an offense when there is no authorize call'
do
inspect_source
(
<<~
TYPE
)
module Types
class AType < BaseObject
field :a_thing
field :another_thing
end
it
'adds an offense when there is no authorize call'
do
inspect_source
(
<<~
TYPE
)
module Types
class AType < BaseObject
field :a_thing
field :another_thing
end
TYPE
end
TYPE
expect
(
cop
.
offenses
.
size
).
to
eq
1
end
expect
(
cop
.
offenses
.
size
).
to
eq
1
end
it
'does not add an offense for classes that have an authorize call'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
module Types
class AType < BaseObject
graphql_name 'ATypeName'
it
'does not add an offense for classes that have an authorize call'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
module Types
class AType < BaseObject
graphql_name 'ATypeName'
authorize :an_ability, :second_ability
authorize :an_ability, :second_ability
field :a_thing
end
field :a_thing
end
TYPE
end
end
TYPE
end
it
'does not add an offense for classes that only have an authorize call'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
module Types
class AType < SuperClassWithFields
authorize :an_ability
end
it
'does not add an offense for classes that only have an authorize call'
do
expect_no_offenses
(
<<~
TYPE
.
strip
)
module Types
class AType < SuperClassWithFields
authorize :an_ability
end
TYPE
end
end
TYPE
end
it
'does not add an offense for base types'
do
expect_no_offenses
(
<<~
TYPE
)
module Types
class AType < BaseEnum
field :a_thing
end
it
'does not add an offense for base types'
do
expect_no_offenses
(
<<~
TYPE
)
module Types
class AType < BaseEnum
field :a_thing
end
TYPE
end
end
TYPE
end
it
'does not add an offense for Enums'
do
expect_no_offenses
(
<<~
TYPE
)
module Types
class ATypeEnum < AnotherEnum
field :a_thing
end
it
'does not add an offense for Enums'
do
expect_no_offenses
(
<<~
TYPE
)
module Types
class ATypeEnum < AnotherEnum
field :a_thing
end
TYPE
end
end
TYPE
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