@@ -492,7 +492,10 @@ def test_validate_basic(self):
492
492
assert result ['errors' ] == []
493
493
assert 'message' in result
494
494
assert 'culprit' in result
495
- assert 'tags' in result
495
+ assert result ['tags' ] == [
496
+ ('effective-directive' , 'img-src' ),
497
+ ('blocked-uri' , 'http://google.com' ),
498
+ ]
496
499
assert result ['sentry.interfaces.User' ] == {'ip_address' : '69.69.69.69' }
497
500
assert result ['sentry.interfaces.Http' ] == {
498
501
'url' : 'http://45.55.25.245:8123/csp' ,
@@ -506,3 +509,58 @@ def test_validate_basic(self):
506
509
def test_validate_raises_invalid_interface (self ):
507
510
with self .assertRaises (APIForbidden ):
508
511
self .helper .validate_data (self .project , {})
512
+
513
+ def test_tags_out_of_bounds (self ):
514
+ report = {
515
+ "document-uri" : "http://45.55.25.245:8123/csp" ,
516
+ "referrer" : "http://example.com" ,
517
+ "violated-directive" : "img-src https://45.55.25.245:8123/" ,
518
+ "effective-directive" : "img-src" ,
519
+ "original-policy" : "default-src https://45.55.25.245:8123/; child-src https://45.55.25.245:8123/; connect-src https://45.55.25.245:8123/; font-src https://45.55.25.245:8123/; img-src https://45.55.25.245:8123/; media-src https://45.55.25.245:8123/; object-src https://45.55.25.245:8123/; script-src https://45.55.25.245:8123/; style-src https://45.55.25.245:8123/; form-action https://45.55.25.245:8123/; frame-ancestors 'none'; plugin-types 'none'; report-uri http://45.55.25.245:8123/csp-report?os=OS%20X&device=&browser_version=43.0&browser=chrome&os_version=Lion" ,
520
+ "blocked-uri" : "v" * 201 ,
521
+ "status-code" : 200 ,
522
+ "_meta" : {
523
+ "release" : "abc123" ,
524
+ }
525
+ }
526
+ result = self .helper .validate_data (self .project , report )
527
+ assert result ['tags' ] == [
528
+ ('effective-directive' , 'img-src' ),
529
+ ]
530
+ assert len (result ['errors' ]) == 1
531
+
532
+ def test_tag_value (self ):
533
+ report = {
534
+ "document-uri" : "http://45.55.25.245:8123/csp" ,
535
+ "referrer" : "http://example.com" ,
536
+ "violated-directive" : "img-src https://45.55.25.245:8123/" ,
537
+ "effective-directive" : "img-src" ,
538
+ "original-policy" : "default-src https://45.55.25.245:8123/; child-src https://45.55.25.245:8123/; connect-src https://45.55.25.245:8123/; font-src https://45.55.25.245:8123/; img-src https://45.55.25.245:8123/; media-src https://45.55.25.245:8123/; object-src https://45.55.25.245:8123/; script-src https://45.55.25.245:8123/; style-src https://45.55.25.245:8123/; form-action https://45.55.25.245:8123/; frame-ancestors 'none'; plugin-types 'none'; report-uri http://45.55.25.245:8123/csp-report?os=OS%20X&device=&browser_version=43.0&browser=chrome&os_version=Lion" ,
539
+ "blocked-uri" : "http://google.com\n " ,
540
+ "status-code" : 200 ,
541
+ "_meta" : {
542
+ "release" : "abc123" ,
543
+ }
544
+ }
545
+ result = self .helper .validate_data (self .project , report )
546
+ assert result ['tags' ] == [
547
+ ('effective-directive' , 'img-src' ),
548
+ ]
549
+ assert len (result ['errors' ]) == 1
550
+
551
+ def test_no_tags (self ):
552
+ report = {
553
+ "document-uri" : "http://45.55.25.245:8123/csp" ,
554
+ "referrer" : "http://example.com" ,
555
+ "violated-directive" : "img-src https://45.55.25.245:8123/" ,
556
+ "effective-directive" : "v" * 201 ,
557
+ "original-policy" : "default-src https://45.55.25.245:8123/; child-src https://45.55.25.245:8123/; connect-src https://45.55.25.245:8123/; font-src https://45.55.25.245:8123/; img-src https://45.55.25.245:8123/; media-src https://45.55.25.245:8123/; object-src https://45.55.25.245:8123/; script-src https://45.55.25.245:8123/; style-src https://45.55.25.245:8123/; form-action https://45.55.25.245:8123/; frame-ancestors 'none'; plugin-types 'none'; report-uri http://45.55.25.245:8123/csp-report?os=OS%20X&device=&browser_version=43.0&browser=chrome&os_version=Lion" ,
558
+ "blocked-uri" : "http://google.com\n " ,
559
+ "status-code" : 200 ,
560
+ "_meta" : {
561
+ "release" : "abc123" ,
562
+ }
563
+ }
564
+ result = self .helper .validate_data (self .project , report )
565
+ assert 'tags' not in result
566
+ assert len (result ['errors' ]) == 2
0 commit comments