@@ -26,6 +26,48 @@ import Foundation
26
26
import XCTest
27
27
28
28
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
+ }
29
71
30
72
// Hero Scenario 2.2.2. Sign in - User is not registered with given email
31
73
func test_signInWithUnknownUsernameResultsInError( ) async throws {
@@ -46,9 +88,10 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
46
88
XCTAssertTrue ( signInDelegateSpy. onSignInErrorCalled)
47
89
XCTAssertTrue ( signInDelegateSpy. error!. isUserNotFound)
48
90
}
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 " )
52
95
53
96
guard let sut = initialisePublicClientApplication ( clientIdType: . code) , let username = retrieveUsernameForSignInCode ( ) else {
54
97
XCTFail ( " Missing information " )
@@ -62,30 +105,15 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
62
105
63
106
await fulfillment ( of: [ signInExpectation] )
64
107
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 )
84
111
}
85
112
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
+
89
117
guard let sut = initialisePublicClientApplication ( clientIdType: . code) , let username = retrieveUsernameForSignInCode ( ) else {
90
118
XCTFail ( " Missing information " )
91
119
return
@@ -99,31 +127,24 @@ final class MSALNativeAuthSignInUsernameEndToEndTests: MSALNativeAuthEndToEndBas
99
127
await fulfillment ( of: [ signInExpectation] )
100
128
101
129
guard signInDelegateSpy. onSignInCodeRequiredCalled else {
102
- XCTFail ( " onSignInCodeRequired not called " )
130
+ XCTFail ( " OTP not sent " )
103
131
return
104
132
}
105
-
106
133
XCTAssertNotNil ( signInDelegateSpy. newStateCodeRequired)
107
134
XCTAssertNotNil ( signInDelegateSpy. sentTo)
108
135
109
136
// Now submit the code..
110
137
111
- guard let code = await retrieveCodeFor ( email: username) else {
112
- XCTFail ( " OTP code could not be retrieved " )
113
- return
114
- }
115
-
116
138
let verifyCodeExpectation = expectation ( description: " verifying code " )
117
139
let signInVerifyCodeDelegateSpy = SignInVerifyCodeDelegateSpy ( expectation: verifyCodeExpectation)
118
140
119
- signInDelegateSpy. newStateCodeRequired? . submitCode ( code: code , delegate: signInVerifyCodeDelegateSpy)
141
+ signInDelegateSpy. newStateCodeRequired? . submitCode ( code: " 00000000 " , delegate: signInVerifyCodeDelegateSpy)
120
142
121
143
await fulfillment ( of: [ verifyCodeExpectation] )
122
144
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 )
127
148
}
128
149
129
150
// Sign In - Verify Custom URL Domain - "https://<tenantName>.ciamlogin.com/<tenantName>.onmicrosoft.com"
0 commit comments