@@ -129,7 +129,7 @@ class CollectorServiceSpec extends Specification {
129
129
None ,
130
130
Some (" b" ),
131
131
" p" ,
132
- Some (HttpCookie (" sp" ," cookie-nuid" )),
132
+ Some (HttpCookie (" sp" , " cookie-nuid" )),
133
133
None ,
134
134
None ,
135
135
" h" ,
@@ -143,14 +143,14 @@ class CollectorServiceSpec extends Specification {
143
143
l must have size 1
144
144
val newEvent = new CollectorPayload (" iglu-schema" , " ip" , System .currentTimeMillis, " UTF-8" , " collector" )
145
145
deserializer.deserialize(newEvent, l.head)
146
- newEvent.networkUserId shouldEqual " "
146
+ newEvent.networkUserId shouldEqual " 00000000-0000-0000-0000-000000000000 "
147
147
}
148
148
" network_userid from cookie should persist if SP-Anonymous is not present" in {
149
149
val (_, l) = service.cookie(
150
150
None ,
151
151
Some (" b" ),
152
152
" p" ,
153
- Some (HttpCookie (" sp" ," cookie-nuid" )),
153
+ Some (HttpCookie (" sp" , " cookie-nuid" )),
154
154
None ,
155
155
None ,
156
156
" h" ,
@@ -340,9 +340,10 @@ class CollectorServiceSpec extends Specification {
340
340
e.contentType shouldEqual ct.get
341
341
}
342
342
" fill the correct values if SP-Anonymous is present" in {
343
- val l = `Location`(" l" )
344
- val ct = Some (" image/gif" )
345
- val r = HttpRequest ().withHeaders(l :: hs)
343
+ val l = `Location`(" l" )
344
+ val ct = Some (" image/gif" )
345
+ val r = HttpRequest ().withHeaders(l :: hs)
346
+ val nuid = service.networkUserId(r, None , Some (" *" )).get
346
347
val e =
347
348
service.buildEvent(
348
349
Some (" q" ),
@@ -353,7 +354,7 @@ class CollectorServiceSpec extends Specification {
353
354
" h" ,
354
355
" unknown" ,
355
356
r,
356
- " nuid" ,
357
+ nuid,
357
358
ct,
358
359
Some (" *" )
359
360
)
@@ -367,16 +368,29 @@ class CollectorServiceSpec extends Specification {
367
368
e.userAgent shouldEqual " ua"
368
369
e.refererUri shouldEqual " ref"
369
370
e.hostname shouldEqual " h"
370
- e.networkUserId shouldEqual " "
371
+ e.networkUserId shouldEqual " 00000000-0000-0000-0000-000000000000 "
371
372
e.headers shouldEqual (List (l) ++ ct).map(_.toString).asJava
372
373
e.contentType shouldEqual ct.get
373
374
}
374
375
" have a null queryString if it's None" in {
375
- val l = `Location`(" l" )
376
- val ct = Some (" image/gif" )
377
- val r = HttpRequest ().withHeaders(l :: hs)
376
+ val l = `Location`(" l" )
377
+ val ct = Some (" image/gif" )
378
+ val r = HttpRequest ().withHeaders(l :: hs)
379
+ val nuid = service.networkUserId(r, None , Some (" *" )).get
378
380
val e =
379
- service.buildEvent(None , Some (" b" ), " p" , Some (" ua" ), Some (" ref" ), " h" , " unknown" , r, " nuid" , ct, Some (" *" ))
381
+ service.buildEvent(
382
+ None ,
383
+ Some (" b" ),
384
+ " p" ,
385
+ Some (" ua" ),
386
+ Some (" ref" ),
387
+ " h" ,
388
+ " unknown" ,
389
+ r,
390
+ nuid,
391
+ ct,
392
+ Some (" *" )
393
+ )
380
394
e.schema shouldEqual " iglu:com.snowplowanalytics.snowplow/CollectorPayload/thrift/1-0-0"
381
395
e.ipAddress shouldEqual " unknown"
382
396
e.encoding shouldEqual " UTF-8"
@@ -387,17 +401,30 @@ class CollectorServiceSpec extends Specification {
387
401
e.userAgent shouldEqual " ua"
388
402
e.refererUri shouldEqual " ref"
389
403
e.hostname shouldEqual " h"
390
- e.networkUserId shouldEqual " "
404
+ e.networkUserId shouldEqual " 00000000-0000-0000-0000-000000000000 "
391
405
e.headers shouldEqual (List (l) ++ ct).map(_.toString).asJava
392
406
e.contentType shouldEqual ct.get
393
407
}
394
408
" have an empty nuid if SP-Anonymous is present" in {
395
- val l = `Location`(" l" )
396
- val ct = Some (" image/gif" )
397
- val r = HttpRequest ().withHeaders(l :: hs)
409
+ val l = `Location`(" l" )
410
+ val ct = Some (" image/gif" )
411
+ val r = HttpRequest ().withHeaders(l :: hs)
412
+ val nuid = service.networkUserId(r, None , Some (" *" )).get
398
413
val e =
399
- service.buildEvent(None , Some (" b" ), " p" , Some (" ua" ), Some (" ref" ), " h" , " unknown" , r, " nuid" , ct, Some (" *" ))
400
- e.networkUserId shouldEqual " "
414
+ service.buildEvent(
415
+ None ,
416
+ Some (" b" ),
417
+ " p" ,
418
+ Some (" ua" ),
419
+ Some (" ref" ),
420
+ " h" ,
421
+ " unknown" ,
422
+ r,
423
+ nuid,
424
+ ct,
425
+ Some (" *" )
426
+ )
427
+ e.networkUserId shouldEqual " 00000000-0000-0000-0000-000000000000"
401
428
}
402
429
" have a nuid if SP-Anonymous is not present" in {
403
430
val l = `Location`(" l" )
@@ -671,17 +698,42 @@ class CollectorServiceSpec extends Specification {
671
698
}
672
699
673
700
" netwokUserId" in {
674
- " give back the nuid query param if present" in {
675
- service.networkUserId(
676
- HttpRequest ().withUri(Uri ().withRawQueryString(" nuid=12" )),
677
- Some (HttpCookie (" nuid" , " 13" ))
678
- ) shouldEqual Some (" 12" )
679
- }
680
- " give back the request cookie if there no nuid query param" in {
681
- service.networkUserId(HttpRequest (), Some (HttpCookie (" nuid" , " 13" ))) shouldEqual Some (" 13" )
701
+ " with SP-Anonymous header not present" in {
702
+ " give back the nuid query param if present" in {
703
+ service.networkUserId(
704
+ HttpRequest ().withUri(Uri ().withRawQueryString(" nuid=12" )),
705
+ Some (HttpCookie (" nuid" , " 13" )),
706
+ None
707
+ ) shouldEqual Some (" 12" )
708
+ }
709
+ " give back the request cookie if there no nuid query param" in {
710
+ service.networkUserId(HttpRequest (), Some (HttpCookie (" nuid" , " 13" )), None ) shouldEqual Some (" 13" )
711
+ }
712
+ " give back none otherwise" in {
713
+ service.networkUserId(HttpRequest (), None , None ) shouldEqual None
714
+ }
682
715
}
683
- " give back none otherwise" in {
684
- service.networkUserId(HttpRequest (), None ) shouldEqual None
716
+
717
+ " with SP-Anonymous header present" in {
718
+ " give back the dummy nuid" in {
719
+ " if query param is present" in {
720
+ service.networkUserId(
721
+ HttpRequest ().withUri(Uri ().withRawQueryString(" nuid=12" )),
722
+ Some (HttpCookie (" nuid" , " 13" )),
723
+ Some (" *" )
724
+ ) shouldEqual Some (" 00000000-0000-0000-0000-000000000000" )
725
+ }
726
+ " if the request cookie can be used in place of a missing nuid query param" in {
727
+ service.networkUserId(HttpRequest (), Some (HttpCookie (" nuid" , " 13" )), Some (" *" )) shouldEqual Some (
728
+ " 00000000-0000-0000-0000-000000000000"
729
+ )
730
+ }
731
+ " in any other case" in {
732
+ service.networkUserId(HttpRequest (), None , Some (" *" )) shouldEqual Some (
733
+ " 00000000-0000-0000-0000-000000000000"
734
+ )
735
+ }
736
+ }
685
737
}
686
738
}
687
739
0 commit comments