@@ -117,6 +117,90 @@ func TestSafelist(t *testing.T) {
117117 })
118118 })
119119
120+ t .Run ("safelist with access log sha256 attribute allows a persisted query to run" , func (t * testing.T ) {
121+ testenv .Run (t , & testenv.Config {
122+ AccessLogFields : []config.CustomAttribute {
123+ {
124+ Key : "operation_sha256" ,
125+ ValueFrom : & config.CustomDynamicAttribute {
126+ ContextField : core .ContextFieldOperationSha256 ,
127+ },
128+ },
129+ },
130+ RouterOptions : []core.Option {
131+ core .WithPersistedOperationsConfig (config.PersistedOperationsConfig {
132+ Safelist : config.SafelistConfiguration {Enabled : true },
133+ }),
134+ },
135+ }, func (t * testing.T , xEnv * testenv.Environment ) {
136+ header := make (http.Header )
137+ header .Add ("graphql-client-name" , "my-client" )
138+ res , err := xEnv .MakeGraphQLRequest (testenv.GraphQLRequest {
139+ OperationName : []byte (`"Employees"` ),
140+ Header : header ,
141+ Query : persistedQuery ,
142+ })
143+ require .NoError (t , err )
144+ require .Equal (t , `{"data":{"employees":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":7},{"id":8},{"id":10},{"id":11},{"id":12}]}}` , res .Body )
145+ })
146+ })
147+
148+ t .Run ("safelist with access log sha256 attribute allows a persisted query run with ID" , func (t * testing.T ) {
149+ testenv .Run (t , & testenv.Config {
150+ AccessLogFields : []config.CustomAttribute {
151+ {
152+ Key : "operation_sha256" ,
153+ ValueFrom : & config.CustomDynamicAttribute {
154+ ContextField : core .ContextFieldOperationSha256 ,
155+ },
156+ },
157+ },
158+ RouterOptions : []core.Option {
159+ core .WithPersistedOperationsConfig (config.PersistedOperationsConfig {
160+ Safelist : config.SafelistConfiguration {Enabled : true },
161+ }),
162+ },
163+ }, func (t * testing.T , xEnv * testenv.Environment ) {
164+ header := make (http.Header )
165+ header .Add ("graphql-client-name" , "my-client" )
166+ res , err := xEnv .MakeGraphQLRequest (testenv.GraphQLRequest {
167+ OperationName : []byte (`"Employees"` ),
168+ Extensions : []byte (`{"persistedQuery": {"version": 1, "sha256Hash": "dc67510fb4289672bea757e862d6b00e83db5d3cbbcfb15260601b6f29bb2b8f"}}` ),
169+ Header : header ,
170+ })
171+ require .NoError (t , err )
172+ require .Equal (t , `{"data":{"employees":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":7},{"id":8},{"id":10},{"id":11},{"id":12}]}}` , res .Body )
173+ })
174+ })
175+
176+ t .Run ("safelist with access log sha256 attribute rejects non persisted query" , func (t * testing.T ) {
177+ testenv .Run (t , & testenv.Config {
178+ AccessLogFields : []config.CustomAttribute {
179+ {
180+ Key : "operation_sha256" ,
181+ ValueFrom : & config.CustomDynamicAttribute {
182+ ContextField : core .ContextFieldOperationSha256 ,
183+ },
184+ },
185+ },
186+ RouterOptions : []core.Option {
187+ core .WithPersistedOperationsConfig (config.PersistedOperationsConfig {
188+ Safelist : config.SafelistConfiguration {Enabled : true },
189+ }),
190+ },
191+ }, func (t * testing.T , xEnv * testenv.Environment ) {
192+ header := make (http.Header )
193+ header .Add ("graphql-client-name" , "my-client" )
194+ res , err := xEnv .MakeGraphQLRequest (testenv.GraphQLRequest {
195+ OperationName : []byte (`"Employees"` ),
196+ Header : header ,
197+ Query : queryWithDetails ,
198+ })
199+ require .NoError (t , err )
200+ require .Equal (t , persistedNotFoundResp , res .Body )
201+ })
202+ })
203+
120204 t .Run ("log unknown operations" , func (t * testing.T ) {
121205 t .Run ("logs non persisted query but allows them to continue" , func (t * testing.T ) {
122206 testenv .Run (t , & testenv.Config {
0 commit comments