@@ -961,6 +961,156 @@ describe('utils', () => {
961961 delete process . env . CYPRESS_TEST_1 ;
962962 delete process . env . cypress_test_2 ;
963963 } ) ;
964+
965+ const URL_ENV_VARS = [
966+ 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL' ,
967+ 'BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL' ,
968+ ] ;
969+ let savedUrlEnvs = { } ;
970+
971+ beforeEach ( ( ) => {
972+ URL_ENV_VARS . forEach ( ( key ) => {
973+ savedUrlEnvs [ key ] = process . env [ key ] ;
974+ delete process . env [ key ] ;
975+ } ) ;
976+ } ) ;
977+
978+ afterEach ( ( ) => {
979+ URL_ENV_VARS . forEach ( ( key ) => {
980+ if ( savedUrlEnvs [ key ] === undefined ) {
981+ delete process . env [ key ] ;
982+ } else {
983+ process . env [ key ] = savedUrlEnvs [ key ] ;
984+ }
985+ } ) ;
986+ } ) ;
987+
988+ it ( 'forwards the observability collector url for the remote reporter' , ( ) => {
989+ let bsConfig = { run_settings : { env : null } } ;
990+
991+ utils . setSystemEnvs ( bsConfig ) ;
992+ expect ( bsConfig . run_settings . system_env_vars )
993+ . to . be . an ( 'array' )
994+ . that . includes ( 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-observability.browserstack.com' ) ;
995+ } ) ;
996+
997+ it ( 'forwards an overridden observability collector url' , ( ) => {
998+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_API_URL = 'https://collector-example.bsstag.com' ;
999+ let bsConfig = { run_settings : { env : null } } ;
1000+
1001+ utils . setSystemEnvs ( bsConfig ) ;
1002+ expect ( bsConfig . run_settings . system_env_vars )
1003+ . to . be . an ( 'array' )
1004+ . that . includes ( 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-example.bsstag.com' ) ;
1005+ } ) ;
1006+
1007+ it ( 'prefers a separate remote collector url for the remote reporter' , ( ) => {
1008+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_API_URL = 'https://collector-private.bsstag.com' ;
1009+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com' ;
1010+ let bsConfig = { run_settings : { env : null } } ;
1011+
1012+ utils . setSystemEnvs ( bsConfig ) ;
1013+ expect ( bsConfig . run_settings . system_env_vars )
1014+ . to . be . an ( 'array' )
1015+ . that . includes ( 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-public.bsstag.com' ) ;
1016+ } ) ;
1017+
1018+ it ( 'warns when only the remote collector is overridden' , ( ) => {
1019+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com' ;
1020+ const warn = sinon . stub ( logger , 'warn' ) ;
1021+
1022+ try {
1023+ utils . validateCollectorUrls ( ) ;
1024+ sinon . assert . calledOnce ( warn ) ;
1025+ expect ( warn . firstCall . args [ 0 ] ) . to . match ( / c o l l e c t o r - p u b l i c \. b s s t a g \. c o m / ) ;
1026+ expect ( warn . firstCall . args [ 0 ] ) . to . match ( / s a m e e n v i r o n m e n t / ) ;
1027+ } finally {
1028+ warn . restore ( ) ;
1029+ }
1030+ } ) ;
1031+
1032+ it ( 'names only the host in that warning, never the path' , ( ) => {
1033+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com/t0ken' ;
1034+ const warn = sinon . stub ( logger , 'warn' ) ;
1035+
1036+ try {
1037+ utils . validateCollectorUrls ( ) ;
1038+ expect ( warn . firstCall . args [ 0 ] ) . to . not . match ( / t 0 k e n / ) ;
1039+ } finally {
1040+ warn . restore ( ) ;
1041+ }
1042+ } ) ;
1043+
1044+ it ( 'does not warn when both collector urls are set' , ( ) => {
1045+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_API_URL = 'https://collector-private.bsstag.com' ;
1046+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com' ;
1047+ const warn = sinon . stub ( logger , 'warn' ) ;
1048+
1049+ try {
1050+ utils . validateCollectorUrls ( ) ;
1051+ sinon . assert . notCalled ( warn ) ;
1052+ } finally {
1053+ warn . restore ( ) ;
1054+ }
1055+ } ) ;
1056+
1057+ it ( 'neither warns nor throws when no collector url is overridden' , ( ) => {
1058+ const warn = sinon . stub ( logger , 'warn' ) ;
1059+
1060+ try {
1061+ expect ( ( ) => utils . validateCollectorUrls ( ) ) . to . not . throw ( ) ;
1062+ sinon . assert . notCalled ( warn ) ;
1063+ } finally {
1064+ warn . restore ( ) ;
1065+ }
1066+ } ) ;
1067+
1068+ it ( 'rejects a collector url carrying a username or password' , ( ) => {
1069+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://user:secret@collector-public.bsstag.com' ;
1070+
1071+ expect ( ( ) => utils . validateCollectorUrls ( ) ) . to . throw ( / m u s t n o t c o n t a i n a u s e r n a m e o r p a s s w o r d / ) ;
1072+ } ) ;
1073+
1074+ it ( 'validates both overrides, even when the remote one is valid' , ( ) => {
1075+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_API_URL = 'http://collector-private.bsstag.com' ;
1076+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com' ;
1077+
1078+ expect ( ( ) => utils . validateCollectorUrls ( ) ) . to . throw ( / B R O W S E R S T A C K _ T E S T _ O B S E R V A B I L I T Y _ A P I _ U R L m u s t b e a n h t t p s / ) ;
1079+ } ) ;
1080+
1081+ it ( 'rejects a collector url that is not https' , ( ) => {
1082+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'http://collector-public.bsstag.com' ;
1083+ let bsConfig = { run_settings : { env : null } } ;
1084+
1085+ expect ( ( ) => utils . setSystemEnvs ( bsConfig ) ) . to . throw ( / m u s t b e a n h t t p s : \/ \/ U R L / ) ;
1086+ } ) ;
1087+
1088+ it ( 'rejects a collector url carrying a query or fragment' , ( ) => {
1089+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com/#staging' ;
1090+ let bsConfig = { run_settings : { env : null } } ;
1091+
1092+ expect ( ( ) => utils . setSystemEnvs ( bsConfig ) ) . to . throw ( / m u s t n o t c o n t a i n a q u e r y o r f r a g m e n t / ) ;
1093+ } ) ;
1094+
1095+ it ( 'normalises a bare query or fragment delimiter' , ( ) => {
1096+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com?' ;
1097+ let bsConfig = { run_settings : { env : null } } ;
1098+
1099+ utils . setSystemEnvs ( bsConfig ) ;
1100+ expect ( bsConfig . run_settings . system_env_vars )
1101+ . to . be . an ( 'array' )
1102+ . that . includes ( 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-public.bsstag.com' ) ;
1103+ } ) ;
1104+
1105+ it ( 'trims a trailing slash so endpoint paths are not doubled' , ( ) => {
1106+ process . env . BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL = 'https://collector-public.bsstag.com/' ;
1107+ let bsConfig = { run_settings : { env : null } } ;
1108+
1109+ utils . setSystemEnvs ( bsConfig ) ;
1110+ expect ( bsConfig . run_settings . system_env_vars )
1111+ . to . be . an ( 'array' )
1112+ . that . includes ( 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL=https://collector-public.bsstag.com' ) ;
1113+ } ) ;
9641114 } ) ;
9651115
9661116 describe ( 'fixCommaSeparatedString' , ( ) => {
0 commit comments