-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
AstSignatureTest.groovy
129 lines (111 loc) · 3.57 KB
/
AstSignatureTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package graphql.language
import graphql.TestUtil
import spock.lang.Specification
import static graphql.language.AstPrinter.printAst
class AstSignatureTest extends Specification {
def query = '''
query Ouch($secretVariable : String, $otherVariable : Int) {
fieldZ
fieldX(password : "hunter2", accountBalance : 200000.23,
avatar : { name : "secretPicture", url : "http://someplace" }
favouriteThings : [ "brown", "paper", "packages", "tied", "up", "in", "string" ]
likesIceCream : true
argToAVariable : $secretVariable
anotherArg : $otherVariable
)
fieldY {
innerFieldA
innerFieldC
innerFieldB
}
... X
}
query Ohh {
fieldZ
fieldX
fieldY {
innerFieldA
innerFieldC
innerFieldB
}
}
{
unnamedQuery
withFields
}
fragment X on SomeType {
fieldX(password : "hunter2", accountBalance : 200000.23,
avatar : { name : "secretPicture", url : "http://some place" }
favouriteThings : [ "brown", "paper", "packages", "tied", "up", "in", "string" ]
likesIceCream : true
)
}
type RogueSDLElement {
field : String
}
'''
def "can make a signature for a query"() {
def expectedQuery = '''query Ouch($var1: String, $var2: Int) {
fieldX(accountBalance: 0, anotherArg: $var2, argToAVariable: $var1, avatar: {}, favouriteThings: [], likesIceCream: false, password: "")
fieldY {
innerFieldA
innerFieldB
innerFieldC
}
fieldZ
...X
}
fragment X on SomeType {
fieldX(accountBalance: 0, avatar: {}, favouriteThings: [], likesIceCream: false, password: "")
}
'''
def doc = TestUtil.parseQuery(query)
when:
def newDoc = new AstSignature().signatureQuery(doc, "Ouch")
then:
newDoc != null
printAst(newDoc) == expectedQuery
}
def "can make a privacy safe document for a query"() {
def expectedQuery = '''query Ouch($var1: String, $var2: Int) {
fieldX(accountBalance: 0, anotherArg: $var2, argToAVariable: $var1, avatar: {name : "", url : ""}, favouriteThings: ["", "", "", "", "", "", ""], likesIceCream: false, password: "")
fieldY {
innerFieldA
innerFieldB
innerFieldC
}
fieldZ
...X
}
fragment X on SomeType {
fieldX(accountBalance: 0, avatar: {name : "", url : ""}, favouriteThings: ["", "", "", "", "", "", ""], likesIceCream: false, password: "")
}
'''
def doc = TestUtil.parseQuery(query)
when:
def newDoc = new AstSignature().privacySafeQuery(doc, "Ouch")
then:
newDoc != null
printAst(newDoc) == expectedQuery
}
def "can do signature on queries with no name"() {
def query = """
{
allIssues(arg1 : "UGC", arg2 : 666) {
id
}
}"""
def expectedQuery = """{
allIssues(arg1: "", arg2: 0) {
id
}
}
"""
def doc = TestUtil.parseQuery(query)
when:
def newDoc = new AstSignature().signatureQuery(doc, null)
then:
newDoc != null
printAst(newDoc) == expectedQuery
}
}