Skip to content

Commit

Permalink
More descriptive error message for NotAuthorizedError
Browse files Browse the repository at this point in the history
  • Loading branch information
sshaw committed Oct 18, 2019
1 parent 807bcbb commit 034891f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/graphql/guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module GraphQL
class Guard
ANY_FIELD_NAME = :'*'
DEFAULT_NOT_AUTHORIZED = ->(type, field) { raise NotAuthorizedError.new("#{type}.#{field}") }
DEFAULT_NOT_AUTHORIZED = ->(type, field) { raise NotAuthorizedError.new("Not authorized to access: #{type}.#{field}") }

NotAuthorizedError = Class.new(StandardError)

Expand Down
8 changes: 4 additions & 4 deletions spec/graphql/guard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

expect {
Inline::Schema.execute(query, variables: {'userId' => '2'}, context: {current_user: user})
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Query.posts')
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Not authorized to access: Query.posts')
end

it 'does not authorize a field with a policy on the type' do
Expand All @@ -33,7 +33,7 @@

expect {
Inline::Schema.execute(query, variables: {'userId' => '1'}, context: {current_user: user})
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Post.id')
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Not authorized to access: Post.id')
end

it 'does not authorize a field and returns an error' do
Expand Down Expand Up @@ -91,7 +91,7 @@

expect {
PolicyObject::Schema.execute(query, variables: {'userId' => '2'}, context: {current_user: user})
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Query.posts')
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Not authorized to access: Query.posts')
end

it 'does not authorize a field with a policy on the type' do
Expand All @@ -100,7 +100,7 @@

expect {
PolicyObject::Schema.execute(query, variables: {'userId' => '1'}, context: {current_user: user})
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Post.id')
}.to raise_error(GraphQL::Guard::NotAuthorizedError, 'Not authorized to access: Post.id')
end
end
end

0 comments on commit 034891f

Please sign in to comment.