Skip to content

Commit

Permalink
feat(authenticator): Add support for Email MFA (#199)
Browse files Browse the repository at this point in the history
Co-authored-by: tjroach <[email protected]>
  • Loading branch information
vincetran and tylerjroach authored Oct 31, 2024
1 parent ecfa81f commit 409b53b
Show file tree
Hide file tree
Showing 36 changed files with 834 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amplifyframework.ui.authenticator.ui

import com.amplifyframework.auth.AuthCodeDeliveryDetails
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
import com.amplifyframework.ui.authenticator.SignInConfirmMfaState
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
import com.amplifyframework.ui.authenticator.forms.FieldConfig
import com.amplifyframework.ui.authenticator.forms.FieldError
import com.amplifyframework.ui.authenticator.forms.FieldKey
import com.amplifyframework.ui.authenticator.mockFieldData
import com.amplifyframework.ui.authenticator.mockFieldState
import com.amplifyframework.ui.authenticator.mockForm
import org.junit.Test

class SignInConfirmMfa : ScreenshotTestBase() {

@Test
fun sign_in_confirm_email_mfa_default() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"[email protected]",
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL
)
)
)
}
}

@Test
fun sign_in_confirm_email_mfa_incorrect_code() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"[email protected]",
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL
),
"123456",
FieldError.ConfirmationCodeIncorrect
)
)
}
}

@Test
fun sign_in_confirm_sms_mfa_default() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"123-123-1234",
AuthCodeDeliveryDetails.DeliveryMedium.SMS
)
)
)
}
}

@Test
fun sign_in_confirm_sms_mfa_incorrect_code() {
screenshot {
SignInConfirmMfa(
mockSignInConfirmMfaState(
AuthCodeDeliveryDetails(
"123-123-1234",
AuthCodeDeliveryDetails.DeliveryMedium.SMS
),
"123456",
FieldError.ConfirmationCodeIncorrect
)
)
}
}

private fun mockSignInConfirmMfaState(
deliveryDetails: AuthCodeDeliveryDetails,
confirmationCode: String = "",
fieldError: FieldError? = null
) = object : SignInConfirmMfaState {
override val form = mockForm(
mockFieldData(
config = FieldConfig.Text(FieldKey.ConfirmationCode),
state = mockFieldState(content = confirmationCode, error = fieldError)
)
)
override val deliveryDetails: AuthCodeDeliveryDetails
get() = deliveryDetails

override fun moveTo(step: AuthenticatorInitialStep) {}
override suspend fun confirmSignIn() {
TODO("Not yet implemented")
}

override val step = AuthenticatorStep.SignInContinueWithEmailSetup
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amplifyframework.ui.authenticator.ui

import com.amplifyframework.ui.authenticator.ScreenshotTestBase
import com.amplifyframework.ui.authenticator.SignInContinueWithEmailSetupState
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
import com.amplifyframework.ui.authenticator.forms.FieldConfig
import com.amplifyframework.ui.authenticator.forms.FieldKey
import com.amplifyframework.ui.authenticator.mockFieldData
import com.amplifyframework.ui.authenticator.mockFieldState
import com.amplifyframework.ui.authenticator.mockForm
import org.junit.Test

class SignInContinueWithEmailSetupScreenshots : ScreenshotTestBase() {

@Test
fun default_state() {
screenshot {
SignInContinueWithEmailSetup(mockSignInContinueWithEmailSetupState())
}
}

private fun mockSignInContinueWithEmailSetupState() = object : SignInContinueWithEmailSetupState {
override val form = mockForm(
mockFieldData(
config = FieldConfig.Text(FieldKey.Email),
state = mockFieldState(content = "[email protected]")
)
)
override fun moveTo(step: AuthenticatorInitialStep) {}
override suspend fun continueSignIn() {}
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amplifyframework.ui.authenticator.ui

import com.amplifyframework.auth.MFAType
import com.amplifyframework.ui.authenticator.ScreenshotTestBase
import com.amplifyframework.ui.authenticator.SignInContinueWithMfaSetupSelectionState
import com.amplifyframework.ui.authenticator.enums.AuthenticatorInitialStep
import com.amplifyframework.ui.authenticator.enums.AuthenticatorStep
import com.amplifyframework.ui.authenticator.forms.FieldConfig
import com.amplifyframework.ui.authenticator.forms.FieldKey
import com.amplifyframework.ui.authenticator.mockFieldData
import com.amplifyframework.ui.authenticator.mockFieldState
import com.amplifyframework.ui.authenticator.mockForm
import org.junit.Test

class SignInContinueWithMfaSetupSelection : ScreenshotTestBase() {

@Test
fun default_state() {
screenshot {
SignInContinueWithMfaSetupSelection(mockSignInContinueWithMfaSetupSelectionState())
}
}

private fun mockSignInContinueWithMfaSetupSelectionState() = object : SignInContinueWithMfaSetupSelectionState {
override val form = mockForm(
mockFieldData(
config = FieldConfig.Text(FieldKey.MfaSelection),
state = mockFieldState(content = "EMAIL_OTP")
)
)
override val allowedMfaTypes: Set<MFAType>
get() = setOf(MFAType.TOTP, MFAType.SMS, MFAType.EMAIL)

override fun moveTo(step: AuthenticatorInitialStep) {}
override suspend fun continueSignIn() {}
override val step = AuthenticatorStep.SignInContinueWithEmailSetup
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 409b53b

Please sign in to comment.