@@ -1047,6 +1047,51 @@ describe('globals', function() {
1047
1047
assert . isFunction ( opts . onError ) ;
1048
1048
} ) ;
1049
1049
1050
+ it ( 'should pass sentry_secret as part of auth params if specified' , function ( ) {
1051
+ this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
1052
+ this . sinon . stub ( Raven , '_makeRequest' ) ;
1053
+ this . sinon . stub ( Raven , '_getHttpData' ) . returns ( {
1054
+ url : 'http://localhost/?a=b' ,
1055
+ headers : { 'User-Agent' : 'lolbrowser' }
1056
+ } ) ;
1057
+
1058
+ Raven . _globalEndpoint = 'http://localhost/store/' ;
1059
+ Raven . _globalOptions = {
1060
+ projectId : 2 ,
1061
+ logger : 'javascript' ,
1062
+ maxMessageLength : 100 ,
1063
+ release : 'abc123'
1064
+ } ; ;
1065
+ Raven . _globalSecret = 'def' ; // <-- secret
1066
+
1067
+ Raven . _send ( { message : 'bar' } ) ;
1068
+ var args = Raven . _makeRequest . lastCall . args ;
1069
+ assert . equal ( args . length , 1 ) ;
1070
+ var opts = args [ 0 ] ;
1071
+ assert . equal ( opts . url , 'http://localhost/store/' ) ;
1072
+ assert . deepEqual ( opts . data , {
1073
+ project : '2' ,
1074
+ release : 'abc123' ,
1075
+ logger : 'javascript' ,
1076
+ platform : 'javascript' ,
1077
+ request : {
1078
+ url : 'http://localhost/?a=b' ,
1079
+ headers : {
1080
+ 'User-Agent' : 'lolbrowser'
1081
+ }
1082
+ } ,
1083
+ event_id : 'abc123' ,
1084
+ message : 'bar' ,
1085
+ extra : { 'session:duration' : 100 } ,
1086
+ } ) ;
1087
+ assert . deepEqual ( opts . auth , {
1088
+ sentry_client : 'raven-js/2.1.0' ,
1089
+ sentry_key : 'abc' ,
1090
+ sentry_secret : 'def' ,
1091
+ sentry_version : '7'
1092
+ } ) ;
1093
+ } ) ;
1094
+
1050
1095
it ( 'should call globalOptions.transport if specified' , function ( ) {
1051
1096
this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
1052
1097
this . sinon . stub ( Raven , '_getHttpData' ) . returns ( {
@@ -1528,12 +1573,33 @@ describe('Raven (public API)', function() {
1528
1573
assert . equal ( Raven , Raven . config ( SENTRY_DSN , { foo : 'bar' } ) , 'it should return Raven' ) ;
1529
1574
1530
1575
assert . equal ( Raven . _globalKey , 'abc' ) ;
1576
+ assert . equal ( Raven . _globalSecret , '' ) ;
1531
1577
assert . equal ( Raven . _globalEndpoint , 'http://example.com:80/api/2/store/' ) ;
1532
1578
assert . equal ( Raven . _globalOptions . foo , 'bar' ) ;
1533
1579
assert . equal ( Raven . _globalProject , '2' ) ;
1534
1580
assert . isTrue ( Raven . isSetup ( ) ) ;
1535
1581
} ) ;
1536
1582
1583
+ it ( 'throw an Error if the DSN contains a private/secret key' , function ( ) {
1584
+ assert . throws ( function ( ) {
1585
+ Raven . config ( 'http://abc:[email protected] :80/2' ) ;
1586
+ } , Error ) ;
1587
+ } ) ;
1588
+
1589
+ it ( 'will NOT throw an Error if the DSN contains a private/secret key AND allowSecretKey is true' , function ( ) {
1590
+ assert . equal (
1591
+ Raven ,
1592
+ Raven . config ( 'http://abc:[email protected] :80/2' , { allowSecretKey :
true } ) ,
1593
+ 'it should return Raven'
1594
+ ) ;
1595
+
1596
+ assert . equal ( Raven . _globalKey , 'abc' ) ;
1597
+ assert . equal ( Raven . _globalSecret , 'def' ) ;
1598
+ assert . equal ( Raven . _globalEndpoint , 'http://example.com:80/api/2/store/' ) ;
1599
+ assert . equal ( Raven . _globalProject , '2' ) ;
1600
+ assert . isTrue ( Raven . isSetup ( ) ) ;
1601
+ } ) ;
1602
+
1537
1603
it ( 'should work with a protocol relative DSN' , function ( ) {
1538
1604
Raven . config ( '//[email protected] /2' ) ;
1539
1605
0 commit comments