Skip to content

Commit a032c70

Browse files
committed
2.2.1-2.2.3
1 parent d4784ec commit a032c70

File tree

1 file changed

+58
-37
lines changed

1 file changed

+58
-37
lines changed

MSAL/test/integration/native_auth/end_to_end/sign_in/MSALNativeAuthSignInUsernameEndToEndTests.swift

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,48 @@ import Foundation
2626
import XCTest
2727

2828
final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBaseTestCase {
29+
// Hero Scenario 2.2.1. Sign in - Use email and OTP to get token and sign in
30+
func test_signInAndSendingCorrectOTPResultsInSuccess() async throws {
31+
32+
guard let sut = initialisePublicClientApplication(clientIdType: .code), let username = retrieveUsernameForSignInCode() else {
33+
XCTFail("Missing information")
34+
return
35+
}
36+
37+
let signInExpectation = expectation(description: "signing in")
38+
let signInDelegateSpy = SignInStartDelegateSpy(expectation: signInExpectation)
39+
40+
sut.signIn(username: username, correlationId: correlationId, delegate: signInDelegateSpy)
41+
42+
await fulfillment(of: [signInExpectation])
43+
44+
guard signInDelegateSpy.onSignInCodeRequiredCalled else {
45+
XCTFail("onSignInCodeRequired not called")
46+
return
47+
}
48+
49+
XCTAssertNotNil(signInDelegateSpy.newStateCodeRequired)
50+
XCTAssertNotNil(signInDelegateSpy.sentTo)
51+
52+
// Now submit the code..
53+
54+
guard let code = await retrieveCodeFor(email: username) else {
55+
XCTFail("OTP code could not be retrieved")
56+
return
57+
}
58+
59+
let verifyCodeExpectation = expectation(description: "verifying code")
60+
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation)
61+
62+
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy)
63+
64+
await fulfillment(of: [verifyCodeExpectation])
65+
66+
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled)
67+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result)
68+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken)
69+
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username)
70+
}
2971

3072
// Hero Scenario 2.2.2. Sign in - User is not registered with given email
3173
func test_signInWithUnknownUsernameResultsInError() async throws {
@@ -46,9 +88,10 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
4688
XCTAssertTrue(signInDelegateSpy.onSignInErrorCalled)
4789
XCTAssertTrue(signInDelegateSpy.error!.isUserNotFound)
4890
}
49-
50-
// Hero Scenario 2.2.7. Sign in - Invalid OTP code
51-
func test_signInAndSendingIncorrectOTPResultsInError() async throws {
91+
92+
// User Case 2.2.3 Sign In - User email is registered with password method, which is not supported by client (aka redirect flow)
93+
func test_signInWithInsufficientChallengeInError() async throws {
94+
throw XCTSkip("Retrieving OTP failure")
5295

5396
guard let sut = initialisePublicClientApplication(clientIdType: .code), let username = retrieveUsernameForSignInCode() else {
5497
XCTFail("Missing information")
@@ -62,30 +105,15 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
62105

63106
await fulfillment(of: [signInExpectation])
64107

65-
guard signInDelegateSpy.onSignInCodeRequiredCalled else {
66-
XCTFail("OTP not sent")
67-
return
68-
}
69-
XCTAssertNotNil(signInDelegateSpy.newStateCodeRequired)
70-
XCTAssertNotNil(signInDelegateSpy.sentTo)
71-
72-
// Now submit the code..
73-
74-
let verifyCodeExpectation = expectation(description: "verifying code")
75-
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation)
76-
77-
signInDelegateSpy.newStateCodeRequired?.submitCode(code: "00000000", delegate: signInVerifyCodeDelegateSpy)
78-
79-
await fulfillment(of: [verifyCodeExpectation])
80-
81-
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInVerifyCodeErrorCalled)
82-
XCTAssertNotNil(signInVerifyCodeDelegateSpy.error)
83-
XCTAssertEqual(signInVerifyCodeDelegateSpy.error?.isInvalidCode, true)
108+
// Verify error condition
109+
XCTAssertTrue(signInDelegateSpy.onSignInErrorCalled)
110+
XCTAssertEqual(signInDelegateSpy.error?.isBrowserRequired, true)
84111
}
85112

86-
// Hero Scenario 2.2.1. Sign in - Use email and OTP to get token and sign in
87-
func test_signInAndSendingCorrectOTPResultsInSuccess() async throws {
88-
113+
// Hero Scenario 2.2.7. Sign in - Invalid OTP code
114+
func test_signInAndSendingIncorrectOTPResultsInError() async throws {
115+
throw XCTSkip("The test account is locked")
116+
89117
guard let sut = initialisePublicClientApplication(clientIdType: .code), let username = retrieveUsernameForSignInCode() else {
90118
XCTFail("Missing information")
91119
return
@@ -99,31 +127,24 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
99127
await fulfillment(of: [signInExpectation])
100128

101129
guard signInDelegateSpy.onSignInCodeRequiredCalled else {
102-
XCTFail("onSignInCodeRequired not called")
130+
XCTFail("OTP not sent")
103131
return
104132
}
105-
106133
XCTAssertNotNil(signInDelegateSpy.newStateCodeRequired)
107134
XCTAssertNotNil(signInDelegateSpy.sentTo)
108135

109136
// Now submit the code..
110137

111-
guard let code = await retrieveCodeFor(email: username) else {
112-
XCTFail("OTP code could not be retrieved")
113-
return
114-
}
115-
116138
let verifyCodeExpectation = expectation(description: "verifying code")
117139
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy(expectation: verifyCodeExpectation)
118140

119-
signInDelegateSpy.newStateCodeRequired?.submitCode(code: code, delegate: signInVerifyCodeDelegateSpy)
141+
signInDelegateSpy.newStateCodeRequired?.submitCode(code: "00000000", delegate: signInVerifyCodeDelegateSpy)
120142

121143
await fulfillment(of: [verifyCodeExpectation])
122144

123-
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInCompletedCalled)
124-
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result)
125-
XCTAssertNotNil(signInVerifyCodeDelegateSpy.result?.idToken)
126-
XCTAssertEqual(signInVerifyCodeDelegateSpy.result?.account.username, username)
145+
XCTAssertTrue(signInVerifyCodeDelegateSpy.onSignInVerifyCodeErrorCalled)
146+
XCTAssertNotNil(signInVerifyCodeDelegateSpy.error)
147+
XCTAssertEqual(signInVerifyCodeDelegateSpy.error?.isInvalidCode, true)
127148
}
128149

129150
// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com"

0 commit comments

Comments
 (0)