Skip to content

Commit 608928f

Browse files
committed
feat(Auth): Worked on review comments and cleaning up unit tests (#3071)
1 parent ce277fb commit 608928f

22 files changed

+184
-98
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/MFATypeExtension.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
import Amplify
99
import Foundation
1010

11-
extension MFAType {
11+
extension MFAType: DefaultLogger {
1212

1313
internal init?(rawValue: String) {
1414
if rawValue.caseInsensitiveCompare("SMS_MFA") == .orderedSame {
1515
self = .sms
1616
} else if rawValue.caseInsensitiveCompare("SOFTWARE_TOKEN_MFA") == .orderedSame {
1717
self = .totp
1818
} else {
19+
Self.log.error("Tried to initialize an unsupported MFA type with value: \(rawValue) ")
1920
return nil
2021
}
2122
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/UserPoolSignInHelper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct UserPoolSignInHelper: DefaultLogger {
5151
} else if case .resolvingTOTPSetup(let totpSetupState, _) = signInState,
5252
case .waitingForAnswer(let totpSetupData) = totpSetupState {
5353
return .init(nextStep: .continueSignInWithTOTPSetup(
54-
.init(secretCode: totpSetupData.secretCode, username: totpSetupData.username)))
54+
.init(sharedSecret: totpSetupData.secretCode, username: totpSetupData.username)))
5555
}
5656
return nil
5757
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/SetUpTOTPTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SetUpTOTPTask: AuthSetUpTOTPTask, DefaultLogger {
6969
AuthPluginErrorConstants.invalidStateError,
7070
nil)
7171
}
72-
return .init(secretCode: secretCode,
72+
return .init(sharedSecret: secretCode,
7373
username: authUser.username)
7474

7575
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/ClientBehaviorConfirmResetPasswordTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ClientBehaviorConfirmResetPasswordTests: AWSCognitoAuthClientBehaviorTests
5454

5555
/// Test a successful confirmResetPassword call
5656
///
57-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
57+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
5858
/// - When:
5959
/// - I invoke confirmSignup with a valid username, a new password and a confirmation code
6060
/// - Then:
@@ -71,7 +71,7 @@ class ClientBehaviorConfirmResetPasswordTests: AWSCognitoAuthClientBehaviorTests
7171

7272
/// Test a confirmResetPassword call with empty username
7373
///
74-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
74+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
7575
/// - When:
7676
/// - I invoke confirmResetPassword with an empty username, a new password and a confirmation code
7777
/// - Then:
@@ -97,7 +97,7 @@ class ClientBehaviorConfirmResetPasswordTests: AWSCognitoAuthClientBehaviorTests
9797

9898
/// Test a confirmResetPassword call with plugin options
9999
///
100-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
100+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
101101
/// - When:
102102
/// - I invoke confirmResetPassword with an empty username, a new password and a confirmation code
103103
/// - Then:
@@ -121,7 +121,7 @@ class ClientBehaviorConfirmResetPasswordTests: AWSCognitoAuthClientBehaviorTests
121121

122122
/// Test a confirmResetPassword call with empty new password
123123
///
124-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
124+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
125125
/// - When:
126126
/// - I invoke confirmResetPassword with a valid username, an empty new password and a confirmation code
127127
/// - Then:

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/ClientBehaviorResetPasswordTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ClientBehaviorResetPasswordTests: AWSCognitoAuthClientBehaviorTests {
5353

5454
/// Test a successful resetPassword call
5555
///
56-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
56+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
5757
/// - When:
5858
/// - I invoke resetPassword with username
5959
/// - Then:
@@ -73,7 +73,7 @@ class ClientBehaviorResetPasswordTests: AWSCognitoAuthClientBehaviorTests {
7373

7474
/// Test a resetPassword call with nil UserCodeDeliveryDetails
7575
///
76-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
76+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
7777
/// - When:
7878
/// - I invoke resetPassword with username
7979
/// - Then:
@@ -100,7 +100,7 @@ class ClientBehaviorResetPasswordTests: AWSCognitoAuthClientBehaviorTests {
100100

101101
/// Test a resetPassword call with empty username
102102
///
103-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
103+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
104104
/// - When:
105105
/// - I invoke resetPassword with empty username
106106
/// - Then:

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/MFA/FetchMFAPreferenceTaskTests.swift

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FetchMFAPreferenceTaskTests: BasePluginTest {
1818

1919
/// Test a successful fetchMFAPreference call
2020
///
21-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
21+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
2222
/// - When:
2323
/// - I invoke fetchMFAPreference
2424
/// - Then:
@@ -45,7 +45,7 @@ class FetchMFAPreferenceTaskTests: BasePluginTest {
4545

4646
/// Test a successful fetchMFAPreference call
4747
///
48-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
48+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
4949
/// - When:
5050
/// - I invoke fetchMFAPreference
5151
/// - Then:
@@ -72,7 +72,7 @@ class FetchMFAPreferenceTaskTests: BasePluginTest {
7272

7373
/// Test a successful fetchMFAPreference call
7474
///
75-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
75+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
7676
/// - When:
7777
/// - I invoke fetchMFAPreference
7878
/// - Then:
@@ -98,7 +98,60 @@ class FetchMFAPreferenceTaskTests: BasePluginTest {
9898

9999
/// Test a successful fetchMFAPreference call
100100
///
101-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
101+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response with an invalid MFA type string
102+
/// - When:
103+
/// - I invoke fetchMFAPreference
104+
/// - Then:
105+
/// - I should get a successful result
106+
///
107+
func testInvalidResponseForUserMFASettingsList() async {
108+
109+
self.mockIdentityProvider = MockIdentityProvider(
110+
mockGetUserAttributeResponse: { request in
111+
return .init(
112+
userMFASettingList: ["DUMMY"]
113+
)
114+
})
115+
116+
do {
117+
let fetchMFAPreferenceResult = try await plugin.fetchMFAPreference()
118+
XCTAssertNil(fetchMFAPreferenceResult.enabled)
119+
XCTAssertNil(fetchMFAPreferenceResult.preferred)
120+
} catch {
121+
XCTFail("Received failure with error \(error)")
122+
}
123+
}
124+
125+
/// Test a successful fetchMFAPreference call
126+
///
127+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response with an invalid MFA type string
128+
/// - When:
129+
/// - I invoke fetchMFAPreference
130+
/// - Then:
131+
/// - I should get a successful result
132+
///
133+
func testInvalidResponseForUserMFAPreference() async {
134+
135+
self.mockIdentityProvider = MockIdentityProvider(
136+
mockGetUserAttributeResponse: { request in
137+
return .init(
138+
preferredMfaSetting: "DUMMY",
139+
userMFASettingList: ["SOFTWARE_TOKEN_MFA", "SMS_MFA"]
140+
)
141+
})
142+
143+
do {
144+
let fetchMFAPreferenceResult = try await plugin.fetchMFAPreference()
145+
XCTAssertNotNil(fetchMFAPreferenceResult.enabled)
146+
XCTAssertNil(fetchMFAPreferenceResult.preferred)
147+
} catch {
148+
XCTFail("Received failure with error \(error)")
149+
}
150+
}
151+
152+
/// Test a successful fetchMFAPreference call
153+
///
154+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
102155
/// - When:
103156
/// - I invoke fetchMFAPreference
104157
/// - Then:

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/MFA/SetUpTOTPTaskTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SetUpTOTPTaskTests: BasePluginTest {
1818

1919
/// Test a successful set up TOTP call
2020
///
21-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
21+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
2222
/// - When:
2323
/// - I invoke setUpTOTP
2424
/// - Then:

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/MFA/VerifyTOTPSetupTaskTests.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
4242
}
4343
}
4444

45-
46-
//case invalidUserPoolConfigurationException(InvalidUserPoolConfigurationException)
47-
4845
// MARK: Service error handling test
4946

5047
/// Test a verifyTOTPSetup call with forbiddenException response from service
@@ -178,7 +175,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
178175
/// - When:
179176
/// - I invoke verifyTOTPSetup
180177
/// - Then:
181-
/// - I should get a .service error with .softwareTokenMFANotEnabled as underlyingError
178+
/// - I should get a .service error with .mfaMethodNotFound as underlyingError
182179
///
183180
func testVerifyTOTPSetupWithSoftwareTokenMFANotFoundException() async {
184181

@@ -269,7 +266,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
269266
/// - When:
270267
/// - I invoke verifyTOTPSetup with a valid confirmation code
271268
/// - Then:
272-
/// - I should get a .service error with .resourceNotFound as underlyingError
269+
/// - I should get a .service error with .codeMismatch as underlyingError
273270
///
274271
func testVerifyTOTPSetupInWithCodeMismatchException() async {
275272
self.mockIdentityProvider = MockIdentityProvider(
@@ -300,7 +297,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
300297
/// - When:
301298
/// - I invoke verifyTOTPSetup with a valid confirmation code
302299
/// - Then:
303-
/// - I should get a .service error with .resourceNotFound as underlyingError
300+
/// - I should get a .service error with .softwareTokenMFANotEnabled as underlyingError
304301
///
305302
func testVerifyTOTPSetupInWithEnableSoftwareTokenMFAException() async {
306303
self.mockIdentityProvider = MockIdentityProvider(
@@ -331,7 +328,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
331328
/// - When:
332329
/// - I invoke verifyTOTPSetup with a valid confirmation code
333330
/// - Then:
334-
/// - I should get a .service error with .resourceNotFound as underlyingError
331+
/// - I should get a .service error with .passwordResetRequired as underlyingError
335332
///
336333
func testVerifyTOTPSetupInWithPasswordResetRequiredException() async {
337334
self.mockIdentityProvider = MockIdentityProvider(
@@ -362,7 +359,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
362359
/// - When:
363360
/// - I invoke verifyTOTPSetup with a valid confirmation code
364361
/// - Then:
365-
/// - I should get a .service error with .resourceNotFound as underlyingError
362+
/// - I should get a .service error with .requestLimitExceeded as underlyingError
366363
///
367364
func testVerifyTOTPSetupInWithTooManyRequestsException() async {
368365
self.mockIdentityProvider = MockIdentityProvider(
@@ -393,7 +390,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
393390
/// - When:
394391
/// - I invoke verifyTOTPSetup with a valid confirmation code
395392
/// - Then:
396-
/// - I should get a .service error with .resourceNotFound as underlyingError
393+
/// - I should get a .service error with .userNotFound as underlyingError
397394
///
398395
func testVerifyTOTPSetupInWithUserNotFoundException() async {
399396
self.mockIdentityProvider = MockIdentityProvider(
@@ -424,7 +421,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
424421
/// - When:
425422
/// - I invoke verifyTOTPSetup with a valid confirmation code
426423
/// - Then:
427-
/// - I should get a .service error with .resourceNotFound as underlyingError
424+
/// - I should get a .service error with .userNotConfirmed as underlyingError
428425
///
429426
func testVerifyTOTPSetupInWithUserNotConfirmedException() async {
430427
self.mockIdentityProvider = MockIdentityProvider(
@@ -455,7 +452,7 @@ class VerifyTOTPSetupTaskTests: BasePluginTest {
455452
/// - When:
456453
/// - I invoke verifyTOTPSetup with a valid confirmation code
457454
/// - Then:
458-
/// - I should get a .service error with .resourceNotFound as underlyingError
455+
/// - I should get a .service error
459456
///
460457
func testVerifyTOTPSetupInWithInvalidUserPoolConfigurationException() async {
461458
self.mockIdentityProvider = MockIdentityProvider(

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInTaskTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest {
2626

2727
/// Test a successful confirmSignIn call with .done as next step
2828
///
29-
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successul response
29+
/// - Given: an auth plugin with mocked service. Mocked service calls should mock a successful response
3030
/// - When:
3131
/// - I invoke confirmSignIn with a valid confirmation code
3232
/// - Then:
@@ -55,7 +55,7 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest {
5555

5656
/// Test a confirmSignIn call with an empty confirmation code
5757
///
58-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
58+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
5959
/// - When:
6060
/// - I invoke confirmSignIn with an empty confirmation code
6161
/// - Then:
@@ -80,9 +80,9 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest {
8080
}
8181
}
8282

83-
/// Test a confirmSignIn call with an empty confirmation code followed by a second valaid confirmSignIn call
83+
/// Test a confirmSignIn call with an empty confirmation code followed by a second valid confirmSignIn call
8484
///
85-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
85+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
8686
/// - When:
8787
/// - I invoke second confirmSignIn after confirmSignIn with an empty confirmation code
8888
/// - Then:
@@ -115,7 +115,7 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest {
115115

116116
/// Test a confirmSignIn call with client metadata and user attributes
117117
///
118-
/// - Given: an auth plugin with mocked service. Mocked service should mock a successul response
118+
/// - Given: an auth plugin with mocked service. Mocked service should mock a successful response
119119
/// - When:
120120
/// - I invoke confirmSignIn with an confirmation code and plugin options
121121
/// - Then:
@@ -411,7 +411,7 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest {
411411
/// - When:
412412
/// - I invoke confirmSignIn with a valid confirmation code
413413
/// - Then:
414-
/// - I should get a --
414+
/// - I should get a .service error with .smsRole as underlyingError
415415
///
416416
func testConfirmSignInWithinvalidSmsRoleAccessPolicyException() async {
417417
self.mockIdentityProvider = MockIdentityProvider(
@@ -442,7 +442,7 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest {
442442
/// - When:
443443
/// - I invoke confirmSignIn with a valid confirmation code
444444
/// - Then:
445-
/// - I should get a --
445+
/// - I should get a .service error with .smsRole as underlyingError
446446
///
447447
func testConfirmSignInWithInvalidSmsRoleTrustRelationshipException() async {
448448
self.mockIdentityProvider = MockIdentityProvider(

0 commit comments

Comments
 (0)