@@ -328,6 +328,138 @@ - (void)testAliasURLWithOptionsAndOverrideAndEventsOnlyAndTrackingHost {
328328 XCTAssert ([aliasURL.accessibilityHint isEqualToString: @" identity" ]);
329329}
330330
331+ - (void )testCustomBaseURLRejectsNonHTTPS {
332+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
333+ options.customBaseURL = [NSURL URLWithString: @" http://rkt.example.com" ];
334+ XCTAssertNil (options.customBaseURL , @" Non-HTTPS customBaseURL should be rejected" );
335+ }
336+
337+ - (void )testConfigURLWithCustomBaseURL {
338+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
339+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
340+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
341+ [MParticle sharedInstance ].networkOptions = options;
342+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
343+ NSURL *configURL = [networkCommunication configURL ].url ;
344+ [self deswizzle ];
345+ XCTAssert ([configURL.absoluteString rangeOfString: @" rkt.example.com/config/v4/" ].location != NSNotFound );
346+ XCTAssert ([configURL.absoluteString rangeOfString: @" config2.mparticle.com" ].location == NSNotFound );
347+ }
348+
349+ - (void )testConfigURLCustomBaseURLOverridesConfigHost {
350+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
351+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
352+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
353+ options.configHost = @" config.mpproxy.example.com" ;
354+ [MParticle sharedInstance ].networkOptions = options;
355+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
356+ NSURL *configURL = [networkCommunication configURL ].url ;
357+ [self deswizzle ];
358+ XCTAssert ([configURL.absoluteString rangeOfString: @" rkt.example.com/config/v4/" ].location != NSNotFound );
359+ XCTAssert ([configURL.absoluteString rangeOfString: @" config.mpproxy.example.com" ].location == NSNotFound );
360+ }
361+
362+ - (void )testModifyURLWithCustomBaseURL {
363+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
364+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
365+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
366+ [MParticle sharedInstance ].networkOptions = options;
367+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
368+ NSURL *modifyURL = [networkCommunication modifyURL ].url ;
369+ [self deswizzle ];
370+ XCTAssert ([modifyURL.absoluteString rangeOfString: @" https://rkt.example.com/identity/v1/" ].location != NSNotFound );
371+ XCTAssert ([modifyURL.absoluteString rangeOfString: @" identity.us1.mparticle.com" ].location == NSNotFound );
372+ XCTAssert ([modifyURL.accessibilityHint isEqualToString: @" identity" ]);
373+ }
374+
375+ - (void )testModifyURLCustomBaseURLOverridesIdentityTrackingHost {
376+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
377+ MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance ].stateMachine ;
378+ stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusAuthorized);
379+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
380+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
381+ options.identityTrackingHost = @" identity-tracking.mpproxy.example.com" ;
382+ [MParticle sharedInstance ].networkOptions = options;
383+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
384+ NSURL *modifyURL = [networkCommunication modifyURL ].url ;
385+ stateMachine.attAuthorizationStatus = nil ;
386+ [self deswizzle ];
387+ XCTAssert ([modifyURL.absoluteString rangeOfString: @" https://rkt.example.com/identity/v1/" ].location != NSNotFound );
388+ XCTAssert ([modifyURL.absoluteString rangeOfString: @" identity-tracking.mpproxy.example.com" ].location == NSNotFound );
389+ }
390+
391+ - (void )testEventURLWithCustomBaseURL {
392+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
393+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
394+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
395+ [MParticle sharedInstance ].networkOptions = options;
396+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
397+ MPUpload *upload = [[MPUpload alloc ] initWithSessionId: nil uploadDictionary: @{} dataPlanId: nil dataPlanVersion: nil uploadSettings: [MPUploadSettings currentUploadSettingsWithStateMachine: [MParticle sharedInstance ].stateMachine networkOptions: [MParticle sharedInstance ].networkOptions]];
398+ NSURL *eventURL = [networkCommunication eventURLForUpload: upload].url ;
399+ [self deswizzle ];
400+ XCTAssert ([eventURL.absoluteString rangeOfString: @" rkt.example.com/nativeevents/v2/" ].location != NSNotFound );
401+ XCTAssert ([eventURL.absoluteString rangeOfString: @" nativesdks.us1.mparticle.com" ].location == NSNotFound );
402+ }
403+
404+ - (void )testEventURLCustomBaseURLAppliesToTrackingHost {
405+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
406+ MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance ].stateMachine ;
407+ stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusAuthorized);
408+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
409+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
410+ [MParticle sharedInstance ].networkOptions = options;
411+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
412+ MPUpload *upload = [[MPUpload alloc ] initWithSessionId: nil uploadDictionary: @{} dataPlanId: nil dataPlanVersion: nil uploadSettings: [MPUploadSettings currentUploadSettingsWithStateMachine: [MParticle sharedInstance ].stateMachine networkOptions: [MParticle sharedInstance ].networkOptions]];
413+ NSURL *eventURL = [networkCommunication eventURLForUpload: upload].url ;
414+ stateMachine.attAuthorizationStatus = nil ;
415+ [self deswizzle ];
416+ XCTAssert ([eventURL.absoluteString rangeOfString: @" rkt.example.com/nativeevents/v2/" ].location != NSNotFound );
417+ XCTAssert ([eventURL.absoluteString rangeOfString: @" tracking-nativesdks" ].location == NSNotFound );
418+ }
419+
420+ - (void )testAliasURLWithCustomBaseURL {
421+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
422+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
423+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
424+ [MParticle sharedInstance ].networkOptions = options;
425+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
426+ MPUpload *upload = [[MPUpload alloc ] initWithSessionId: nil uploadDictionary: @{} dataPlanId: nil dataPlanVersion: nil uploadSettings: [MPUploadSettings currentUploadSettingsWithStateMachine: [MParticle sharedInstance ].stateMachine networkOptions: [MParticle sharedInstance ].networkOptions]];
427+ NSURL *aliasURL = [networkCommunication aliasURLForUpload: upload].url ;
428+ [self deswizzle ];
429+ XCTAssert ([aliasURL.absoluteString rangeOfString: @" https://rkt.example.com/nativeevents/v1/identity/" ].location != NSNotFound );
430+ XCTAssert ([aliasURL.absoluteString rangeOfString: @" nativesdks.us1.mparticle.com" ].location == NSNotFound );
431+ XCTAssert ([aliasURL.accessibilityHint isEqualToString: @" identity" ]);
432+ }
433+
434+ - (void )testAudienceURLWithCustomBaseURL {
435+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
436+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
437+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
438+ [MParticle sharedInstance ].networkOptions = options;
439+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
440+ NSURL *audienceURL = [networkCommunication audienceURL ].url ;
441+ [self deswizzle ];
442+ XCTAssert ([audienceURL.absoluteString rangeOfString: @" rkt.example.com" ].location != NSNotFound );
443+ XCTAssert ([audienceURL.absoluteString rangeOfString: @" mparticle.com" ].location == NSNotFound );
444+ }
445+
446+ - (void )testAliasURLWithCustomBaseURLAndATTAuthorized {
447+ [self swizzleInstanceMethodForInstancesOfClass: [NSBundle class ] selector: @selector (infoDictionary )];
448+ MPStateMachine_PRIVATE *stateMachine = [MParticle sharedInstance ].stateMachine ;
449+ stateMachine.attAuthorizationStatus = @(MPATTAuthorizationStatusAuthorized);
450+ MPNetworkOptions *options = [[MPNetworkOptions alloc ] init ];
451+ options.customBaseURL = [NSURL URLWithString: @" https://rkt.example.com" ];
452+ [MParticle sharedInstance ].networkOptions = options;
453+ MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
454+ MPUpload *upload = [[MPUpload alloc ] initWithSessionId: nil uploadDictionary: @{} dataPlanId: nil dataPlanVersion: nil uploadSettings: [MPUploadSettings currentUploadSettingsWithStateMachine: [MParticle sharedInstance ].stateMachine networkOptions: [MParticle sharedInstance ].networkOptions]];
455+ NSURL *aliasURL = [networkCommunication aliasURLForUpload: upload].url ;
456+ stateMachine.attAuthorizationStatus = nil ;
457+ [self deswizzle ];
458+ XCTAssert ([aliasURL.absoluteString rangeOfString: @" https://rkt.example.com/nativeevents/v1/identity/" ].location != NSNotFound );
459+ XCTAssert ([aliasURL.absoluteString rangeOfString: @" nativesdks.us1.mparticle.com" ].location == NSNotFound );
460+ XCTAssert ([aliasURL.accessibilityHint isEqualToString: @" identity" ]);
461+ }
462+
331463- (void )testEmptyUploadsArray {
332464 MPNetworkCommunication_PRIVATE *networkCommunication = [[MPNetworkCommunication_PRIVATE alloc ] init ];
333465 NSArray *uploads = @[];
0 commit comments