Skip to content

Commit 959934e

Browse files
authored
fix: Pass additional info in signIn next step (#1201)
1 parent bc06036 commit 959934e

File tree

2 files changed

+119
-2
lines changed

2 files changed

+119
-2
lines changed

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Models/SignInResult+Extension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ extension SignInResult {
2020
return .done
2121
case .smsMFA:
2222
let deliveryDetails = AuthCodeDeliveryDetails(destination: .sms(codeDetails?.destination))
23-
return .confirmSignInWithSMSMFACode(deliveryDetails, nil)
23+
return .confirmSignInWithSMSMFACode(deliveryDetails, parameters)
2424
case .customChallenge:
2525
return .confirmSignInWithCustomChallenge(parameters)
2626
case .newPasswordRequired:
27-
return .confirmSignInWithNewPassword(nil)
27+
return .confirmSignInWithNewPassword(parameters)
2828
default:
2929
throw (AuthError.unknown("AWSMobileClient auth state is not handled"))
3030
}

AmplifyPlugins/Auth/AWSCognitoAuthPluginTests/AuthenticationProviderTests/AuthenticationProviderSigninTests.swift

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,123 @@ class AuthenticationProviderSigninTests: BaseAuthenticationProviderTest {
186186
wait(for: [resultExpectation], timeout: apiTimeout)
187187
}
188188

189+
/// Test a signIn with additional info in next step
190+
///
191+
/// - Given: Given an auth plugin with mocked service. Mock additional info in custom auth
192+
///
193+
/// - When:
194+
/// - I invoke signIn
195+
/// - Then:
196+
/// - I should get a the info in next step
197+
///
198+
func testCustomAuthWithAdditionalInfo() {
199+
200+
let mockSigninResult = SignInResult(signInState: .customChallenge, parameters: ["paramKey": "value"])
201+
mockAWSMobileClient?.signInMockResult = .success(mockSigninResult)
202+
203+
let options = AuthSignInRequest.Options()
204+
let resultExpectation = expectation(description: "Should receive a result")
205+
_ = plugin.signIn(username: "username", password: "password", options: options) { result in
206+
defer {
207+
resultExpectation.fulfill()
208+
}
209+
switch result {
210+
case .success(let signinResult):
211+
guard case .confirmSignInWithCustomChallenge(let additionalInfo) = signinResult.nextStep else {
212+
XCTFail("Result should be .confirmSignInWithCustomChallenge for next step")
213+
return
214+
}
215+
guard let addditionalValue = additionalInfo?["paramKey"] else {
216+
XCTFail("Additional info should be passed to the result")
217+
return
218+
}
219+
XCTAssertEqual(addditionalValue, "value", "Additional info should be same")
220+
XCTAssertFalse(signinResult.isSignedIn, "Signin result should not be complete")
221+
case .failure(let error):
222+
XCTFail("Received failure with error \(error)")
223+
}
224+
}
225+
wait(for: [resultExpectation], timeout: apiTimeout)
226+
}
227+
228+
/// Test a signIn with additional info in next step
229+
///
230+
/// - Given: Given an auth plugin with mocked service. Mock additional info in sms mfa
231+
///
232+
/// - When:
233+
/// - I invoke signIn
234+
/// - Then:
235+
/// - I should get a the info in next step
236+
///
237+
func testSMSMFAWithAdditionalInfo() {
238+
239+
let mockSigninResult = SignInResult(signInState: .smsMFA, parameters: ["paramKey": "value"])
240+
mockAWSMobileClient?.signInMockResult = .success(mockSigninResult)
241+
242+
let options = AuthSignInRequest.Options()
243+
let resultExpectation = expectation(description: "Should receive a result")
244+
_ = plugin.signIn(username: "username", password: "password", options: options) { result in
245+
defer {
246+
resultExpectation.fulfill()
247+
}
248+
switch result {
249+
case .success(let signinResult):
250+
guard case .confirmSignInWithSMSMFACode(_, let additionalInfo) = signinResult.nextStep else {
251+
XCTFail("Result should be .confirmSignInWithSMSMFACode for next step")
252+
return
253+
}
254+
guard let addditionalValue = additionalInfo?["paramKey"] else {
255+
XCTFail("Additional info should be passed to the result")
256+
return
257+
}
258+
XCTAssertEqual(addditionalValue, "value", "Additional info should be same")
259+
XCTAssertFalse(signinResult.isSignedIn, "Signin result should not be complete")
260+
case .failure(let error):
261+
XCTFail("Received failure with error \(error)")
262+
}
263+
}
264+
wait(for: [resultExpectation], timeout: apiTimeout)
265+
}
266+
267+
/// Test a signIn with additional info in next step
268+
///
269+
/// - Given: Given an auth plugin with mocked service. Mock additional info in new password
270+
///
271+
/// - When:
272+
/// - I invoke signIn
273+
/// - Then:
274+
/// - I should get a the info in next step
275+
///
276+
func testNewPasswordWithAdditionalInfo() {
277+
278+
let mockSigninResult = SignInResult(signInState: .newPasswordRequired, parameters: ["paramKey": "value"])
279+
mockAWSMobileClient?.signInMockResult = .success(mockSigninResult)
280+
281+
let options = AuthSignInRequest.Options()
282+
let resultExpectation = expectation(description: "Should receive a result")
283+
_ = plugin.signIn(username: "username", password: "password", options: options) { result in
284+
defer {
285+
resultExpectation.fulfill()
286+
}
287+
switch result {
288+
case .success(let signinResult):
289+
guard case .confirmSignInWithNewPassword(let additionalInfo) = signinResult.nextStep else {
290+
XCTFail("Result should be .confirmSignInWithNewPassword for next step")
291+
return
292+
}
293+
guard let addditionalValue = additionalInfo?["paramKey"] else {
294+
XCTFail("Additional info should be passed to the result")
295+
return
296+
}
297+
XCTAssertEqual(addditionalValue, "value", "Additional info should be same")
298+
XCTAssertFalse(signinResult.isSignedIn, "Signin result should not be complete")
299+
case .failure(let error):
300+
XCTFail("Received failure with error \(error)")
301+
}
302+
}
303+
wait(for: [resultExpectation], timeout: apiTimeout)
304+
}
305+
189306
/// Test a signIn with customChallenge as signIn result response
190307
///
191308
/// - Given: Given an auth plugin with mocked service. Mock customChallenge response for signIn result

0 commit comments

Comments
 (0)