@@ -1047,6 +1047,51 @@ describe('globals', function() {
10471047 assert . isFunction ( opts . onError ) ;
10481048 } ) ;
10491049
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+
10501095 it ( 'should call globalOptions.transport if specified' , function ( ) {
10511096 this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
10521097 this . sinon . stub ( Raven , '_getHttpData' ) . returns ( {
@@ -1528,12 +1573,33 @@ describe('Raven (public API)', function() {
15281573 assert . equal ( Raven , Raven . config ( SENTRY_DSN , { foo : 'bar' } ) , 'it should return Raven' ) ;
15291574
15301575 assert . equal ( Raven . _globalKey , 'abc' ) ;
1576+ assert . equal ( Raven . _globalSecret , '' ) ;
15311577 assert . equal ( Raven . _globalEndpoint , 'http://example.com:80/api/2/store/' ) ;
15321578 assert . equal ( Raven . _globalOptions . foo , 'bar' ) ;
15331579 assert . equal ( Raven . _globalProject , '2' ) ;
15341580 assert . isTrue ( Raven . isSetup ( ) ) ;
15351581 } ) ;
15361582
1583+ it ( 'throw an Error if the DSN contains a private/secret key' , function ( ) {
1584+ assert . throws ( function ( ) {
1585+ Raven . config ( 'http://abc:def@example.com: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:def@example.com: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+
15371603 it ( 'should work with a protocol relative DSN' , function ( ) {
15381604 Raven . config ( '//abc@example.com/2' ) ;
15391605
0 commit comments