Skip to content

Commit 409b53b

Browse files
feat(authenticator): Add support for Email MFA (#199)
Co-authored-by: tjroach <tjroach@amazon.com>
1 parent ecfa81f commit 409b53b

File tree

36 files changed

+834
-24
lines changed

36 files changed

+834
-24
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.ui.authenticator.ui
17+
18+
import com.amplifyframework.auth.AuthCodeDeliveryDetails
19+
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
20+
import com.amplifyframework.ui.authenticator.SignInConfirmMfaState
21+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
22+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
23+
import com.amplifyframework.ui.authenticator.forms.FieldConfig
24+
import com.amplifyframework.ui.authenticator.forms.FieldError
25+
import com.amplifyframework.ui.authenticator.forms.FieldKey
26+
import com.amplifyframework.ui.authenticator.mockFieldData
27+
import com.amplifyframework.ui.authenticator.mockFieldState
28+
import com.amplifyframework.ui.authenticator.mockForm
29+
import org.junit.Test
30+
31+
class SignInConfirmMfa : ScreenshotTestBase() {
32+
33+
@Test
34+
fun sign_in_confirm_email_mfa_default() {
35+
screenshot {
36+
SignInConfirmMfa(
37+
mockSignInConfirmMfaState(
38+
AuthCodeDeliveryDetails(
39+
"email@email.com",
40+
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL
41+
)
42+
)
43+
)
44+
}
45+
}
46+
47+
@Test
48+
fun sign_in_confirm_email_mfa_incorrect_code() {
49+
screenshot {
50+
SignInConfirmMfa(
51+
mockSignInConfirmMfaState(
52+
AuthCodeDeliveryDetails(
53+
"email@email.com",
54+
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL
55+
),
56+
"123456",
57+
FieldError.ConfirmationCodeIncorrect
58+
)
59+
)
60+
}
61+
}
62+
63+
@Test
64+
fun sign_in_confirm_sms_mfa_default() {
65+
screenshot {
66+
SignInConfirmMfa(
67+
mockSignInConfirmMfaState(
68+
AuthCodeDeliveryDetails(
69+
"123-123-1234",
70+
AuthCodeDeliveryDetails.DeliveryMedium.SMS
71+
)
72+
)
73+
)
74+
}
75+
}
76+
77+
@Test
78+
fun sign_in_confirm_sms_mfa_incorrect_code() {
79+
screenshot {
80+
SignInConfirmMfa(
81+
mockSignInConfirmMfaState(
82+
AuthCodeDeliveryDetails(
83+
"123-123-1234",
84+
AuthCodeDeliveryDetails.DeliveryMedium.SMS
85+
),
86+
"123456",
87+
FieldError.ConfirmationCodeIncorrect
88+
)
89+
)
90+
}
91+
}
92+
93+
private fun mockSignInConfirmMfaState(
94+
deliveryDetails: AuthCodeDeliveryDetails,
95+
confirmationCode: String = "",
96+
fieldError: FieldError? = null
97+
) = object : SignInConfirmMfaState {
98+
override val form = mockForm(
99+
mockFieldData(
100+
config = FieldConfig.Text(FieldKey.ConfirmationCode),
101+
state = mockFieldState(content = confirmationCode, error = fieldError)
102+
)
103+
)
104+
override val deliveryDetails: AuthCodeDeliveryDetails
105+
get() = deliveryDetails
106+
107+
override fun moveTo(step: AuthenticatorInitialStep) {}
108+
override suspend fun confirmSignIn() {
109+
TODO("Not yet implemented")
110+
}
111+
112+
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.ui.authenticator.ui
17+
18+
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
19+
import com.amplifyframework.ui.authenticator.SignInContinueWithEmailSetupState
20+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
21+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
22+
import com.amplifyframework.ui.authenticator.forms.FieldConfig
23+
import com.amplifyframework.ui.authenticator.forms.FieldKey
24+
import com.amplifyframework.ui.authenticator.mockFieldData
25+
import com.amplifyframework.ui.authenticator.mockFieldState
26+
import com.amplifyframework.ui.authenticator.mockForm
27+
import org.junit.Test
28+
29+
class SignInContinueWithEmailSetupScreenshots : ScreenshotTestBase() {
30+
31+
@Test
32+
fun default_state() {
33+
screenshot {
34+
SignInContinueWithEmailSetup(mockSignInContinueWithEmailSetupState())
35+
}
36+
}
37+
38+
private fun mockSignInContinueWithEmailSetupState() = object : SignInContinueWithEmailSetupState {
39+
override val form = mockForm(
40+
mockFieldData(
41+
config = FieldConfig.Text(FieldKey.Email),
42+
state = mockFieldState(content = "email@email.com")
43+
)
44+
)
45+
override fun moveTo(step: AuthenticatorInitialStep) {}
46+
override suspend fun continueSignIn() {}
47+
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amplifyframework.ui.authenticator.ui
17+
18+
import com.amplifyframework.auth.MFAType
19+
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
20+
import com.amplifyframework.ui.authenticator.SignInContinueWithMfaSetupSelectionState
21+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
22+
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
23+
import com.amplifyframework.ui.authenticator.forms.FieldConfig
24+
import com.amplifyframework.ui.authenticator.forms.FieldKey
25+
import com.amplifyframework.ui.authenticator.mockFieldData
26+
import com.amplifyframework.ui.authenticator.mockFieldState
27+
import com.amplifyframework.ui.authenticator.mockForm
28+
import org.junit.Test
29+
30+
class SignInContinueWithMfaSetupSelection : ScreenshotTestBase() {
31+
32+
@Test
33+
fun default_state() {
34+
screenshot {
35+
SignInContinueWithMfaSetupSelection(mockSignInContinueWithMfaSetupSelectionState())
36+
}
37+
}
38+
39+
private fun mockSignInContinueWithMfaSetupSelectionState() = object : SignInContinueWithMfaSetupSelectionState {
40+
override val form = mockForm(
41+
mockFieldData(
42+
config = FieldConfig.Text(FieldKey.MfaSelection),
43+
state = mockFieldState(content = "EMAIL_OTP")
44+
)
45+
)
46+
override val allowedMfaTypes: Set<MFAType>
47+
get() = setOf(MFAType.TOTP, MFAType.SMS, MFAType.EMAIL)
48+
49+
override fun moveTo(step: AuthenticatorInitialStep) {}
50+
override suspend fun continueSignIn() {}
51+
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
52+
}
53+
}

0 commit comments

Comments
 (0)