-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(GraphQL): Support auth with custom DQL #7775
Merged
Merged
Changes from 27 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
3323ed7
initial commit
minhaj-shakeel 389349e
minor fix
minhaj-shakeel 84c82c5
change Root Query
minhaj-shakeel 8dec57e
add support for @groupby in AsString
minhaj-shakeel 41a4eac
attach rewriter to custom resolver
minhaj-shakeel af4479b
add unit tests
minhaj-shakeel 1e048ce
minor fix
minhaj-shakeel e74fadb
support for multiple query blocks
minhaj-shakeel 04e5502
support var query with rbac = Negative
minhaj-shakeel 181684d
fix AsString
minhaj-shakeel f050f8d
fix test case
minhaj-shakeel 2afba2a
add auth rules on children
minhaj-shakeel d4f0031
fix var block auth query
minhaj-shakeel 0b295b7
fix test name
minhaj-shakeel c6e8e2a
fix AsString
minhaj-shakeel fa81419
fix AsString
minhaj-shakeel 9fbe48f
insert quotes in the argument
minhaj-shakeel 4da6db7
remove redundant function
minhaj-shakeel 188a4d2
fix for filter arguments
minhaj-shakeel b4977db
handle filter attribute
minhaj-shakeel f45a91f
fix rewriting of test cases
minhaj-shakeel 55149db
add some comments
minhaj-shakeel f786c23
modify unit tests
minhaj-shakeel b19f215
handle has function
minhaj-shakeel c124b59
add e2e test cases
minhaj-shakeel f4bcf9c
fix var query for RBAC negative
minhaj-shakeel b54cc0c
fix test
minhaj-shakeel ba1aa4a
address comments
minhaj-shakeel e8a3de4
add e2e test for interface auth
minhaj-shakeel 84f1af2
clean code
minhaj-shakeel 8359e73
add example of order
minhaj-shakeel 0abd898
add e2e case for interfaces
minhaj-shakeel 7e21e44
minor fix
minhaj-shakeel 434cdcd
fmt
minhaj-shakeel a1f7cad
address Rajas's comments
minhaj-shakeel 209e2de
fix indent
minhaj-shakeel fee9e14
add Todo
minhaj-shakeel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,6 +322,122 @@ func (s Student) add(t *testing.T) { | |
require.JSONEq(t, result, string(gqlResponse.Data)) | ||
} | ||
|
||
func TestAuthWithCustomDQL(t *testing.T) { | ||
TestCases := []TestCase{ | ||
{ | ||
name: "RBAC OR filter query; RBAC Pass", | ||
query: ` | ||
query{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: indent |
||
queryProjectsOrderByName{ | ||
name | ||
} | ||
} | ||
`, | ||
role: "ADMIN", | ||
result: `{"queryProjectsOrderByName":[{"name": "Project1"},{"name": "Project2"}]}`, | ||
}, | ||
{ | ||
name: "RBAC OR filter query; RBAC fail", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: RBAC false or user1 projects. |
||
query: ` | ||
query{ | ||
queryProjectsOrderByName{ | ||
name | ||
} | ||
} | ||
`, | ||
role: "USER", | ||
user: "user1", | ||
result: `{"queryProjectsOrderByName":[{"name": "Project1"}]}`, | ||
}, | ||
{ | ||
name: "RBAC OR filter query; missing jwt", | ||
query: ` | ||
query{ | ||
queryProjectsOrderByName{ | ||
name | ||
} | ||
} | ||
`, | ||
result: `{"queryProjectsOrderByName":[]}`, | ||
}, | ||
{ | ||
name: "var query; RBAC AND filter query; RBAC pass", | ||
query: ` | ||
query{ | ||
queryIssueSortedByOwnerAge{ | ||
msg | ||
} | ||
} | ||
`, | ||
role: "ADMIN", | ||
user: "user2", | ||
result: `{"queryIssueSortedByOwnerAge": [{"msg": "Issue2"}]}`, | ||
}, | ||
{ | ||
name: "var query; RBAC AND filter query; RBAC fail", | ||
query: ` | ||
query{ | ||
queryIssueSortedByOwnerAge{ | ||
msg | ||
} | ||
} | ||
`, | ||
role: "USER", | ||
user: "user2", | ||
result: `{"queryIssueSortedByOwnerAge": []}`, | ||
}, | ||
{ | ||
name: "DQL query with @cascade and pagination", | ||
query: ` | ||
query{ | ||
queryFirstTwoMovieWithNonNullRegion{ | ||
content | ||
code | ||
regionsAvailable{ | ||
name | ||
} | ||
} | ||
} | ||
`, | ||
role: "ADMIN", | ||
user: "user1", | ||
result: `{"queryFirstTwoMovieWithNonNullRegion": [ | ||
{ | ||
"content": "Movie3", | ||
"code": "m3", | ||
"regionsAvailable": [ | ||
{ | ||
"name": "Region1" | ||
} | ||
] | ||
}, | ||
{ | ||
"content": "Movie4", | ||
"code": "m4", | ||
"regionsAvailable": [ | ||
{ | ||
"name": "Region5" | ||
} | ||
] | ||
} | ||
] | ||
}`, | ||
}, | ||
} | ||
|
||
for _, tcase := range TestCases { | ||
t.Run(tcase.name, func(t *testing.T) { | ||
getUserParams := &common.GraphQLParams{ | ||
Headers: common.GetJWT(t, tcase.user, tcase.role, metaInfo), | ||
Query: tcase.query, | ||
} | ||
gqlResponse := getUserParams.ExecuteAsPost(t, common.GraphqlURL) | ||
common.RequireNoGQLErrors(t, gqlResponse) | ||
require.JSONEq(t, tcase.result, string(gqlResponse.Data)) | ||
}) | ||
} | ||
} | ||
|
||
func TestAddMutationWithXid(t *testing.T) { | ||
mutation := ` | ||
mutation addTweets($tweet: AddTweetsInput!){ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment