-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOS Sign Up E2E Test #2422
IOS Sign Up E2E Test #2422
Changes from 35 commits
2565b80
3247d2a
fd3a63a
a469024
9974b64
578c479
24e6838
2bf3f9e
e90dadc
94b550b
db431c4
9cd2c77
b197a17
95bfcaf
b7e826d
dc67b95
91e59f0
c2ff7f7
273af9b
e163297
4ab385a
08ba0c8
61569bb
faa59c5
886d1fe
6a82162
f4b68df
d1ce495
cc3864d
14531e1
4463c60
9b56bc2
3812849
cefac96
99d3b11
7fe3bc8
1422d14
d239b4c
4f65bff
1c93d83
96c3908
08ef259
6704e4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,7 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase { | |||||
static let clientIdEmailPasswordAttributesKey = "email_password_attributes_client_id" | ||||||
static let clientIdEmailCodeAttributesKey = "email_code_attributes_client_id" | ||||||
static let tenantSubdomainKey = "tenant_subdomain" | ||||||
static let tenantIdKey = "tenant_id" | ||||||
static let signInEmailPasswordUsernameKey = "sign_in_email_password_username" | ||||||
static let signInEmailPasswordMFAUsernameKey = "sign_in_email_password_mfa_username" | ||||||
static let signInEmailPasswordMFANoDefaultAuthMethodUsernameKey = "sign_in_email_password_mfa_no_default_username" | ||||||
|
@@ -71,14 +72,55 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase { | |||||
|
||||||
func initialisePublicClientApplication( | ||||||
clientIdType: ClientIdType = .password, | ||||||
challengeTypes: MSALNativeAuthChallengeTypes = [.OOB, .password] | ||||||
challengeTypes: MSALNativeAuthChallengeTypes = [.OOB, .password], | ||||||
customAuthorityURLFormat: AuthorityURLFormat? = nil | ||||||
) -> MSALNativeAuthPublicClientApplication? { | ||||||
let clientIdKey = getClientIdKey(type: clientIdType) | ||||||
guard let clientId = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[clientIdKey] as? String, let tenantSubdomain = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[Constants.tenantSubdomainKey] as? String else { | ||||||
XCTFail("ClientId or tenantSubdomain not found in conf.json") | ||||||
guard let clientId = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[clientIdKey] as? String else { | ||||||
XCTFail("ClientId not found in conf.json") | ||||||
return nil | ||||||
} | ||||||
return try? MSALNativeAuthPublicClientApplication(clientId: clientId, tenantSubdomain: tenantSubdomain, challengeTypes: challengeTypes) | ||||||
|
||||||
guard let tenantSubdomain = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[Constants.tenantSubdomainKey] as? String else { | ||||||
XCTFail("TenantSubdomain not found in conf.json") | ||||||
return nil | ||||||
} | ||||||
|
||||||
guard let tenantId = MSALNativeAuthEndToEndBaseTestCase.nativeAuthConfFileContent?[Constants.tenantIdKey] as? String else { | ||||||
XCTFail("TenantId not found in conf.json") | ||||||
return nil | ||||||
} | ||||||
|
||||||
|
||||||
if let customAuthorityURLFormat = customAuthorityURLFormat { | ||||||
let customSubdomain = getCustomTenantSubdomain( | ||||||
tenantName: tenantSubdomain, | ||||||
tenantId: tenantId, | ||||||
format: customAuthorityURLFormat | ||||||
) | ||||||
|
||||||
let authority = try? MSALCIAMAuthority( | ||||||
url: URL(string: customSubdomain)!, | ||||||
validateFormat: false | ||||||
) | ||||||
|
||||||
let configuration = MSALPublicClientApplicationConfig( | ||||||
clientId: clientId, | ||||||
redirectUri: nil, | ||||||
authority: authority | ||||||
) | ||||||
|
||||||
return try? MSALNativeAuthPublicClientApplication( | ||||||
configuration: configuration, | ||||||
challengeTypes: challengeTypes | ||||||
) | ||||||
} else { | ||||||
return try? MSALNativeAuthPublicClientApplication( | ||||||
clientId: clientId, | ||||||
tenantSubdomain: tenantSubdomain, | ||||||
challengeTypes: challengeTypes | ||||||
) | ||||||
} | ||||||
} | ||||||
|
||||||
func generateSignUpRandomEmail() -> String { | ||||||
|
@@ -129,4 +171,15 @@ class MSALNativeAuthEndToEndBaseTestCase: XCTestCase { | |||||
return Constants.clientIdEmailCodeAttributesKey | ||||||
} | ||||||
} | ||||||
|
||||||
private func getCustomTenantSubdomain(tenantName: String, tenantId: String, format: AuthorityURLFormat) -> String { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please call this method
Suggested change
And could you please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
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 | ||||
---|---|---|---|---|---|---|
|
@@ -125,4 +125,130 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas | |||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken) | ||||||
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username) | ||||||
} | ||||||
|
||||||
// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com" | ||||||
func test_signInCustomDomain1InSuccess() async throws { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please include the name of the authority URL format in use instead of a number? Same comment applies for other tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
guard let sut = initialisePublicClientApplication(clientIdType: .code, customAuthorityURLFormat: AuthorityURLFormat.tenantSubdomainLongVersion), let username = retrieveUsernameForSignInCode() else { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you can avoid specifying the Enum name here :)
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
XCTFail("Missing information") | ||||||
return | ||||||
} | ||||||
|
||||||
let signInExpectation = expectation(description: "signing in") | ||||||
let signInDelegateSpy = SignInStartDelegateSpy(expectation: signInExpectation) | ||||||
|
||||||
sut.signIn(username: username, correlationId: correlationId, delegate: signInDelegateSpy) | ||||||
|
||||||
await fulfillment(of: [signInExpectation]) | ||||||
|
||||||
guard signInDelegateSpy.onSignInCodeRequiredCalled else { | ||||||
XCTFail("onSignInCodeRequired not called") | ||||||
return | ||||||
} | ||||||
|
||||||
XCTAssertNotNil(signInDelegateSpy.newStateCodeRequired) | ||||||
XCTAssertNotNil(signInDelegateSpy.sentTo) | ||||||
|
||||||
// Now submit the code.. | ||||||
|
||||||
guard let code = await retrieveCodeFor(email: username) else { | ||||||
XCTFail("OTP code could not be retrieved") | ||||||
return | ||||||
} | ||||||
|
||||||
let verifyCodeExpectation = expectation(description: "verifying code") | ||||||
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation) | ||||||
|
||||||
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy) | ||||||
|
||||||
await fulfillment(of: [verifyCodeExpectation]) | ||||||
|
||||||
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled) | ||||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result) | ||||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken) | ||||||
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username) | ||||||
} | ||||||
|
||||||
// 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 { | ||||||
XCTFail("Missing information") | ||||||
return | ||||||
} | ||||||
|
||||||
let signInExpectation = expectation(description: "signing in") | ||||||
let signInDelegateSpy = SignInStartDelegateSpy(expectation: signInExpectation) | ||||||
|
||||||
sut.signIn(username: username, correlationId: correlationId, delegate: signInDelegateSpy) | ||||||
|
||||||
await fulfillment(of: [signInExpectation]) | ||||||
|
||||||
guard signInDelegateSpy.onSignInCodeRequiredCalled else { | ||||||
XCTFail("onSignInCodeRequired not called") | ||||||
return | ||||||
} | ||||||
|
||||||
XCTAssertNotNil(signInDelegateSpy.newStateCodeRequired) | ||||||
XCTAssertNotNil(signInDelegateSpy.sentTo) | ||||||
|
||||||
// Now submit the code.. | ||||||
|
||||||
guard let code = await retrieveCodeFor(email: username) else { | ||||||
XCTFail("OTP code could not be retrieved") | ||||||
return | ||||||
} | ||||||
|
||||||
let verifyCodeExpectation = expectation(description: "verifying code") | ||||||
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation) | ||||||
|
||||||
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy) | ||||||
|
||||||
await fulfillment(of: [verifyCodeExpectation]) | ||||||
|
||||||
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled) | ||||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result) | ||||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken) | ||||||
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username) | ||||||
} | ||||||
|
||||||
// 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 { | ||||||
XCTFail("Missing information") | ||||||
return | ||||||
} | ||||||
|
||||||
let signInExpectation = expectation(description: "signing in") | ||||||
let signInDelegateSpy = SignInStartDelegateSpy(expectation: signInExpectation) | ||||||
|
||||||
sut.signIn(username: username, correlationId: correlationId, delegate: signInDelegateSpy) | ||||||
|
||||||
await fulfillment(of: [signInExpectation]) | ||||||
|
||||||
guard signInDelegateSpy.onSignInCodeRequiredCalled else { | ||||||
XCTFail("onSignInCodeRequired not called") | ||||||
return | ||||||
} | ||||||
|
||||||
XCTAssertNotNil(signInDelegateSpy.newStateCodeRequired) | ||||||
XCTAssertNotNil(signInDelegateSpy.sentTo) | ||||||
|
||||||
// Now submit the code.. | ||||||
|
||||||
guard let code = await retrieveCodeFor(email: username) else { | ||||||
XCTFail("OTP code could not be retrieved") | ||||||
return | ||||||
} | ||||||
|
||||||
let verifyCodeExpectation = expectation(description: "verifying code") | ||||||
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation) | ||||||
|
||||||
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy) | ||||||
|
||||||
await fulfillment(of: [verifyCodeExpectation]) | ||||||
|
||||||
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled) | ||||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result) | ||||||
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken) | ||||||
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username) | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request does not update CHANGELOG.md.
Please consider if this change would be noticeable to a partner or user and either update CHANGELOG.md or resolve this conversation.