|
34 | 34 | @interface MSIDTokenResponseMock : MSIDTokenResponse |
35 | 35 |
|
36 | 36 | @property (nonatomic) NSDictionary *responseJson; |
| 37 | +@property (nonatomic) BOOL returnNilAccounUpn; |
37 | 38 |
|
38 | 39 | @end |
39 | 40 |
|
40 | 41 | @implementation MSIDTokenResponseMock |
41 | 42 |
|
| 43 | +- (NSString *)accountUpn |
| 44 | +{ |
| 45 | + if (self.returnNilAccounUpn) return nil; |
| 46 | + |
| 47 | + return [super accountUpn]; |
| 48 | +} |
| 49 | + |
42 | 50 | - (NSDictionary *)jsonDictionary |
43 | 51 | { |
44 | 52 | return self.responseJson; |
@@ -98,4 +106,38 @@ - (void)testJsonDictionary_whenPayloadExist_shouldBeCorrect |
98 | 106 | XCTAssertEqualObjects(expectedJson, [response jsonDictionary]); |
99 | 107 | } |
100 | 108 |
|
| 109 | +- (void)testJsonDictionary_whenNoUpnInReponse_shouldUseProvidedUpn |
| 110 | +{ |
| 111 | + NSString *idToken = [MSIDTestIdTokenUtil idTokenWithPreferredUsername:DEFAULT_TEST_ID_TOKEN_USERNAME |
| 112 | + subject:DEFAULT_TEST_ID_TOKEN_SUBJECT]; |
| 113 | + |
| 114 | + NSDictionary *jsonInput = @{@"id_token": idToken}; |
| 115 | + |
| 116 | + MSIDTokenResponseMock *tokenResponseMock = [[MSIDTokenResponseMock alloc] initWithJSONDictionary:jsonInput error:nil]; |
| 117 | + tokenResponseMock.returnNilAccounUpn = YES; |
| 118 | + tokenResponseMock.responseJson = @{@"some_key": @"some_value"}; |
| 119 | + |
| 120 | + __auto_type operationTokenResponse = [[MSIDBrokerOperationTokenResponse alloc] initWithDeviceInfo:nil]; |
| 121 | + operationTokenResponse.tokenResponse = tokenResponseMock; |
| 122 | + |
| 123 | + __auto_type response = [[MSIDBrowserNativeMessageGetTokenResponse alloc] initWithTokenResponse:operationTokenResponse]; |
| 124 | + response.state = @"1234"; |
| 125 | + response. accountUpn = @"[email protected]"; |
| 126 | + |
| 127 | + __auto_type expectedJson = @{ |
| 128 | + @"account": @{ |
| 129 | + @"id": tokenResponseMock.accountIdentifier, |
| 130 | + |
| 131 | + }, |
| 132 | + @"properties": @{ |
| 133 | + |
| 134 | + }, |
| 135 | + @"state": @"1234", |
| 136 | + @"some_key": @"some_value" |
| 137 | + }; |
| 138 | + |
| 139 | + XCTAssertNotNil([response jsonDictionary]); |
| 140 | + XCTAssertEqualObjects(expectedJson, [response jsonDictionary]); |
| 141 | +} |
| 142 | + |
101 | 143 | @end |
0 commit comments