|
| 1 | +/* |
| 2 | + Copyright (c) 2025-present, salesforce.com, inc. All rights reserved. |
| 3 | + |
| 4 | + Redistribution and use of this software in source and binary forms, with or without modification, |
| 5 | + are permitted provided that the following conditions are met: |
| 6 | + * Redistributions of source code must retain the above copyright notice, this list of conditions |
| 7 | + and the following disclaimer. |
| 8 | + * Redistributions in binary form must reproduce the above copyright notice, this list of |
| 9 | + conditions and the following disclaimer in the documentation and/or other materials provided |
| 10 | + with the distribution. |
| 11 | + * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to |
| 12 | + endorse or promote products derived from this software without specific prior written |
| 13 | + permission of salesforce.com, inc. |
| 14 | + |
| 15 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR |
| 16 | + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 18 | + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 20 | + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 21 | + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY |
| 22 | + WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | + */ |
| 24 | + |
| 25 | +#import <XCTest/XCTest.h> |
| 26 | +#import <SalesforceSDKCore/SalesforceSDKCore.h> |
| 27 | + |
| 28 | +@interface SFOAuthInfoTests : XCTestCase |
| 29 | + |
| 30 | +@end |
| 31 | + |
| 32 | +@implementation SFOAuthInfoTests |
| 33 | + |
| 34 | +- (void)testAuthTypeDescription { |
| 35 | + // Test SFOAuthTypeUnknown |
| 36 | + SFOAuthInfo *unknownInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeUnknown]; |
| 37 | + XCTAssertEqualObjects(unknownInfo.authTypeDescription, @"SFOAuthTypeUnknown", @"Unknown auth type should return correct description"); |
| 38 | + XCTAssertEqual(unknownInfo.authType, SFOAuthTypeUnknown, @"Auth type should be Unknown"); |
| 39 | + |
| 40 | + // Test SFOAuthTypeUserAgent |
| 41 | + SFOAuthInfo *userAgentInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeUserAgent]; |
| 42 | + XCTAssertEqualObjects(userAgentInfo.authTypeDescription, @"SFOAuthTypeUserAgent", @"UserAgent auth type should return correct description"); |
| 43 | + XCTAssertEqual(userAgentInfo.authType, SFOAuthTypeUserAgent, @"Auth type should be UserAgent"); |
| 44 | + |
| 45 | + // Test SFOAuthTypeWebServer |
| 46 | + SFOAuthInfo *webServerInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeWebServer]; |
| 47 | + XCTAssertEqualObjects(webServerInfo.authTypeDescription, @"SFOAuthTypeWebServer", @"WebServer auth type should return correct description"); |
| 48 | + XCTAssertEqual(webServerInfo.authType, SFOAuthTypeWebServer, @"Auth type should be WebServer"); |
| 49 | + |
| 50 | + // Test SFOAuthTypeRefresh |
| 51 | + SFOAuthInfo *refreshInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeRefresh]; |
| 52 | + XCTAssertEqualObjects(refreshInfo.authTypeDescription, @"SFOAuthTypeRefresh", @"Refresh auth type should return correct description"); |
| 53 | + XCTAssertEqual(refreshInfo.authType, SFOAuthTypeRefresh, @"Auth type should be Refresh"); |
| 54 | + |
| 55 | + // Test SFOAuthTypeAdvancedBrowser |
| 56 | + SFOAuthInfo *advancedBrowserInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeAdvancedBrowser]; |
| 57 | + XCTAssertEqualObjects(advancedBrowserInfo.authTypeDescription, @"SFOAuthTypeAdvancedBrowser", @"AdvancedBrowser auth type should return correct description"); |
| 58 | + XCTAssertEqual(advancedBrowserInfo.authType, SFOAuthTypeAdvancedBrowser, @"Auth type should be AdvancedBrowser"); |
| 59 | + |
| 60 | + // Test SFOAuthTypeJwtTokenExchange |
| 61 | + SFOAuthInfo *jwtInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeJwtTokenExchange]; |
| 62 | + XCTAssertEqualObjects(jwtInfo.authTypeDescription, @"SFOAuthTypeJwtTokenExchange", @"JwtTokenExchange auth type should return correct description"); |
| 63 | + XCTAssertEqual(jwtInfo.authType, SFOAuthTypeJwtTokenExchange, @"Auth type should be JwtTokenExchange"); |
| 64 | + |
| 65 | + // Test SFOAuthTypeIDP |
| 66 | + SFOAuthInfo *idpInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeIDP]; |
| 67 | + XCTAssertEqualObjects(idpInfo.authTypeDescription, @"SFOAuthTypeIDP", @"IDP auth type should return correct description"); |
| 68 | + XCTAssertEqual(idpInfo.authType, SFOAuthTypeIDP, @"Auth type should be IDP"); |
| 69 | + |
| 70 | + // Test SFOAuthTypeNative |
| 71 | + SFOAuthInfo *nativeInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeNative]; |
| 72 | + XCTAssertEqualObjects(nativeInfo.authTypeDescription, @"SFOAuthTypeNative", @"Native auth type should return correct description"); |
| 73 | + XCTAssertEqual(nativeInfo.authType, SFOAuthTypeNative, @"Auth type should be Native"); |
| 74 | + |
| 75 | + // Test SFOAuthTypeRefreshTokenMigration |
| 76 | + SFOAuthInfo *migrationInfo = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeRefreshTokenMigration]; |
| 77 | + XCTAssertEqualObjects(migrationInfo.authTypeDescription, @"SFOAuthTypeRefreshTokenMigration", @"RefreshTokenMigration auth type should return correct description"); |
| 78 | + XCTAssertEqual(migrationInfo.authType, SFOAuthTypeRefreshTokenMigration, @"Auth type should be RefreshTokenMigration"); |
| 79 | +} |
| 80 | + |
| 81 | +- (void)testDescription { |
| 82 | + // Test that description includes authTypeDescription |
| 83 | + SFOAuthInfo *info = [[SFOAuthInfo alloc] initWithAuthType:SFOAuthTypeRefresh]; |
| 84 | + NSString *description = [info description]; |
| 85 | + |
| 86 | + XCTAssertNotNil(description, @"Description should not be nil"); |
| 87 | + XCTAssertTrue([description containsString:@"SFOAuthInfo"], @"Description should contain class name"); |
| 88 | + XCTAssertTrue([description containsString:@"authType="], @"Description should contain authType label"); |
| 89 | + XCTAssertTrue([description containsString:@"SFOAuthTypeRefresh"], @"Description should contain auth type description"); |
| 90 | +} |
| 91 | + |
| 92 | +@end |
| 93 | + |
0 commit comments