Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki-YuXin committed Dec 19, 2024
1 parent 99d3b11 commit 7fe3bc8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase {
}
}

private func getCustomTenantSubdomain(tenantName: String, tenantId: String, format: AuthorityURLFormat) -> String {
private func getAuthorityURLString(tenantSubdomain: String, tenantId: String, format: AuthorityURLFormat) -> String {
switch format {
case .tenantSubdomainShortVersion:
return String(format: "https://%@.ciamlogin.com/", tenantName)
return String(format: "https://%@.ciamlogin.com/", tenantSubdomain)
case .tenantSubdomainLongVersion:
return String(format: "https://%@.ciamlogin.com/%@.onmicrosoft.com", tenantName, tenantName)
return String(format: "https://%@.ciamlogin.com/%@.onmicrosoft.com", tenantSubdomain, tenantSubdomain)
case .tenantSubdomainTenantId:
return String(format: "https://%@.ciamlogin.com/%@", tenantName, tenantId)
return String(format: "https://%@.ciamlogin.com/%@", tenantSubdomain, tenantId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
}

// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com"
func test_signInCustomDomain1InSuccess() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainLongVersion), let username = retrieveUsernameForSignInCode() else {
func test_signInCustomSubdomainLongInSuccess() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: .tenantSubdomainLongVersion), let username = retrieveUsernameForSignInCode() else {
XCTFail("Missing information")
return
}
Expand Down Expand Up @@ -169,8 +169,8 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
}

// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantId>"
func test_signInCustomDomain2InSuccess() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainTenantId), let username = retrieveUsernameForSignInCode() else {
func test_signInCustomSubdomainIdInSuccess() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: .tenantSubdomainTenantId), let username = retrieveUsernameForSignInCode() else {
XCTFail("Missing information")
return
}
Expand Down Expand Up @@ -211,8 +211,8 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
}

// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/"
func test_signInCustomDomain3InSuccess() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainShortVersion), let username = retrieveUsernameForSignInCode() else {
func test_signInCustomSubdomainShortInSuccess() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: .tenantSubdomainShortVersion), let username = retrieveUsernameForSignInCode() else {
XCTFail("Missing information")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ final class MSALNativeAuthSignUpUsernameAndPasswordEndToEndTests: MSALNativeAuth

// Verify error condition
XCTAssertTrue(signUpStartDelegate.onSignUpPasswordErrorCalled)
XCTAssertEqual(signUpStartDelegate.error!.isInvalidUsername, true)
XCTAssertEqual(signUpStartDelegate.error?.isInvalidUsername, true)
}

// Use case 1.1.12. Sign up - with Email & Password, Developer makes a request with invalid format email address
Expand All @@ -662,7 +662,7 @@ final class MSALNativeAuthSignUpUsernameAndPasswordEndToEndTests: MSALNativeAuth

// Verify error condition
XCTAssertTrue(signUpStartDelegate.onSignUpPasswordErrorCalled)
XCTAssertEqual(signUpStartDelegate.error!.isInvalidUsername, true)
XCTAssertEqual(signUpStartDelegate.error?.isInvalidUsername, true)
}

// Use case 1.1.13. Sign up - with Email & Password, Developer makes a request with password that does not match password complexity requirements set on portal
Expand All @@ -689,7 +689,7 @@ final class MSALNativeAuthSignUpUsernameAndPasswordEndToEndTests: MSALNativeAuth

// Verify error condition
XCTAssertTrue(signUpStartDelegate.onSignUpPasswordErrorCalled)
XCTAssertEqual(signUpStartDelegate.error!.isInvalidPassword, true)
XCTAssertEqual(signUpStartDelegate.error?.isInvalidPassword, true)
}

private func checkSignUpStartDelegate(_ delegate: SignUpPasswordStartDelegateSpy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas

// Verify error condition
XCTAssertTrue(signUpStartDelegate.onSignUpErrorCalled)
XCTAssertEqual(signUpStartDelegate.error!.isUserAlreadyExists, true)
XCTAssertEqual(signUpStartDelegate.error?.isUserAlreadyExists, true)
}

// Use case 2.1.7. Sign up - with Email & Password, User already exists with given email as social account
Expand Down Expand Up @@ -336,7 +336,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas

// Verify error condition
XCTAssertTrue(signUpStartDelegate.onSignUpPasswordErrorCalled)
XCTAssertEqual(signUpStartDelegate.error!.isInvalidUsername, true)
XCTAssertEqual(signUpStartDelegate.error?.isInvalidUsername, true)
}

// Use case 2.1.8. Sign up - with Email & OTP, Developer makes a request with invalid format email address
Expand All @@ -361,7 +361,7 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas

// Verify error condition
XCTAssertTrue(signUpStartDelegate.onSignUpPasswordErrorCalled)
XCTAssertEqual(signUpStartDelegate.error!.isInvalidUsername, true)
XCTAssertEqual(signUpStartDelegate.error?.isInvalidUsername, true)
}

// Hero Scenario 2.1.9. Sign up – without automatic sign in (Email & Email OTP)
Expand Down Expand Up @@ -426,70 +426,6 @@ final class MSALNativeAuthSignUpUsernameEndToEndTests: MSALNativeAuthEndToEndBas

// Hero Scenario 2.1.11. Sign up – Server requires password authentication, which is supported by the developer
// The same as 1.1.4
func test_signUpWithCode_withPasswordConfiguration_succeeds() async throws {
guard let sut = initialisePublicClientApplication(clientIdType: .password) else {
XCTFail("Missing information")
return
}
let codeRequiredExp = expectation(description: "code required")
let signUpStartDelegate = SignUpStartDelegateSpy(expectation: codeRequiredExp)
let username = generateSignUpRandomEmail()
let password = generateRandomPassword()

sut.signUp(username: username, correlationId: correlationId, delegate: signUpStartDelegate)

await fulfillment(of: [codeRequiredExp])
guard signUpStartDelegate.onSignUpCodeRequiredCalled else {
XCTFail("OTP not sent")
return
}
checkSignUpStartDelegate(signUpStartDelegate)

// Now submit the code...

guard let code = await retrieveCodeFor(email: username) else {
XCTFail("OTP code could not be retrieved")
return
}

let submitCodeExp = expectation(description: "submit code, credential required")
let signUpVerifyCodeDelegate = SignUpVerifyCodeDelegateSpy(expectation: submitCodeExp)

signUpStartDelegate.newState?.submitCode(code: code, delegate: signUpVerifyCodeDelegate)

await fulfillment(of: [submitCodeExp])

guard signUpVerifyCodeDelegate.onSignUpPasswordRequiredCalled else {
XCTFail("onSignUpPasswordRequired not called")
return
}

// Now submit the password...

let passwordRequiredExp = expectation(description: "password required")
let signUpPasswordDelegate = SignUpPasswordRequiredDelegateSpy(expectation: passwordRequiredExp)

signUpVerifyCodeDelegate.passwordRequiredState?.submitPassword(
password: password,
delegate: signUpPasswordDelegate
)

await fulfillment(of: [passwordRequiredExp])

guard signUpPasswordDelegate.onSignUpCompletedCalled else {
XCTFail("onSignUpCompleted not called")
return
}

// Now sign in...
let signInExp = expectation(description: "sign-in after sign-up")
let signInAfterSignUpDelegate = SignInAfterSignUpDelegateSpy(expectation: signInExp)

signUpPasswordDelegate.signInAfterSignUpState?.signIn(delegate: signInAfterSignUpDelegate)

await fulfillment(of: [signInExp])
checkSignInAfterSignUpDelegate(signInAfterSignUpDelegate, username: username)
}

private func checkSignUpStartDelegate(_ delegate: SignUpStartDelegateSpy) {
XCTAssertEqual(delegate.channelTargetType?.isEmailType, true)
Expand Down

0 comments on commit 7fe3bc8

Please sign in to comment.