@@ -17,6 +17,7 @@ import (
17
17
"github.com/dgraph-io/badger/v4"
18
18
"github.com/dgraph-io/dgo/v250/protos/api"
19
19
"github.com/hypermodeinc/dgraph/v25/chunker"
20
+ "github.com/hypermodeinc/dgraph/v25/dql"
20
21
"github.com/hypermodeinc/dgraph/v25/schema"
21
22
"github.com/hypermodeinc/dgraph/v25/worker"
22
23
"github.com/hypermodeinc/dgraph/v25/x"
@@ -206,3 +207,82 @@ func TestGetHash(t *testing.T) {
206
207
worker .Config .AclSecretKeyBytes = x .Sensitive ("123456789" )
207
208
require .Equal (t , hex .EncodeToString (h .Sum (nil )), getHash (10 , 20 ))
208
209
}
210
+
211
+ func TestVerifyUniqueWithinMutationBoundsChecks (t * testing.T ) {
212
+ t .Run ("gmuIndex out of bounds" , func (t * testing.T ) {
213
+ qc := & queryContext {
214
+ gmuList : []* dql.Mutation {
215
+ {
216
+ Set : []* api.NQuad {
217
+ {
218
+ Subject : "_:a" ,
219
+ Predicate : "username" ,
220
+ ObjectValue : & api.Value {
221
+ Val : & api.Value_StrVal {StrVal : "user1" },
222
+ },
223
+ },
224
+ },
225
+ },
226
+ },
227
+ // Reference gmuList[1], which is out of bounds.
228
+ uniqueVars : map [uint64 ]uniquePredMeta {
229
+ encodeIndex (1 , 0 ): {},
230
+ },
231
+ }
232
+ err := verifyUniqueWithinMutation (qc )
233
+ require .NoError (t , err )
234
+ })
235
+
236
+ t .Run ("rdfIndex out of bounds" , func (t * testing.T ) {
237
+ qc := & queryContext {
238
+ gmuList : []* dql.Mutation {
239
+ {
240
+ Set : []* api.NQuad {
241
+ // Only one element at index 0.
242
+ {
243
+ Subject : "_:a" ,
244
+ Predicate : "username" ,
245
+ ObjectValue : & api.Value {
246
+ Val : & api.Value_StrVal {StrVal : "user1" },
247
+ },
248
+ },
249
+ },
250
+ },
251
+ },
252
+ // Reference Set[1], which is out of bounds.
253
+ uniqueVars : map [uint64 ]uniquePredMeta {
254
+ encodeIndex (0 , 1 ): {},
255
+ },
256
+ }
257
+ err := verifyUniqueWithinMutation (qc )
258
+ require .NoError (t , err )
259
+ })
260
+
261
+ t .Run ("gmuList element is nil" , func (t * testing.T ) {
262
+ qc := & queryContext {
263
+ gmuList : []* dql.Mutation {
264
+ nil , // Element at index 0 is nil.
265
+ },
266
+ uniqueVars : map [uint64 ]uniquePredMeta {
267
+ encodeIndex (0 , 0 ): {},
268
+ },
269
+ }
270
+ err := verifyUniqueWithinMutation (qc )
271
+ require .NoError (t , err )
272
+ })
273
+
274
+ t .Run ("Set slice is nil" , func (t * testing.T ) {
275
+ qc := & queryContext {
276
+ gmuList : []* dql.Mutation {
277
+ {
278
+ Set : nil , // Set slice is nil.
279
+ },
280
+ },
281
+ uniqueVars : map [uint64 ]uniquePredMeta {
282
+ encodeIndex (0 , 0 ): {},
283
+ },
284
+ }
285
+ err := verifyUniqueWithinMutation (qc )
286
+ require .NoError (t , err )
287
+ })
288
+ }
0 commit comments