@@ -664,4 +664,96 @@ - (void)testUserAccountEncoding {
664664 XCTAssertEqual (userIn.accessRestrictions , userOut.accessRestrictions , @" accessRestrictions mismatch" );
665665}
666666
667+ #pragma mark - authRequestWithLoginHost Tests
668+
669+ - (void )testAuthRequestWithLoginHostDefaults {
670+ // Setup default values
671+ NSString *expectedLoginHost = @" https://login.salesforce.com" ;
672+ NSString *expectedClientId = @" testClientId" ;
673+ NSString *expectedRedirectUri = @" testapp://oauth/done" ;
674+ NSSet *expectedScopes = [NSSet setWithObjects: @" api" , @" web" , @" refresh_token" , nil ];
675+
676+ self.uam .loginHost = expectedLoginHost;
677+ self.uam .oauthClientId = expectedClientId;
678+ self.uam .oauthCompletionUrl = expectedRedirectUri;
679+ self.uam .scopes = expectedScopes;
680+
681+ // Call with nil loginHost and nil appConfig (should use defaults)
682+ SFSDKAuthRequest *request = [self .uam authRequestWithLoginHost: nil appConfig: nil ];
683+
684+ XCTAssertNotNil (request, @" Auth request should not be nil" );
685+ XCTAssertEqualObjects (request.loginHost , expectedLoginHost, @" Login host should match default" );
686+ XCTAssertEqualObjects (request.oauthClientId , expectedClientId, @" Client ID should match default" );
687+ XCTAssertEqualObjects (request.oauthCompletionUrl , expectedRedirectUri, @" Redirect URI should match default" );
688+ XCTAssertEqualObjects (request.scopes , expectedScopes, @" Scopes should match default" );
689+ }
690+
691+ - (void )testAuthRequestWithLoginHostCustomHost {
692+ // Setup default values
693+ NSString *defaultLoginHost = @" https://login.salesforce.com" ;
694+ NSString *customLoginHost = @" https://test.salesforce.com" ;
695+ NSString *expectedClientId = @" testClientId" ;
696+
697+ self.uam .loginHost = defaultLoginHost;
698+ self.uam .oauthClientId = expectedClientId;
699+
700+ // Call with custom loginHost
701+ SFSDKAuthRequest *request = [self .uam authRequestWithLoginHost: customLoginHost appConfig: nil ];
702+
703+ XCTAssertNotNil (request, @" Auth request should not be nil" );
704+ XCTAssertEqualObjects (request.loginHost , customLoginHost, @" Login host should be custom value, not default" );
705+ XCTAssertEqualObjects (request.oauthClientId , expectedClientId, @" Client ID should match default" );
706+ }
707+
708+ - (void )testAuthRequestWithLoginHostWithAppConfig {
709+ // Setup default values
710+ NSString *defaultLoginHost = @" https://login.salesforce.com" ;
711+ NSString *defaultClientId = @" defaultClientId" ;
712+ NSString *defaultRedirectUri = @" defaultapp://oauth/done" ;
713+ NSSet *defaultScopes = [NSSet setWithObjects: @" api" , @" web" , nil ];
714+
715+ self.uam .loginHost = defaultLoginHost;
716+ self.uam .oauthClientId = defaultClientId;
717+ self.uam .oauthCompletionUrl = defaultRedirectUri;
718+ self.uam .scopes = defaultScopes;
719+
720+ // Create app config with different values
721+ NSString *appConfigClientId = @" appConfigClientId" ;
722+ NSString *appConfigRedirectUri = @" appconfig://oauth/done" ;
723+ NSSet *appConfigScopes = [NSSet setWithObjects: @" id" , @" api" , @" refresh_token" , nil ];
724+
725+ NSDictionary *configDict = @{
726+ @" remoteAccessConsumerKey" : appConfigClientId,
727+ @" oauthRedirectURI" : appConfigRedirectUri,
728+ @" oauthScopes" : [appConfigScopes allObjects ],
729+ @" shouldAuthenticate" : @YES
730+ };
731+ SFSDKAppConfig *appConfig = [[SFSDKAppConfig alloc ] initWithDict: configDict];
732+
733+ // Call with appConfig
734+ SFSDKAuthRequest *request = [self .uam authRequestWithLoginHost: nil appConfig: appConfig];
735+
736+ XCTAssertNotNil (request, @" Auth request should not be nil" );
737+ XCTAssertEqualObjects (request.loginHost , defaultLoginHost, @" Login host should match default" );
738+ XCTAssertEqualObjects (request.oauthClientId , appConfigClientId, @" Client ID should come from appConfig" );
739+ XCTAssertEqualObjects (request.oauthCompletionUrl , appConfigRedirectUri, @" Redirect URI should come from appConfig" );
740+ XCTAssertEqualObjects (request.scopes , appConfigScopes, @" Scopes should come from appConfig" );
741+ }
742+
743+ - (void )testDefaultAuthRequestUsesAuthRequestWithLoginHost {
744+ // Setup default values
745+ NSString *expectedLoginHost = @" https://login.salesforce.com" ;
746+ NSString *expectedClientId = @" testClientId" ;
747+
748+ self.uam .loginHost = expectedLoginHost;
749+ self.uam .oauthClientId = expectedClientId;
750+
751+ // defaultAuthRequest should call authRequestWithLoginHost:nil appConfig:nil
752+ SFSDKAuthRequest *request = [self .uam defaultAuthRequest ];
753+
754+ XCTAssertNotNil (request, @" Default auth request should not be nil" );
755+ XCTAssertEqualObjects (request.loginHost , expectedLoginHost, @" Login host should match default" );
756+ XCTAssertEqualObjects (request.oauthClientId , expectedClientId, @" Client ID should match default" );
757+ }
758+
667759@end
0 commit comments