|
22 | 22 | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | 23 | */ |
24 | 24 |
|
25 | | -#import "SalesforceSDKIdentityTests.h" |
26 | | -#import "SFSDKTestRequestListener.h" |
27 | | -#import "TestSetupUtils.h" |
28 | | -#import "SFOAuthCoordinator.h" |
| 25 | +#import <XCTest/XCTest.h> |
29 | 26 | #import "SFIdentityCoordinator.h" |
30 | 27 | #import "SFUserAccountManager.h" |
31 | 28 | #import "SFIdentityData.h" |
32 | 29 |
|
33 | | -/** |
34 | | - * Private interface for this tests module. |
35 | | - */ |
36 | | -@interface SalesforceSDKIdentityTests() |
37 | | -/** |
38 | | - * Synchronous wrapper around the asynchronous request to the identity service. |
39 | | - */ |
40 | | -- (void)sendSyncIdentityRequest; |
| 30 | +@interface SFIdentityCoordinator () |
41 | 31 |
|
42 | | -/** |
43 | | - * Does a cursory pass on the identity data, to sanity check values. |
44 | | - */ |
45 | | -- (void)validateIdentityData; |
| 32 | +- (void)processResponse:(NSData *)data; |
46 | 33 |
|
47 | | - |
48 | | -@property (nonatomic,strong) SFUserAccount *account; |
49 | | - |
50 | | -@property (nonatomic,strong) XCTestExpectation *expectation; |
51 | | - |
52 | | -@property (nonatomic,assign) BOOL requestHasFailed; |
| 34 | +@end |
53 | 35 |
|
54 | 36 |
|
| 37 | +@interface SalesforceSDKIdentityTests : XCTestCase |
55 | 38 | @end |
56 | 39 |
|
57 | | -static NSException *authException = nil; |
58 | | - |
59 | 40 | @implementation SalesforceSDKIdentityTests |
60 | 41 |
|
61 | | -#pragma mark - Test / class setup |
62 | | - |
63 | | -+ (void)setUp |
64 | | -{ |
65 | | - @try { |
66 | | - [TestSetupUtils populateAuthCredentialsFromConfigFileForClass:[self class]]; |
67 | | - [TestSetupUtils synchronousAuthRefresh]; |
68 | | - |
69 | | - } |
70 | | - @catch (NSException *exception) { |
71 | | - authException = exception; |
72 | | - } |
73 | | - [super setUp]; |
74 | | -} |
75 | | - |
76 | | -- (void)setUp |
77 | | -{ |
78 | | - if (authException) { |
79 | | - XCTFail(@"Setting up authentication failed: %@", authException); |
80 | | - } |
81 | | - |
82 | | - // Set-up code here. |
83 | | - _requestListener = nil; |
84 | | - self.expectation = nil; |
85 | | - self.account = nil; |
86 | | - [super setUp]; |
87 | | -} |
88 | | - |
89 | | -#pragma mark - Helper methods |
90 | | - |
91 | | -- (void)sendSyncIdentityRequest |
92 | | -{ |
93 | | - XCTestExpectation *expectation = [self expectationWithDescription:@"retrieveIdentityData"]; |
94 | | - self.expectation = expectation; |
95 | | - self.account = [SFUserAccountManager sharedInstance].currentUser; |
96 | | - SFIdentityCoordinator *idCoordinator = [[SFIdentityCoordinator alloc] initWithCredentials:self.account.credentials]; |
97 | | - idCoordinator.delegate = self; |
98 | | - [idCoordinator initiateIdentityDataRetrieval]; |
99 | | - [self waitForExpectations:@[expectation] timeout:10]; |
100 | | - XCTAssertFalse(self.requestHasFailed); |
101 | | - |
102 | | -} |
103 | | - |
104 | | -#pragma mark - Tests |
105 | | - |
106 | 42 | /** |
107 | | - * Tests that identity data can be successfully retrieved with valid credentials. |
| 43 | + * Tests that identity data can be successfully processed |
108 | 44 | */ |
109 | | -- (void)testRetrieveIdentitySuccess |
| 45 | +- (void)testProcessIdentityData |
110 | 46 | { |
111 | | - [self sendSyncIdentityRequest]; |
112 | | - [self validateIdentityData]; |
113 | | -} |
114 | | - |
| 47 | + NSString *identityResponse = @"{\"id\":\"https://login.salesforce.com/id/some-org-id/some-user-id\",\"asserted_user\":true,\"user_id\":\"some-user-id\",\"organization_id\":\"some-org-id\",\"username\":\" [email protected]\",\"nick_name\":\"nickname\",\"display_name\":\"Example User\",\"email\":\" [email protected]\",\"email_verified\":true,\"first_name\":\"Example\",\"last_name\":\"User\",\"timezone\":\"America/Los_Angeles\",\"photos\":{\"picture\":\"https://example.com/profilephoto/full\",\"thumbnail\":\"https://example.com/profilephoto/thumb\"},\"addr_street\":null,\"addr_city\":null,\"addr_state\":null,\"addr_country\":null,\"addr_zip\":null,\"mobile_phone\":null,\"mobile_phone_verified\":false,\"is_lightning_login_user\":false,\"status\":{\"created_date\":null,\"body\":null},\"urls\":{\"enterprise\":\"https://example.my.salesforce.com/services/Soap/c/some-version/some-org-id\",\"metadata\":\"https://example.my.salesforce.com/services/Soap/m/some-version/some-org-id\",\"partner\":\"https://example.my.salesforce.com/services/Soap/u/some-version/some-org-id\",\"rest\":\"https://example.my.salesforce.com/services/data/vsome-version/\",\"sobjects\":\"https://example.my.salesforce.com/services/data/vsome-version/sobjects/\",\"search\":\"https://example.my.salesforce.com/services/data/vsome-version/search/\",\"query\":\"https://example.my.salesforce.com/services/data/vsome-version/query/\",\"recent\":\"https://example.my.salesforce.com/services/data/vsome-version/recent/\",\"tooling_soap\":\"https://example.my.salesforce.com/services/Soap/T/some-version/some-org-id\",\"tooling_rest\":\"https://example.my.salesforce.com/services/data/vsome-version/tooling/\",\"profile\":\"https://example.my.salesforce.com/some-user-id\",\"feeds\":\"https://example.my.salesforce.com/services/data/vsome-version/chatter/feeds\",\"groups\":\"https://example.my.salesforce.com/services/data/vsome-version/chatter/groups\",\"users\":\"https://example.my.salesforce.com/services/data/vsome-version/chatter/users\",\"feed_items\":\"https://example.my.salesforce.com/services/data/vsome-version/chatter/feed-items\",\"feed_elements\":\"https://example.my.salesforce.com/services/data/vsome-version/chatter/feed-elements\",\"custom_domain\":\"https://example.my.salesforce.com\"},\"active\":true,\"user_type\":\"STANDARD\",\"language\":\"en_US\",\"locale\":\"en_US\",\"utcOffset\":-28800000,\"last_modified_date\":\"2024-12-23T18:40:50Z\"}"; |
115 | 48 |
|
116 | | -- (void)identityCoordinator:(nonnull SFIdentityCoordinator *)coordinator didFailWithError:(nonnull NSError *)error { |
117 | | - self.requestHasFailed = true; |
118 | | - [self.expectation fulfill]; |
119 | | -} |
120 | | - |
121 | | -- (void)identityCoordinatorRetrievedData:(nonnull SFIdentityCoordinator *)coordinator { |
122 | | - self.account.idData = coordinator.idData; |
123 | | - [self.expectation fulfill]; |
124 | | -} |
125 | | - |
126 | | -#pragma mark - Private helper methods |
127 | | - |
128 | | -- (void)validateIdentityData |
129 | | -{ |
130 | | - SFIdentityData *idData = self.account.idData; |
131 | | - XCTAssertNotNil(idData, @"Identity data is nil."); |
132 | | - XCTAssertNotNil(idData.dictRepresentation, @"idData.dictRepresentation should not be nil."); |
133 | | - XCTAssertNotNil(idData.idUrl, @"idUrl should not be nil."); |
134 | | - XCTAssertTrue(idData.assertedUser, @"assertedUser should be true."); |
135 | | - XCTAssertNotNil(idData.userId, @"userId should not be nil."); |
136 | | - XCTAssertNotNil(idData.orgId, @"orgId should not be nil."); |
137 | | - XCTAssertNotNil(idData.username, @"username should not be nil."); |
138 | | - XCTAssertNotNil(idData.nickname, @"nickname should not be nil."); |
139 | | - XCTAssertNotNil(idData.displayName, @"displayName should not be nil."); |
140 | | - XCTAssertNotNil(idData.email, @"email should not be nil."); |
141 | | - XCTAssertNotNil(idData.firstName, @"firstName should not be nil."); |
142 | | - XCTAssertNotNil(idData.lastName, @"lastName should not be nil."); |
143 | | - XCTAssertNotNil(idData.pictureUrl, @"pictureUrl should not be nil."); |
144 | | - XCTAssertNotNil(idData.thumbnailUrl, @"thumbnailUrl should not be nil."); |
145 | | - XCTAssertNotNil(idData.enterpriseSoapUrl, @"enterpriseSoapUrl should not be nil."); |
146 | | - XCTAssertNotNil(idData.metadataSoapUrl, @"metadataSoapUrl should not be nil."); |
147 | | - XCTAssertNotNil(idData.partnerSoapUrl, @"partnerSoapUrl should not be nil."); |
148 | | - XCTAssertNotNil(idData.restUrl, @"restUrl should not be nil."); |
149 | | - XCTAssertNotNil(idData.restSObjectsUrl, @"restSObjectsUrl should not be nil."); |
150 | | - XCTAssertNotNil(idData.restSearchUrl, @"restSearchUrl should not be nil."); |
151 | | - XCTAssertNotNil(idData.restQueryUrl, @"restQueryUrl should not be nil."); |
152 | | - XCTAssertNotNil(idData.restRecentUrl, @"restRecentUrl should not be nil."); |
153 | | - XCTAssertNotNil(idData.profileUrl, @"profileUrl should not be nil."); |
154 | | - XCTAssertNotNil(idData.chatterFeedsUrl, @"chatterFeedsUrl should not be nil."); |
155 | | - XCTAssertNotNil(idData.chatterGroupsUrl, @"chatterGroupsUrl should not be nil."); |
156 | | - XCTAssertNotNil(idData.chatterUsersUrl, @"chatterUsersUrl should not be nil."); |
157 | | - XCTAssertNotNil(idData.chatterFeedItemsUrl, @"chatterFeedItemsUrl should not be nil."); |
158 | | - XCTAssertTrue(idData.isActive, @"isActive should be true."); |
159 | | - XCTAssertNotNil(idData.userType, @"userType should not be nil."); |
160 | | - XCTAssertNotNil(idData.language, @"language should not be nil."); |
161 | | - XCTAssertNotNil(idData.locale, @"locale should not be nil."); |
162 | | - XCTAssertFalse(idData.utcOffset == -1, @"No value determined for utcOffset."); |
163 | | - XCTAssertNotNil(idData.lastModifiedDate, @"lastModifiedDate should not be nil."); |
| 49 | + |
| 50 | + SFIdentityCoordinator* coordinator = [[SFIdentityCoordinator alloc] init]; |
| 51 | + NSData* identityResponseData = [identityResponse dataUsingEncoding:NSUTF8StringEncoding]; |
| 52 | + [coordinator processResponse:identityResponseData]; |
| 53 | + SFIdentityData *idData = coordinator.idData; |
| 54 | + |
| 55 | + |
| 56 | + // Basic identity fields |
| 57 | + XCTAssertEqualObjects(idData.idUrl, [NSURL URLWithString:@"https://login.salesforce.com/id/some-org-id/some-user-id"], @"idUrl should match"); |
| 58 | + XCTAssertTrue(idData.assertedUser, @"assertedUser should be true"); |
| 59 | + XCTAssertEqualObjects(idData.userId, @"some-user-id", @"userId should match"); |
| 60 | + XCTAssertEqualObjects(idData.orgId, @"some-org-id", @"orgId should match"); |
| 61 | + |
| 62 | + // User information |
| 63 | + XCTAssertEqualObjects(idData. username, @"[email protected]", @"username should match"); |
| 64 | + XCTAssertEqualObjects(idData.nickname, @"nickname", @"nickname should match"); |
| 65 | + XCTAssertEqualObjects(idData.displayName, @"Example User", @"displayName should match"); |
| 66 | + XCTAssertEqualObjects(idData. email, @"[email protected]", @"email should match"); |
| 67 | + XCTAssertEqualObjects(idData.firstName, @"Example", @"firstName should match"); |
| 68 | + XCTAssertEqualObjects(idData.lastName, @"User", @"lastName should match"); |
| 69 | + |
| 70 | + // Photos (NSURL* properties) |
| 71 | + XCTAssertEqualObjects(idData.pictureUrl, [NSURL URLWithString:@"https://example.com/profilephoto/full"], @"pictureUrl should match"); |
| 72 | + XCTAssertEqualObjects(idData.thumbnailUrl, [NSURL URLWithString:@"https://example.com/profilephoto/thumb"], @"thumbnailUrl should match"); |
| 73 | + |
| 74 | + // SOAP URLs |
| 75 | + XCTAssertEqualObjects(idData.enterpriseSoapUrl, @"https://example.my.salesforce.com/services/Soap/c/some-version/some-org-id", @"enterpriseSoapUrl should match"); |
| 76 | + XCTAssertEqualObjects(idData.metadataSoapUrl, @"https://example.my.salesforce.com/services/Soap/m/some-version/some-org-id", @"metadataSoapUrl should match"); |
| 77 | + XCTAssertEqualObjects(idData.partnerSoapUrl, @"https://example.my.salesforce.com/services/Soap/u/some-version/some-org-id", @"partnerSoapUrl should match"); |
| 78 | + |
| 79 | + // REST URLs |
| 80 | + XCTAssertEqualObjects(idData.restUrl, @"https://example.my.salesforce.com/services/data/vsome-version/", @"restUrl should match"); |
| 81 | + XCTAssertEqualObjects(idData.restSObjectsUrl, @"https://example.my.salesforce.com/services/data/vsome-version/sobjects/", @"restSObjectsUrl should match"); |
| 82 | + XCTAssertEqualObjects(idData.restSearchUrl, @"https://example.my.salesforce.com/services/data/vsome-version/search/", @"restSearchUrl should match"); |
| 83 | + XCTAssertEqualObjects(idData.restQueryUrl, @"https://example.my.salesforce.com/services/data/vsome-version/query/", @"restQueryUrl should match"); |
| 84 | + XCTAssertEqualObjects(idData.restRecentUrl, @"https://example.my.salesforce.com/services/data/vsome-version/recent/", @"restRecentUrl should match"); |
| 85 | + |
| 86 | + // Profile and Chatter URLs |
| 87 | + XCTAssertEqualObjects(idData.profileUrl, [NSURL URLWithString:@"https://example.my.salesforce.com/some-user-id"], @"profileUrl should match (NSURL)"); |
| 88 | + XCTAssertEqualObjects(idData.chatterFeedsUrl, @"https://example.my.salesforce.com/services/data/vsome-version/chatter/feeds", @"chatterFeedsUrl should match"); |
| 89 | + XCTAssertEqualObjects(idData.chatterGroupsUrl, @"https://example.my.salesforce.com/services/data/vsome-version/chatter/groups", @"chatterGroupsUrl should match"); |
| 90 | + XCTAssertEqualObjects(idData.chatterUsersUrl, @"https://example.my.salesforce.com/services/data/vsome-version/chatter/users", @"chatterUsersUrl should match"); |
| 91 | + XCTAssertEqualObjects(idData.chatterFeedItemsUrl, @"https://example.my.salesforce.com/services/data/vsome-version/chatter/feed-items", @"chatterFeedItemsUrl should match"); |
| 92 | + |
| 93 | + // User status and preferences |
| 94 | + XCTAssertTrue(idData.isActive, @"isActive should be true"); |
| 95 | + XCTAssertEqualObjects(idData.userType, @"STANDARD", @"userType should match"); |
| 96 | + XCTAssertEqualObjects(idData.language, @"en_US", @"language should match"); |
| 97 | + XCTAssertEqualObjects(idData.locale, @"en_US", @"locale should match"); |
| 98 | + XCTAssertEqual(idData.utcOffset, -28800000, @"utcOffset should match"); |
| 99 | + |
| 100 | + // Date parsing |
| 101 | + XCTAssertNotNil(idData.lastModifiedDate, @"lastModifiedDate should not be nil"); |
| 102 | + // Note: lastModifiedDate is parsed from "2024-12-23T18:40:50Z", exact value comparison would need date formatter |
164 | 103 | } |
165 | 104 |
|
166 | 105 | @end |
|
0 commit comments