Skip to content

Commit

Permalink
Merge branch 'dev' into antonioalwan/15_add_temp_tests_adj
Browse files Browse the repository at this point in the history
* dev:
  Merge Hotfix/1.7.44 (#1456) (#1459)
  dummy change to trigger pipeline
  Update API
  Increase waiting time
  wait inorder
  MSA Automation support
  • Loading branch information
antonioalwan committed Jan 2, 2025
2 parents 8616f50 + f75169d commit 207903d
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) MSIDProviderType providerType;
@property (nonatomic, nullable) NSString *oidcScope;
@property (nonatomic, nullable) NSDictionary *extraQueryParameters;
@property (nonatomic) BOOL allowAnyExtraURLQueryParameters;
@property (nonatomic) BOOL instanceAware;
@property (nonatomic, nullable) NSDictionary *enrollmentIds;
@property (nonatomic, nullable) NSDictionary *mamResources;
Expand All @@ -48,6 +49,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) NSString *clientSku;
@property (nonatomic) BOOL skipValidateResultAccount;
@property (nonatomic) BOOL forceRefresh;
@property (nonatomic) BOOL ignoreScopeValidation;


+ (BOOL)fillRequest:(MSIDBrokerOperationTokenRequest *)request
withParameters:(MSIDRequestParameters *)parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ + (BOOL)fillRequest:(MSIDBrokerOperationTokenRequest *)request
request.skipValidateResultAccount = parameters.skipValidateResultAccount;
request.forceRefresh = parameters.forceRefresh;
request.platformSequence = parameters.platformSequence;
request.allowAnyExtraURLQueryParameters = parameters.allowAnyExtraURLQueryParameters;
request.ignoreScopeValidation = parameters.ignoreScopeValidation;
return YES;
}

Expand Down Expand Up @@ -153,6 +155,7 @@ - (NSDictionary *)jsonDictionary
json[MSID_CLIENT_SKU_KEY] = self.clientSku;
json[MSID_SKIP_VALIDATE_RESULT_ACCOUNT_KEY] = [@(self.skipValidateResultAccount) stringValue];
json[MSID_FORCE_REFRESH_KEY] = [@(self.forceRefresh) stringValue];

return json;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ - (NSDictionary *)jsonDictionary
}

__auto_type accountJson = [NSMutableDictionary new];
accountJson[@"userName"] = tokenResponse.idTokenObj.username;
accountJson[@"userName"] = tokenResponse.accountUpn;
accountJson[@"id"] = tokenResponse.accountIdentifier;

response[@"account"] = accountJson;
response[@"state"] = self.state;

__auto_type propertiesJson = [NSMutableDictionary new];
// TODO: once ests follow the latest protocol, this should be removed. Account ID should be read from accountJson.
propertiesJson[@"UPN"] = tokenResponse.idTokenObj.username;
propertiesJson[@"UPN"] = accountJson[@"userName"];
response[@"properties"] = propertiesJson;

return response;
Expand Down
2 changes: 1 addition & 1 deletion IdentityCore/src/oauth2/MSIDOauth2Factory.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ - (BOOL)fillAccount:(MSIDAccount *)account
fromResponse:(MSIDTokenResponse *)response
configuration:(MSIDConfiguration *)configuration
{
NSString *homeAccountId = response.idTokenObj.userId;
NSString *homeAccountId = response.idTokenObj.userId ?: [response accountIdentifier];

if (!homeAccountId)
{
Expand Down
2 changes: 2 additions & 0 deletions IdentityCore/src/oauth2/MSIDTokenResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@

@property (nonatomic, readonly, nullable) NSString *accountIdentifier;

@property (nonatomic, readonly, nullable) NSString *accountUpn;

- (nullable instancetype)initWithJSONDictionary:(nonnull NSDictionary *)json
refreshToken:(nullable MSIDBaseToken<MSIDRefreshableToken> *)token
error:(NSError * _Nullable __autoreleasing *_Nullable)error;
Expand Down
5 changes: 5 additions & 0 deletions IdentityCore/src/oauth2/MSIDTokenResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ - (NSString *)accountIdentifier
return self.idTokenObj.uniqueId;
}

- (NSString *)accountUpn
{
return self.idTokenObj.username;
}

#pragma mark - Protected

- (MSIDIdTokenClaims *)tokenClaimsFromRawIdToken:(NSString *)rawIdToken error:(NSError *__autoreleasing*)error
Expand Down
1 change: 1 addition & 0 deletions IdentityCore/src/oauth2/aad_base/MSIDAADTokenResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@property (nonatomic, nullable) MSIDClientInfo *clientInfo;
@property (nonatomic, nullable) NSString *familyId;
@property (nonatomic, nullable) NSString *suberror;
/// UPN of the user.
@property (nonatomic, nullable) NSString *additionalUserId;

// Custom properties that ADAL/MSAL handles
Expand Down
5 changes: 5 additions & 0 deletions IdentityCore/src/oauth2/aad_base/MSIDAADTokenResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ - (NSString *)accountIdentifier
return self.clientInfo.accountIdentifier;
}

- (NSString *)accountUpn
{
return [super accountUpn] ?: self.additionalUserId;
}

#pragma mark - MSIDJsonSerializable

- (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__autoreleasing*)error
Expand Down
3 changes: 3 additions & 0 deletions IdentityCore/src/parameters/MSIDRequestParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@property (nonatomic) NSString *oidcScope;
@property (nonatomic) MSIDAccountIdentifier *accountIdentifier;
@property (nonatomic) BOOL validateAuthority;
@property (nonatomic) BOOL ignoreScopeValidation;
@property (nonatomic) NSString *nonce;
@property (nonatomic) NSString *clientSku;
@property (nonatomic) BOOL skipValidateResultAccount;
Expand All @@ -67,6 +68,8 @@
@property (nonatomic) NSDictionary *extraTokenRequestParameters;
// Additional URL query parameters that will be added to both token and authorize requests
@property (nonatomic) NSDictionary *extraURLQueryParameters;
// Currently used only in broker to enable/disable EQP filtering.
@property (nonatomic) BOOL allowAnyExtraURLQueryParameters;
@property (nonatomic) NSUInteger tokenExpirationBuffer;
@property (nonatomic) BOOL extendedLifetimeEnabled;
@property (nonatomic) BOOL instanceAware;
Expand Down
1 change: 1 addition & 0 deletions IdentityCore/src/requests/sdk/MSIDTokenResponseValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- (BOOL)validateTokenResult:(nonnull MSIDTokenResult *)tokenResult
configuration:(nonnull MSIDConfiguration *)configuration
oidcScope:(nullable NSString *)oidcScope
validateScopes:(BOOL)validateScopes
correlationID:(nonnull NSUUID *)correlationID
error:(NSError * _Nullable __autoreleasing * _Nullable)error;

Expand Down
3 changes: 3 additions & 0 deletions IdentityCore/src/requests/sdk/MSIDTokenResponseValidator.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ - (MSIDTokenResult *)createTokenResultFromResponse:(MSIDTokenResponse *)tokenRes
- (BOOL)validateTokenResult:(__unused MSIDTokenResult *)tokenResult
configuration:(__unused MSIDConfiguration *)configuration
oidcScope:(__unused NSString *)oidcScope
validateScopes:(__unused BOOL)validateScopes
correlationID:(__unused NSUUID *)correlationID
error:(__unused NSError *__autoreleasing*)error
{
Expand Down Expand Up @@ -224,6 +225,7 @@ - (MSIDTokenResult *)validateAndSaveBrokerResponse:(MSIDBrokerResponse *)brokerR
BOOL resultValid = [self validateTokenResult:tokenResult
configuration:configuration
oidcScope:oidcScope
validateScopes:YES
correlationID:correlationID
error:error];

Expand Down Expand Up @@ -289,6 +291,7 @@ - (MSIDTokenResult *)validateAndSaveTokenResponse:(MSIDTokenResponse *)tokenResp
BOOL resultValid = [self validateTokenResult:tokenResult
configuration:parameters.msidConfiguration
oidcScope:parameters.oidcScope
validateScopes:!parameters.ignoreScopeValidation
correlationID:parameters.correlationId
error:error];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @implementation MSIDLegacyTokenResponseValidator
- (BOOL)validateTokenResult:(MSIDTokenResult *)tokenResult
configuration:(__unused MSIDConfiguration *)configuration
oidcScope:(__unused NSString *)oidcScope
validateScopes:(__unused BOOL)validateScopes
correlationID:(NSUUID *)correlationID
error:(NSError *__autoreleasing*)error
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation MSIDDefaultTokenResponseValidator
- (BOOL)validateTokenResult:(MSIDTokenResult *)tokenResult
configuration:(MSIDConfiguration *)configuration
oidcScope:(NSString *)oidcScope
validateScopes:(BOOL)validateScopes
correlationID:(NSUUID *)correlationID
error:(NSError *__autoreleasing*)error
{
Expand All @@ -47,6 +48,8 @@ - (BOOL)validateTokenResult:(MSIDTokenResult *)tokenResult
{
return YES;
}

if (!validateScopes) return YES;

NSOrderedSet *grantedScopes = tokenResult.accessToken.scopes;
NSOrderedSet *normalizedGrantedScopes = grantedScopes.normalizedScopeSet;
Expand Down
4 changes: 4 additions & 0 deletions IdentityCore/tests/MSIDDefaultTokenResponseValidatorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ - (void)testValidateTokenResult_whenSomeScopesRejectedByServer_shouldReturnError
[self.validator validateTokenResult:result
configuration:configuration
oidcScope:defaultOidcScope
validateScopes:YES
correlationID:correlationID
error:&error];

Expand Down Expand Up @@ -131,6 +132,7 @@ - (void)testValidateTokenResult_whenEmailScopesNotIncludedByServer_shouldReturnV
BOOL validated = [self.validator validateTokenResult:result
configuration:configuration
oidcScope:defaultOidcScope
validateScopes:YES
correlationID:correlationID
error:&error];

Expand Down Expand Up @@ -171,6 +173,7 @@ - (void)testValidateTokenResult_whenEmailScopesIncludedByServer_shouldReturnVali
BOOL validated = [self.validator validateTokenResult:result
configuration:configuration
oidcScope:defaultOidcScope
validateScopes:YES
correlationID:correlationID
error:&error];

Expand Down Expand Up @@ -206,6 +209,7 @@ - (void)testValidateTokenResult_whenWithValidResponse_shouldReturnValidResult
BOOL validated = [self.validator validateTokenResult:result
configuration:configuration
oidcScope:defaultOidcScope
validateScopes:YES
correlationID:correlationID
error:&error];

Expand Down
1 change: 1 addition & 0 deletions IdentityCore/tests/MSIDLegacyTokenResponseValidatorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ - (void)testValidateTokenResult_whenResultContainsAccount_shouldReturnNoError
BOOL result = [self.validator validateTokenResult:testResult
configuration:[MSIDConfiguration new]
oidcScope:nil
validateScopes:YES
correlationID:[NSUUID new]
error:&error];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ typedef NS_ENUM(NSInteger, MSIDAutomationWPJSSOExtensionSecureStorage)
@property (nonatomic) BOOL corruptSessionKey;
@property (nonatomic) BOOL useSafariUserAgent;
@property (nonatomic) BOOL disableCertBasedAuth;
@property (nonatomic) BOOL isMSAAccount;

@property (nonatomic) MSIDAutomationWPJRegistrationAPIMode registrationMode;
@property (nonatomic) NSString *wpjRegistrationTenantId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json
_brokerEnabled = [json[@"brokerEnabled"] boolValue];
_clientCapabilities = json[@"client_capabilities"];
_refreshToken = json[@"refresh_token"];
_isMSAAccount = [json[@"isMSAAccount"] boolValue];

#if TARGET_OS_IPHONE
NSString *webviewTypeString = json[@"webviewtype"];
Expand Down Expand Up @@ -138,6 +139,7 @@ - (NSDictionary *)jsonDictionary
json[@"corrupt_session_key"] = @(_corruptSessionKey);
json[@"use_safari_ua"] = @(_useSafariUserAgent);
json[@"disable_cert_based_auth"] = @(_disableCertBasedAuth);
json[@"isMSAAccount"] = @(_isMSAAccount);

NSString *webviewType = nil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) NSString *homeObjectId;
@property (nonatomic) NSString *homeTenantId;
@property (nonatomic) NSString *environment;
@property (nonatomic) NSString *oneAuthAccountId;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ - (NSDictionary *)jsonDictionary
json[@"home_tenant_id"] = self.homeTenantId;
json[@"environment"] = self.environment;
json[@"legacyAccountId"] = self.legacyAccountId;
json[@"oneAuthAccountId"] = self.oneAuthAccountId;
return json;
}

Expand All @@ -59,6 +60,7 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(__unused NSEr
_homeTenantId = json[@"home_tenant_id"];
_environment = json[@"environment"];
_legacyAccountId = json[@"legacyAccountId"];
_oneAuthAccountId = json[@"oneAuthAccountId"];
}

return self;
Expand Down
41 changes: 28 additions & 13 deletions IdentityCore/tests/automation/ui_tests_lib/MSIDBaseUITest.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,29 @@ - (void)enterPassword:(NSString *)password app:(XCUIApplication *)application is
// Enter password
XCUIElement *passwordSecureTextField = [application.secureTextFields elementBoundByIndex:0];
// This is explicitly to check the new screen where to ask user to signin with the following 2 options. This caused several automation failures
// 1. Use my password
// 2. Sign in to an orgnization
XCUIElement *useMyPasswordButton = application.buttons[@"Use my password"];
XCUIElement *currentElement = [self waitForEitherElements:passwordSecureTextField and:useMyPasswordButton];
if (currentElement.elementType == XCUIElementTypeButton)

XCTWaiterResult result = [self waitForElementsAndContinueIfNotAppear:passwordSecureTextField];
if (result == XCTWaiterResultCompleted)
{
[currentElement tap];
[self enterPassword:password
app:application
isMainApp:isMainApp];
return;
[self tapElementAndWaitForKeyboardToAppear:passwordSecureTextField app:application];
NSString *passwordString = [NSString stringWithFormat:@"%@\n", password];
[self enterText:passwordSecureTextField isMainApp:isMainApp text:passwordString];
}
else
{
// 1. Use my password
// 2. Sign in to an orgnization
XCUIElement *useMyPasswordButton = application.buttons[@"Use my password"];
result = [self waitForElementsAndContinueIfNotAppear:useMyPasswordButton];
if (result == XCTWaiterResultCompleted)
{
[useMyPasswordButton tap];
[self enterPassword:password
app:application
isMainApp:isMainApp];
}
}

[self tapElementAndWaitForKeyboardToAppear:passwordSecureTextField app:application];
NSString *passwordString = [NSString stringWithFormat:@"%@\n", password];
[self enterText:passwordSecureTextField isMainApp:isMainApp text:passwordString];
}

- (void)adfsEnterPassword:(XCUIApplication *)application
Expand Down Expand Up @@ -487,6 +494,14 @@ - (XCUIElement *)waitForEitherElements:(XCUIElement *)object1 and:(XCUIElement *
return object1.exists ? object1 : object2;
}

- (XCTWaiterResult)waitForElementsAndContinueIfNotAppear:(XCUIElement *)object
{
NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:@"%@.exists == 1" argumentArray:@[object]];

XCTestExpectation *expectation = [[XCTNSPredicateExpectation alloc] initWithPredicate:existsPredicate object:object];
return [XCTWaiter waitForExpectations:@[expectation] timeout:30.0f enforceOrder:YES];
}

- (void)tapElementAndWaitForKeyboardToAppear:(XCUIElement *)element
{
[self tapElementAndWaitForKeyboardToAppear:element app:[XCUIApplication new]];
Expand Down
1 change: 1 addition & 0 deletions azure_pipelines/msal_submodule_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:
targetType: 'inline'
script: |
rm -rf $(Agent.BuildDirectory)/s/build/status.txt
- task: PublishTestResults@2
condition: always()
displayName: Publish Test Report
Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
Version TBD
* Make hashed ups in logs case insensitive (#1446)

Version 1.7.44
* Merge 1.7.42-hotfix

Version 1.7.43
* Support web_page_uri #1440
* Save error received from ESTS, and return it to the client on silent broker calls (#1438)
* XPC CommonCore Minor change to support broker XPC changes (#1436)
* Assign completion block before perform request (#1434)

Version 1.7.42-hotfix
* Add support of "lookup" mode in broker #1450
* Support web_page_uri #1440

Version 1.7.42
* Support extra query parameters on signout (#1243)
* Wrap ASAuthorizationProviderExtensionAuthorizationRequest methods (#1427)
Expand Down

0 comments on commit 207903d

Please sign in to comment.