Skip to content

Commit

Permalink
Revert "Revert "Address comments""
Browse files Browse the repository at this point in the history
This reverts commit 4463c60.
  • Loading branch information
Yuki-YuXin committed Dec 18, 2024
1 parent 3812849 commit cefac96
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 43 deletions.
6 changes: 6 additions & 0 deletions MSAL/MSAL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
0D96DB3C27850F0F00DEAF87 /* MSALWipeCacheForAllAccountsConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D96DB2E27850E1300DEAF87 /* MSALWipeCacheForAllAccountsConfig.h */; settings = {ATTRIBUTES = (Public, ); }; };
0D96DB3D27850F1100DEAF87 /* MSALWipeCacheForAllAccountsConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D96DB2E27850E1300DEAF87 /* MSALWipeCacheForAllAccountsConfig.h */; settings = {ATTRIBUTES = (Public, ); }; };
0D96DB3E27850F1200DEAF87 /* MSALWipeCacheForAllAccountsConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D96DB2E27850E1300DEAF87 /* MSALWipeCacheForAllAccountsConfig.h */; settings = {ATTRIBUTES = (Public, ); }; };
12E2160B2D11D3920000F44C /* AuthorityURLFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E2160A2D11D3920000F44C /* AuthorityURLFormat.swift */; };
12E2160C2D11D3920000F44C /* AuthorityURLFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E2160A2D11D3920000F44C /* AuthorityURLFormat.swift */; };
1E04572324BD5A7D00444756 /* MSALCacheItemDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E04572024BD5A7D00444756 /* MSALCacheItemDetailViewController.m */; };
1E06CD6524D116F800E3D0E5 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D6A206371FC510B500755A51 /* Security.framework */; };
1E1A2E042256D12F001009ED /* MSALTestAppSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = D61A64B01E5AAC5C0086D120 /* MSALTestAppSettings.m */; };
Expand Down Expand Up @@ -1922,6 +1924,7 @@
04D32CCF1FD8AFF3000B123E /* MSALErrorConverterTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSALErrorConverterTests.m; sourceTree = "<group>"; };
0D96DB2E27850E1300DEAF87 /* MSALWipeCacheForAllAccountsConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSALWipeCacheForAllAccountsConfig.h; sourceTree = "<group>"; };
0D96DB3627850E3900DEAF87 /* MSALWipeCacheForAllAccountsConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSALWipeCacheForAllAccountsConfig.m; sourceTree = "<group>"; };
12E2160A2D11D3920000F44C /* AuthorityURLFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorityURLFormat.swift; sourceTree = "<group>"; };
1E04571F24BD5A7D00444756 /* MSALCacheItemDetailViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSALCacheItemDetailViewController.h; sourceTree = "<group>"; };
1E04572024BD5A7D00444756 /* MSALCacheItemDetailViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSALCacheItemDetailViewController.m; sourceTree = "<group>"; };
1E1A2E052256D194001009ED /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -3425,6 +3428,7 @@
9B235D9E2A3CFB4300657331 /* MSALNativeAuthEndToEndBaseTestCase.swift */,
2809E8342C3C37B7009F14D7 /* MSALNativeAuthEndToEndPasswordTestCase.swift */,
280095EA2C32CAFC00F1653E /* ClientIdType.swift */,
12E2160A2D11D3920000F44C /* AuthorityURLFormat.swift */,
);
path = end_to_end;
sourceTree = "<group>";
Expand Down Expand Up @@ -6367,6 +6371,7 @@
281A0E182C21E1FD00CB30CB /* SignInDelegateSpies.swift in Sources */,
28A277D92C22ED5E00D95E00 /* MSALNativeAuthEmailCodeRetriever.swift in Sources */,
E24CE9CC2C57F1160069E2E4 /* AttributesStub.swift in Sources */,
12E2160B2D11D3920000F44C /* AuthorityURLFormat.swift in Sources */,
281A0E1B2C21E20600CB30CB /* MSALNativeAuthEndToEndBaseTestCase.swift in Sources */,
28188F652C8F4C1100CFDD05 /* MFADelegateSpies.swift in Sources */,
281A0E192C21E20000CB30CB /* MSALNativeAuthResetPasswordEndToEndTests.swift in Sources */,
Expand Down Expand Up @@ -7418,6 +7423,7 @@
DE1BD1062C3C284900B0888E /* SignInDelegateSpies.swift in Sources */,
DE1BD1072C3C284C00B0888E /* MSALNativeAuthResetPasswordEndToEndTests.swift in Sources */,
DE9EB8622C5CE44B00328AA4 /* AttributesStub.swift in Sources */,
12E2160C2D11D3920000F44C /* AuthorityURLFormat.swift in Sources */,
DE1BD1012C3C283C00B0888E /* MSALNativeAuthSignUpUsernameEndToEndTests.swift in Sources */,
28188F662C8F4C1100CFDD05 /* MFADelegateSpies.swift in Sources */,
DE1BD1032C3C284100B0888E /* SignUpDelegateSpies.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


import Foundation

enum AuthorityURLFormat {
case tenantSubdomainShortVersion
case tenantSubdomainLongVersion
case tenantSubdomainTenantId
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
static let signInEmailPasswordMFAUsernameKey = "sign_in_email_password_mfa_username"
static let signInEmailPasswordMFANoDefaultAuthMethodUsernameKey = "sign_in_email_password_mfa_no_default_username"
static let signInEmailCodeUsernameKey = "sign_in_email_code_username"
static let customDomainFormat = [
"https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com",
"https://<tenantName>.ciamlogin.com/<tenantId>",
"https://<tenantName>.ciamlogin.com/",
]
#if !os(macOS)
static let resetPasswordUsernameKey = "reset_password_username"
#else
Expand Down Expand Up @@ -78,7 +73,7 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
func initialisePublicClientApplication(
clientIdType: ClientIdType = .password,
challengeTypes: MSALNativeAuthChallengeTypes = [.OOB, .password],
customSubdomainFormat: Int? = nil
customAuthorityURLFormat: AuthorityURLFormat? = nil
) -> MSALNativeAuthPublicClientApplication? {
let clientIdKey = getClientIdKey(type: clientIdType)
guard let clientId = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[clientIdKey] as? String else {
Expand All @@ -87,7 +82,7 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
}

guard let tenantSubdomain = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[Constants.tenantSubdomainKey] as? String else {
XCTFail("TenantName not found in conf.json")
XCTFail("TenantSubdomain not found in conf.json")
return nil
}

Expand All @@ -97,15 +92,15 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
}


if customSubdomainFormat != nil {
if let customAuthorityURLFormat = customAuthorityURLFormat {
let customSubdomain = getCustomTenantSubdomain(
tenantName: tenantSubdomain,
tenantId: tenantId,
format: customSubdomainFormat!
format: customAuthorityURLFormat
)

let authority = try? MSALCIAMAuthority(
url: URL(string: customSubdomain)!,
let authority = try? MSALCIAMAuthority(
url: URL(string: customSubdomain)!,
validateFormat: false
)

Expand All @@ -120,7 +115,11 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
challengeTypes: challengeTypes
)
} else {
return try? MSALNativeAuthPublicClientApplication(clientId: clientId, tenantSubdomain: tenantSubdomain, challengeTypes: challengeTypes)
return try? MSALNativeAuthPublicClientApplication(
clientId: clientId,
tenantSubdomain: tenantSubdomain,
challengeTypes: challengeTypes
)
}
}

Expand Down Expand Up @@ -173,9 +172,14 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
}
}

private func getCustomTenantSubdomain(tenantName: String?, tenantId: String?, format: Int) -> String {
return Constants.customDomainFormat[format]
.replacingOccurrences(of: "<tenantName>", with: tenantName!)
.replacingOccurrences(of: "<tenantId>", with: tenantId!)
private func getCustomTenantSubdomain(tenantName: String, tenantId: String, format: AuthorityURLFormat) -> String {
switch format {
case .tenantSubdomainShortVersion:
return String(format: "https://%@.ciamlogin.com/", tenantName)
case .tenantSubdomainLongVersion:
return String(format: "https://%@.ciamlogin.com/%@.onmicrosoft.com", tenantName, tenantName)
case .tenantSubdomainTenantId:
return String(format: "https://%@.ciamlogin.com/%@", tenantName, tenantId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth

// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com"
func test_signInCustomDomain1InSuccess() async throws {
guard let sut = initialisePublicClientApplication(customSubdomainFormat: 0) else {
guard let sut = initialisePublicClientApplication(customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainLongVersion) else {
XCTFail("Failed to initialise auth client")
return
}
Expand All @@ -131,20 +131,18 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
let signInExpectation = expectation(description: "Signing in")
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)

// Perform the sign-in asynchronously
Task {
await sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
await fulfillment(of: [signInExpectation])
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)

await fulfillment(of: [signInExpectation])

XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
}
XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
}

// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantId>"
func test_signInCustomDomain2InSuccess() async throws {
guard let sut = initialisePublicClientApplication(customSubdomainFormat: 1) else {
guard let sut = initialisePublicClientApplication(customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainTenantId) else {
XCTFail("Failed to initialise auth client")
return
}
Expand All @@ -157,20 +155,19 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
let signInExpectation = expectation(description: "Signing in")
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)

// Perform the sign-in asynchronously
Task {
await sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
await fulfillment(of: [signInExpectation])

XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
}
sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)

await fulfillment(of: [signInExpectation])

XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
}

// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/"
func test_signInCustomDomain3InSuccess() async throws {
guard let sut = initialisePublicClientApplication(customSubdomainFormat: 2) else {
guard let sut = initialisePublicClientApplication(customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainShortVersion) else {
XCTFail("Failed to initialise auth client")
return
}
Expand All @@ -183,14 +180,13 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
let signInExpectation = expectation(description: "Signing in")
let signInDelegateSpy = SignInPasswordStartDelegateSpy(expectation: signInExpectation)

// Perform the sign-in asynchronously
Task {
await sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
await fulfillment(of: [signInExpectation])

sut.signIn(username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)

XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
}
await fulfillment(of: [signInExpectation])

XCTAssertTrue(signInDelegateSpy.onSignInCompletedCalled)
XCTAssertNotNil(signInDelegateSpy.result?.idToken)
XCTAssertEqual(signInDelegateSpy.result?.account.username, username)
}
}

0 comments on commit cefac96

Please sign in to comment.