@@ -85,6 +85,92 @@ final class MSALNativeAuthSignInUsernameAndPasswordEndToEndTests: MSALNativeAuth
85
85
XCTAssertTrue ( signInDelegateSpy. error!. isInvalidCredentials)
86
86
}
87
87
88
+ // User Case 1.2.4. Sign In - User signs in with account A, while data for account A already exists in SDK persistence
89
+ func test_signInWithAccountSigned( ) async throws {
90
+ guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInUsernameAndPassword ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
91
+ XCTFail ( " Missing information " )
92
+ return
93
+ }
94
+
95
+ let signInExpectation = expectation ( description: " signing in " )
96
+ let signInDelegateSpy = SignInPasswordStartDelegateSpy ( expectation: signInExpectation)
97
+
98
+ sut. signIn ( username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
99
+
100
+ await fulfillment ( of: [ signInExpectation] )
101
+
102
+ XCTAssertTrue ( signInDelegateSpy. onSignInCompletedCalled)
103
+ XCTAssertNotNil ( signInDelegateSpy. result? . idToken)
104
+ XCTAssertEqual ( signInDelegateSpy. result? . account. username, username)
105
+
106
+ // Now signed in the account again
107
+ let signInExpectation2 = expectation ( description: " signing in " )
108
+ let signInDelegateSpy2 = SignInPasswordStartDelegateSpy ( expectation: signInExpectation2)
109
+
110
+ sut. signIn ( username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy2)
111
+
112
+ XCTAssertTrue ( signInDelegateSpy2. error!. description, " An account is already signed in. " )
113
+ }
114
+
115
+ // User Case 1.2.5. Sign In - User signs in with account B, while data for account A already exists in SDK persistence
116
+ // The same as 1.2.4
117
+
118
+ // User Case 1.2.6. Sign In - Ability to provide scope to control auth strength of the token
119
+
120
+ // User Case 1.2.7. Sign In - User email is registered with email OTP auth method, which is supported by the developer
121
+ func test_signInWithOTPSufficientChallengeResultsInSuccess( ) async throws {
122
+ guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInUsernameAndPassword ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
123
+ XCTFail ( " Missing information " )
124
+ return
125
+ }
126
+
127
+ let signInExpectation = expectation ( description: " signing in " )
128
+ let passwordRequiredExpectation = expectation ( description: " verifying password " )
129
+ let signInDelegateSpy = SignInStartDelegateSpy ( expectation: signInExpectation)
130
+ let signInPasswordRequiredDelegateSpy = SignInPasswordRequiredDelegateSpy ( expectation: passwordRequiredExpectation)
131
+
132
+ sut. signIn ( username: username, correlationId: correlationId, delegate: signInDelegateSpy)
133
+
134
+ await fulfillment ( of: [ signInExpectation] )
135
+
136
+ guard signInDelegateSpy. onSignInPasswordRequiredCalled else {
137
+ XCTFail ( " onSignInPasswordRequired not called " )
138
+ return
139
+ }
140
+
141
+ XCTAssertNotNil ( signInDelegateSpy. newStatePasswordRequired)
142
+
143
+ // Now submit the password..
144
+
145
+ signInDelegateSpy. newStatePasswordRequired? . submitPassword ( password: password, delegate: signInPasswordRequiredDelegateSpy)
146
+
147
+ await fulfillment ( of: [ passwordRequiredExpectation] )
148
+
149
+ XCTAssertTrue ( signInPasswordRequiredDelegateSpy. onSignInCompletedCalled)
150
+ }
151
+
152
+ // User Case 1.2.8. Sign In - User attempts to sign in with email and password, but server requires second factor authentication (MFA OTP)
153
+ // Please refer to MFA End to End Test
154
+
155
+ // User Case 1.2.9. Sign In - User email is registered with email OTP auth method, which is not supported by the developer (aka redirect flow)
156
+ func test_signInWithOTPInsufficientChallengeResultsInError( ) async throws {
157
+ guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInUsernameAndPassword ( ) , let password = await retrievePasswordForSignInUsername ( ) else {
158
+ XCTFail ( " Missing information " )
159
+ return
160
+ }
161
+
162
+ let signInExpectation = expectation ( description: " signing in " )
163
+ let signInDelegateSpy = SignInPasswordStartDelegateSpy ( expectation: signInExpectation)
164
+
165
+ sut. signIn ( username: username, password: password, correlationId: correlationId, delegate: signInDelegateSpy)
166
+
167
+ await fulfillment ( of: [ signInExpectation] )
168
+
169
+ XCTAssertTrue ( signInDelegateSpy. onSignInPasswordErrorCalled)
170
+ XCTAssertTrue ( signInDelegateSpy. error!. isBrowserRequired)
171
+ }
172
+
173
+
88
174
// Sign in - Password is incorrect (sent over delegate.newStatePasswordRequired)
89
175
func test_signInAndSendingIncorrectPasswordResultsInError( ) async throws {
90
176
guard let sut = initialisePublicClientApplication ( ) , let username = retrieveUsernameForSignInUsernameAndPassword ( ) else {
0 commit comments