Skip to content

Commit

Permalink
graphql: fix password rewriting (hypermodeinc#5256)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJCompton authored and dna2github committed Jul 18, 2020
1 parent f9a6330 commit 459eb0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions graphql/resolve/query_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func (qr *queryRewriter) Rewrite(ctx context.Context,
}

dgQuery := rewriteAsGet(gqlQuery, uid, xid)
addTypeFilter(dgQuery, gqlQuery.Type())

return dgQuery, nil

case schema.FilterQuery:
Expand Down Expand Up @@ -201,8 +199,12 @@ func addArgumentsToField(dgQuery *gql.GraphQuery, field schema.Field) {
}

func rewriteAsGet(field schema.Field, uid uint64, xid *string) *gql.GraphQuery {
var dgQuery *gql.GraphQuery

if xid == nil {
return rewriteAsQueryByIds(field, []uint64{uid})
dgQuery = rewriteAsQueryByIds(field, []uint64{uid})
addTypeFilter(dgQuery, field.Type())
return dgQuery
}

xidArgName := field.XIDArg()
Expand All @@ -214,7 +216,6 @@ func rewriteAsGet(field schema.Field, uid uint64, xid *string) *gql.GraphQuery {
},
}

var dgQuery *gql.GraphQuery
if uid > 0 {
dgQuery = &gql.GraphQuery{
Attr: field.ResponseName(),
Expand All @@ -235,6 +236,7 @@ func rewriteAsGet(field schema.Field, uid uint64, xid *string) *gql.GraphQuery {
}
addSelectionSetFrom(dgQuery, field)
addUID(dgQuery)
addTypeFilter(dgQuery, field.Type())
return dgQuery
}

Expand Down
6 changes: 3 additions & 3 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,17 +1146,17 @@
name: "Password query"
gqlquery: |
query {
checkUserPassword(name: "0x1", pwd: "Password") {
checkUserPassword(name: "user1", pwd: "Password") {
name
}
}
dgquery: |-
query {
checkUserPassword(func: eq(User.name, "0x1")) @filter((eq(val(pwd), 1))) {
checkUserPassword(func: eq(User.name, "user1")) @filter((eq(val(pwd), 1) AND type(User))) {
name : User.name
dgraph.uid : uid
}
checkPwd(func: eq(User.name, "0x1")) {
checkPwd(func: eq(User.name, "user1")) @filter(type(User)) {
pwd as checkpwd(User.pwd, "Password")
}
}
Expand Down

0 comments on commit 459eb0e

Please sign in to comment.