Skip to content

Commit

Permalink
Fix failing auth tests (#6923)
Browse files Browse the repository at this point in the history
(cherry picked from commit 74fb2c7)
  • Loading branch information
vmrajas committed Nov 20, 2020
1 parent 8446b32 commit 51487df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
19 changes: 19 additions & 0 deletions graphql/e2e/auth/add_mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func TestAuth_AddOnTypeWithRBACRuleOnInterface(t *testing.T) {
role: "ADMIN",
variables: map[string]interface{}{"fbpost": &FbPost{
Text: "New FbPost",
Pwd: "password",
Author: &Author{
Name: "[email protected]",
},
Expand All @@ -177,6 +178,7 @@ func TestAuth_AddOnTypeWithRBACRuleOnInterface(t *testing.T) {
role: "USER",
variables: map[string]interface{}{"fbpost": &FbPost{
Text: "New FbPost",
Pwd: "password",
Author: &Author{
Name: "[email protected]",
},
Expand Down Expand Up @@ -264,6 +266,7 @@ func TestAuth_AddOnTypeWithGraphTraversalRuleOnInterface(t *testing.T) {
ans: true,
variables: map[string]interface{}{"question": &Question{
Text: "A Question",
Pwd: "password",
Author: &Author{
Name: "[email protected]",
},
Expand All @@ -275,6 +278,7 @@ func TestAuth_AddOnTypeWithGraphTraversalRuleOnInterface(t *testing.T) {
ans: false,
variables: map[string]interface{}{"question": &Question{
Text: "A Question",
Pwd: "password",
Author: &Author{
Name: "user1",
},
Expand All @@ -287,6 +291,7 @@ func TestAuth_AddOnTypeWithGraphTraversalRuleOnInterface(t *testing.T) {
ans: true,
variables: map[string]interface{}{"question": &Question{
Text: "A Question",
Pwd: "password",
Author: &Author{
Name: "user1",
},
Expand Down Expand Up @@ -361,6 +366,7 @@ func TestAddDeepFilter(t *testing.T) {
Name: "column_add_1",
InProject: &Project{
Name: "project_add_1",
Pwd: "password1",
},
}},
}, {
Expand All @@ -372,10 +378,12 @@ func TestAddDeepFilter(t *testing.T) {
Name: "column_add_2",
InProject: &Project{
Name: "project_add_2",
Pwd: "password2",
Roles: []*Role{{
Permission: "ADMIN",
AssignedTo: []*common.User{{
Username: "user2",
Password: "password",
}},
}},
},
Expand All @@ -388,15 +396,18 @@ func TestAddDeepFilter(t *testing.T) {
Name: "column_add_3",
InProject: &Project{
Name: "project_add_4",
Pwd: "password4",
Roles: []*Role{{
Permission: "ADMIN",
AssignedTo: []*common.User{{
Username: "user6",
Password: "password",
}},
}, {
Permission: "VIEW",
AssignedTo: []*common.User{{
Username: "user6",
Password: "password",
}},
}},
},
Expand Down Expand Up @@ -468,6 +479,7 @@ func TestAddOrRBACFilter(t *testing.T) {
result: `{"addProject": {"project":[{"name":"project_add_1"}]}}`,
variables: map[string]interface{}{"project": &Project{
Name: "project_add_1",
Pwd: "password1",
}},
}, {
// Test case fails as the role isn't assigned to the correct user
Expand All @@ -476,10 +488,12 @@ func TestAddOrRBACFilter(t *testing.T) {
result: ``,
variables: map[string]interface{}{"project": &Project{
Name: "project_add_2",
Pwd: "password2",
Roles: []*Role{{
Permission: "ADMIN",
AssignedTo: []*common.User{{
Username: "user2",
Password: "password",
}},
}},
}},
Expand All @@ -489,15 +503,18 @@ func TestAddOrRBACFilter(t *testing.T) {
result: `{"addProject": {"project":[{"name":"project_add_3"}]}}`,
variables: map[string]interface{}{"project": &Project{
Name: "project_add_3",
Pwd: "password3",
Roles: []*Role{{
Permission: "ADMIN",
AssignedTo: []*common.User{{
Username: "user7",
Password: "password",
}},
}, {
Permission: "VIEW",
AssignedTo: []*common.User{{
Username: "user7",
Password: "password",
}},
}},
}},
Expand Down Expand Up @@ -817,13 +834,15 @@ func TestAddRBACFilter(t *testing.T) {
result: `{"addLog": {"log":[{"logs":"log_add_1"}]}}`,
variables: map[string]interface{}{"issue": &Log{
Logs: "log_add_1",
Pwd: "password1",
}},
}, {
user: "user1",
role: "USER",
result: ``,
variables: map[string]interface{}{"issue": &Log{
Logs: "log_add_2",
Pwd: "password2",
}},
}}

Expand Down
3 changes: 3 additions & 0 deletions graphql/e2e/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Question struct {
Text string `json:"text,omitempty"`
Answered bool `json:"answered,omitempty"`
Author *Author `json:"author,omitempty"`
Pwd string `json:"pwd,omitempty"`
}

type Answer struct {
Expand All @@ -93,6 +94,7 @@ type FbPost struct {
Sender *Author `json:"sender,omitempty"`
Receiver *Author `json:"receiver,omitempty"`
PostCount int `json:"postCount,omitempty"`
Pwd string `json:"pwd,omitempty"`
}

type Log struct {
Expand Down Expand Up @@ -133,6 +135,7 @@ type Project struct {
Name string `json:"name,omitempty"`
Roles []*Role `json:"roles,omitempty"`
Columns []*Column `json:"columns,omitempty"`
Pwd string `json:"pwd,omitempty"`
}

type Student struct {
Expand Down
24 changes: 12 additions & 12 deletions graphql/e2e/auth/delete_mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (l *Log) add(t *testing.T, user, role string) {
getParams := &common.GraphQLParams{
Headers: common.GetJWT(t, user, role, metaInfo),
Query: `
mutation addLog($log: AddLogInput!) {
addLog(input: [$log]) {
mutation addLog($pwd: String!, $logs: String, $random: String) {
addLog(input: [{pwd: $pwd, logs: $logs, random: $random}]) {
numUids
}
}
`,
Variables: map[string]interface{}{"log": l},
Variables: map[string]interface{}{"pwd": "password", "logs": l.Logs, "random": l.Random},
}
gqlResponse := getParams.ExecuteAsPost(t, graphqlURL)
require.Nil(t, gqlResponse.Errors)
Expand Down Expand Up @@ -93,13 +93,13 @@ func (q *Question) add(t *testing.T, user string, ans bool) {
getParams := &common.GraphQLParams{
Headers: common.GetJWTForInterfaceAuth(t, user, "", ans, metaInfo),
Query: `
mutation addQuestion($text: String!,$id: ID!, $ans: Boolean ){
addQuestion(input: [{text: $text, author: {id: $id}, answered: $ans }]){
mutation addQuestion($text: String!,$id: ID!, $ans: Boolean, $pwd: String! ){
addQuestion(input: [{text: $text, author: {id: $id}, answered: $ans, pwd: $pwd }]){
numUids
}
}
`,
Variables: map[string]interface{}{"text": q.Text, "ans": q.Answered, "id": q.Author.Id},
Variables: map[string]interface{}{"text": q.Text, "ans": q.Answered, "id": q.Author.Id, "pwd": "password"},
}
gqlResponse := getParams.ExecuteAsPost(t, graphqlURL)
require.Nil(t, gqlResponse.Errors)
Expand All @@ -109,13 +109,13 @@ func (a *Answer) add(t *testing.T, user string) {
getParams := &common.GraphQLParams{
Headers: common.GetJWT(t, user, "", metaInfo),
Query: `
mutation addAnswer($text: String!,$id: ID!){
addAnswer(input: [{text: $text, author: {id: $id}}]){
mutation addAnswer($text: String!,$id: ID!, $pwd: String!){
addAnswer(input: [{text: $text, pwd: $pwd, author: {id: $id}}]){
numUids
}
}
`,
Variables: map[string]interface{}{"text": a.Text, "id": a.Author.Id},
Variables: map[string]interface{}{"text": a.Text, "id": a.Author.Id, "pwd": "password"},
}
gqlResponse := getParams.ExecuteAsPost(t, graphqlURL)
require.Nil(t, gqlResponse.Errors)
Expand All @@ -125,13 +125,13 @@ func (f *FbPost) add(t *testing.T, user, role string) {
getParams := &common.GraphQLParams{
Headers: common.GetJWT(t, user, role, metaInfo),
Query: `
mutation addFbPost($text: String!,$id1: ID!,$id2:ID!, $id3: ID!, $postCount: Int! ){
addFbPost(input: [{text: $text, author: {id: $id1},sender: {id: $id2}, receiver: {id: $id3}, postCount: $postCount }]){
mutation addFbPost($text: String!,$id1: ID!,$id2:ID!, $id3: ID!, $postCount: Int!, $pwd: String! ){
addFbPost(input: [{text: $text, author: {id: $id1},sender: {id: $id2}, receiver: {id: $id3}, postCount: $postCount, pwd: $pwd }]){
numUids
}
}
`,
Variables: map[string]interface{}{"text": f.Text, "id1": f.Author.Id, "id2": f.Sender.Id, "id3": f.Receiver.Id, "postCount": f.PostCount},
Variables: map[string]interface{}{"text": f.Text, "id1": f.Author.Id, "id2": f.Sender.Id, "id3": f.Receiver.Id, "postCount": f.PostCount, "pwd": "password"},
}
gqlResponse := getParams.ExecuteAsPost(t, graphqlURL)
require.Nil(t, gqlResponse.Errors)
Expand Down

0 comments on commit 51487df

Please sign in to comment.