From f10d04bc395e4eb64be6a32540464541eaa4aeee Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Tue, 8 Nov 2022 14:17:23 -0600 Subject: [PATCH 1/7] Adding custom auth test cases --- .../AWSCognitoAuthPluginFeatureTest.kt | 14 ++--- .../featuretest/generators/JsonGenerator.kt | 2 +- .../generators/SerializationTools.kt | 21 +++++-- .../AuthStateJsonGenerator.kt | 25 +++++++- .../SignInTestCaseGenerator.kt | 59 ++++++++++++++++++- .../utilities/AuthOptionsFactory.kt | 16 +++-- .../states/SigningIn_SigningIn.json | 8 ++- .../SigningIn_SigningIn_CustomAuth.json | 26 ++++++++ ..._request_and_returns_custom_challenge.json | 59 +++++++++++++++++++ 9 files changed, 207 insertions(+), 23 deletions(-) create mode 100644 aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json create mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt index 87f95f6d18..ee4cb7eb00 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt @@ -43,12 +43,6 @@ import io.mockk.mockk import io.mockk.mockkObject import io.mockk.mockkStatic import io.mockk.slot -import java.io.File -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit -import kotlin.reflect.full.callSuspend -import kotlin.reflect.full.declaredFunctions -import kotlin.test.assertEquals import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.test.resetMain @@ -61,6 +55,12 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized +import java.io.File +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import kotlin.reflect.full.callSuspend +import kotlin.reflect.full.declaredFunctions +import kotlin.test.assertEquals @RunWith(Parameterized::class) class AWSCognitoAuthPluginFeatureTest(private val testCase: FeatureTestCase) { @@ -201,7 +201,7 @@ class AWSCognitoAuthPluginFeatureTest(private val testCase: FeatureTestCase) { assertEquals(getState(validation.expectedState), authState) getStateLatch.countDown() } - getStateLatch.await(10, TimeUnit.SECONDS) + getStateLatch.await(10, TimeUnit.MINUTES) } } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt index 82aa69c1d5..df3809907d 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt @@ -44,6 +44,6 @@ object JsonGenerator { } fun main() { - cleanDirectory() + //cleanDirectory() JsonGenerator.generate() } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt index bbb675a420..74806edde5 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt @@ -23,12 +23,9 @@ import com.amplifyframework.auth.cognito.featuretest.serializers.CognitoIdentity import com.amplifyframework.auth.cognito.featuretest.serializers.CognitoIdentityProviderExceptionSerializer import com.amplifyframework.auth.cognito.featuretest.serializers.deserializeToAuthState import com.amplifyframework.auth.cognito.featuretest.serializers.serialize +import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions import com.amplifyframework.statemachine.codegen.states.AuthState import com.google.gson.Gson -import java.io.BufferedWriter -import java.io.File -import java.io.FileOutputStream -import java.io.FileWriter import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray @@ -36,6 +33,10 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive +import java.io.BufferedWriter +import java.io.File +import java.io.FileOutputStream +import java.io.FileWriter const val basePath = "aws-auth-cognito/src/test/resources/feature-test" @@ -51,7 +52,7 @@ fun writeFile(json: String, dirName: String, fileName: String) { } fun cleanDirectory() { - val directory = File("$basePath") + val directory = File(basePath) if (directory.exists()) { directory.deleteRecursively() } @@ -167,6 +168,7 @@ fun Any?.toJsonElement(): JsonElement { is Number -> JsonPrimitive(this) is String -> JsonPrimitive(this) is AuthException -> toJsonElement() + is AWSCognitoAuthSignInOptions -> toJsonElement() is CognitoIdentityProviderException -> Json.encodeToJsonElement( CognitoIdentityProviderExceptionSerializer, this @@ -176,6 +178,15 @@ fun Any?.toJsonElement(): JsonElement { } } +fun AWSCognitoAuthSignInOptions.toJsonElement(): JsonElement{ + val responseMap = mutableMapOf( + "metadata" to metadata, + "authFlowType" to authFlowType + ) + + return responseMap.toJsonElement() +} + fun AuthException.toJsonElement(): JsonElement { val responseMap = mutableMapOf( "errorType" to this::class.simpleName, diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt index 55ce81a5d3..4ce11254f9 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt @@ -86,7 +86,7 @@ object AuthStateJsonGenerator : SerializableProvider { session = "someSession", parameters = mapOf( "CODE_DELIVERY_DELIVERY_MEDIUM" to "SMS", - "CODE_DELIVERY_DESTINATION" to "+12345678900" + "CODE_DELIVERY_DESTINATION" to "+12345678911" ) ) ) @@ -95,5 +95,26 @@ object AuthStateJsonGenerator : SerializableProvider { AuthorizationState.SigningIn() ) - override val serializables: List = listOf(signedInState, signedOutState, receivedChallengeState) + private val receivedCustomChallengeState = AuthState.Configured( + AuthenticationState.SigningIn( + SignInState.ResolvingChallenge( + SignInChallengeState.WaitingForAnswer( + AuthChallenge( + challengeName = "CUSTOM_CHALLENGE", + username = username, + session = "someSession", + parameters = mapOf( + "SALT" to "abc", + "SECRET_BLOCK" to "secretBlock", + "SRP_B" to "def", + "USERNAME" to "username" + ) + ) + ) + ) + ), + AuthorizationState.SigningIn() + ) + + override val serializables: List = listOf(signedInState, signedOutState, receivedChallengeState, receivedCustomChallengeState) } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt index 7c01c3ec39..3287c8e0f1 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt @@ -27,6 +27,7 @@ import com.amplifyframework.auth.cognito.featuretest.ResponseType import com.amplifyframework.auth.cognito.featuretest.generators.SerializableProvider import com.amplifyframework.auth.cognito.featuretest.generators.authstategenerators.AuthStateJsonGenerator import com.amplifyframework.auth.cognito.featuretest.generators.toJsonElement +import com.amplifyframework.auth.cognito.options.AuthFlowType import kotlinx.serialization.json.JsonObject object SignInTestCaseGenerator : SerializableProvider { @@ -51,6 +52,22 @@ object SignInTestCaseGenerator : SerializableProvider { ).toJsonElement() ) + private val mockedInitiateAuthForCustomAuthWithoutSRPResponse = MockResponse( + CognitoType.CognitoIdentityProvider, + "initiateAuth", + ResponseType.Success, + mapOf( + "challengeName" to ChallengeNameType.CustomChallenge.toString(), + "session" to "someSession", + "challengeParameters" to mapOf( + "SALT" to "abc", + "SECRET_BLOCK" to "secretBlock", + "SRP_B" to "def", + "USERNAME" to username, + ) + ).toJsonElement() + ) + private val mockedRespondToAuthChallengeResponse = MockResponse( CognitoType.CognitoIdentityProvider, "respondToAuthChallenge", @@ -146,6 +163,23 @@ object SignInTestCaseGenerator : SerializableProvider { ).toJsonElement() ) + private val mockedSignInCustomAuthChallengeExpectation = ExpectationShapes.Amplify( + apiName = AuthAPI.signIn, + responseType = ResponseType.Success, + response = mapOf( + "isSignedIn" to false, + "nextStep" to mapOf( + "signInStep" to "CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE", + "additionalInfo" to mapOf( + "SALT" to "abc", + "SECRET_BLOCK" to "secretBlock", + "USERNAME" to "username", + "SRP_B" to "def" + ) + ) + ).toJsonElement() + ) + private val mockConfirmDeviceResponse = MockResponse( CognitoType.CognitoIdentityProvider, "confirmDevice", @@ -232,5 +266,28 @@ object SignInTestCaseGenerator : SerializableProvider { ) ) - override val serializables: List = listOf(baseCase, challengeCase, deviceSRPTestCase) + private val customAuthCase = baseCase.copy( + description = "Test that Custom Auth signIn invokes proper cognito request and returns custom challenge", + preConditions = PreConditions( + "authconfiguration.json", + "SignedOut_Configured.json", + mockedResponses = listOf( + mockedInitiateAuthForCustomAuthWithoutSRPResponse + ) + ), + api = API( + AuthAPI.signIn, + params = mapOf( + "username" to username, + "password" to "", + ).toJsonElement(), + options = mapOf("signInOptions" to mapOf("authFlow" to AuthFlowType.CUSTOM_AUTH_WITHOUT_SRP.toString())).toJsonElement() + ), + validations = listOf( + mockedSignInCustomAuthChallengeExpectation, + ExpectationShapes.State("SigningIn_SigningIn_CustomAuth.json") + ) + ) + + override val serializables: List = listOf(baseCase, challengeCase, deviceSRPTestCase, customAuthCase) } diff --git a/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt b/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt index 449a02fcc3..0272bcaf87 100644 --- a/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt +++ b/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt @@ -3,12 +3,11 @@ package featureTest.utilities import com.amplifyframework.auth.AuthUserAttribute import com.amplifyframework.auth.AuthUserAttributeKey import com.amplifyframework.auth.cognito.featuretest.AuthAPI -import com.amplifyframework.auth.cognito.featuretest.AuthAPI.confirmSignIn -import com.amplifyframework.auth.cognito.featuretest.AuthAPI.deleteUser import com.amplifyframework.auth.cognito.featuretest.AuthAPI.resetPassword import com.amplifyframework.auth.cognito.featuretest.AuthAPI.signIn -import com.amplifyframework.auth.cognito.featuretest.AuthAPI.signOut import com.amplifyframework.auth.cognito.featuretest.AuthAPI.signUp +import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions +import com.amplifyframework.auth.cognito.options.AuthFlowType import com.amplifyframework.auth.options.AuthConfirmResetPasswordOptions import com.amplifyframework.auth.options.AuthConfirmSignInOptions import com.amplifyframework.auth.options.AuthConfirmSignUpOptions @@ -46,7 +45,7 @@ object AuthOptionsFactory { AuthAPI.rememberDevice -> TODO() AuthAPI.resendSignUpCode -> AuthResendSignUpCodeOptions.defaults() AuthAPI.resendUserAttributeConfirmationCode -> AuthResendUserAttributeConfirmationCodeOptions.defaults() - signIn -> AuthSignInOptions.defaults() + signIn -> getSignInOptions(optionsData) AuthAPI.signInWithSocialWebUI -> AuthWebUISignInOptions.builder().build() AuthAPI.signInWithWebUI -> AuthWebUISignInOptions.builder().build() AuthAPI.signOut -> getSignOutOptions(optionsData) @@ -61,6 +60,15 @@ object AuthOptionsFactory { AuthAPI.getVersion -> TODO() } as T + private fun getSignInOptions(optionsData: JsonObject): AuthSignInOptions { + return if(optionsData.containsKey("signInOptions")) { + val authFlowType = AuthFlowType.valueOf(((optionsData["signInOptions"] as Map)["authFlow"] as JsonPrimitive).content) + AWSCognitoAuthSignInOptions.builder().authFlowType(authFlowType).build() + } else { + AuthSignInOptions.defaults() + } + } + private fun getSignUpOptions(optionsData: JsonObject): AuthSignUpOptions = AuthSignUpOptions.builder().userAttributes( (optionsData["userAttributes"] as Map).map { diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json index dace0d38ce..b641b4d58f 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json @@ -7,12 +7,14 @@ "SignInChallengeState": { "type": "SignInChallengeState.WaitingForAnswer", "authChallenge": { - "challengeName": "SMS_MFA", + "challengeName": "CUSTOM_CHALLENGE", "username": "username", "session": "someSession", "parameters": { - "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", - "CODE_DELIVERY_DESTINATION": "+12345678900" + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "username" } } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json new file mode 100644 index 0000000000..b641b4d58f --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json @@ -0,0 +1,26 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SigningIn", + "SignInState": { + "type": "SignInState.ResolvingChallenge", + "SignInChallengeState": { + "type": "SignInChallengeState.WaitingForAnswer", + "authChallenge": { + "challengeName": "CUSTOM_CHALLENGE", + "username": "username", + "session": "someSession", + "parameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "username" + } + } + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SigningIn" + } +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json new file mode 100644 index 0000000000..78db4e8205 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json @@ -0,0 +1,59 @@ +{ + "description": "Test that Custom Auth signIn invokes proper cognito request and returns custom challenge", + "preConditions": { + "amplify-configuration": "authconfiguration.json", + "state": "SignedOut_Configured.json", + "mockedResponses": [ + { + "type": "cognitoIdentityProvider", + "apiName": "initiateAuth", + "responseType": "success", + "response": { + "challengeName": "CUSTOM_CHALLENGE", + "session": "someSession", + "challengeParameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "username" + } + } + } + ] + }, + "api": { + "name": "signIn", + "params": { + "username": "username", + "password": "" + }, + "options": { + "signInOptions": { + "authFlow": "CUSTOM_AUTH_WITHOUT_SRP" + } + } + }, + "validations": [ + { + "type": "amplify", + "apiName": "signIn", + "responseType": "success", + "response": { + "isSignedIn": false, + "nextStep": { + "signInStep": "CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE", + "additionalInfo": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "USERNAME": "username", + "SRP_B": "def" + } + } + } + }, + { + "type": "state", + "expectedState": "SigningIn_SigningIn_CustomAuth.json" + } + ] +} \ No newline at end of file From 0215c82accc0ab0baa0f0272ae843cb095d67528 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 1 Dec 2022 11:24:48 -0600 Subject: [PATCH 2/7] Updating test cases for Custom Auth to ensure they pass --- .../generators/SerializationTools.kt | 16 +++--- .../AuthStateJsonGenerator.kt | 2 +- .../SignInTestCaseGenerator.kt | 33 ++++++------ .../states/CustomSignIn_SigningIn.json | 26 +++++++++ .../states/SigningIn_SigningIn.json | 8 ++- .../SigningIn_SigningIn_CustomAuth.json | 26 --------- ...s_successfully_returned_after_refresh.json | 53 +++++++++++++++++++ ...ccessfully_returned_for_Identity_Pool.json | 45 ++++++++++++++++ ...ly_returned_for_UserAndIdentity_Pool.json} | 2 +- ...s_successfully_returned_for_User_Pool.json | 44 +++++++++++++++ ..._request_and_returns_custom_challenge.json | 15 +++++- ...ito_request_and_returns_SMS_challenge.json | 4 +- 12 files changed, 214 insertions(+), 60 deletions(-) create mode 100644 aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json delete mode 100644 aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json create mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_after_refresh.json create mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_Identity_Pool.json rename aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/{Test_that_API_is_called_with_given_payload_and_returns_successful_data.json => AuthSession_object_is_successfully_returned_for_UserAndIdentity_Pool.json} (95%) create mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_User_Pool.json diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt index 02dbde2177..2d133704b0 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt @@ -28,13 +28,6 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions import com.amplifyframework.auth.result.AuthSessionResult import com.amplifyframework.statemachine.codegen.states.AuthState import com.google.gson.Gson -import java.io.BufferedWriter -import java.io.File -import java.io.FileOutputStream -import java.io.FileWriter -import kotlin.reflect.KClass -import kotlin.reflect.KVisibility -import kotlin.reflect.full.declaredMemberProperties import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray @@ -42,6 +35,13 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive +import java.io.BufferedWriter +import java.io.File +import java.io.FileOutputStream +import java.io.FileWriter +import kotlin.reflect.KClass +import kotlin.reflect.KVisibility +import kotlin.reflect.full.declaredMemberProperties const val basePath = "aws-auth-cognito/src/test/resources/feature-test" @@ -233,4 +233,4 @@ fun reflectionBasedSerializer(value: Any): JsonElement { }.associate { it.name to it.getter.call(value) }.toMap().toJsonElement() -} +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt index fbda7ad618..b6285d05c6 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt @@ -122,5 +122,5 @@ object AuthStateJsonGenerator : SerializableProvider { AuthorizationState.SigningIn() ) - override val serializables: List = listOf(signedInState, signedOutState, receivedChallengeState, receivedCustomChallengeState) + override val serializables: List = listOf(signedInState, signedOutState, receivedChallengeState) } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt index 3287c8e0f1..b2d199d851 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt @@ -34,7 +34,7 @@ object SignInTestCaseGenerator : SerializableProvider { private const val userId = "userId" private const val username = "username" private const val password = "password" - private const val phone = "+12345678900" + private const val phone = "+12345678911" private val mockedInitiateAuthResponse = MockResponse( CognitoType.CognitoIdentityProvider, @@ -58,7 +58,6 @@ object SignInTestCaseGenerator : SerializableProvider { ResponseType.Success, mapOf( "challengeName" to ChallengeNameType.CustomChallenge.toString(), - "session" to "someSession", "challengeParameters" to mapOf( "SALT" to "abc", "SECRET_BLOCK" to "secretBlock", @@ -114,6 +113,19 @@ object SignInTestCaseGenerator : SerializableProvider { ).toJsonElement() ) + private val mockedCustomChallengeResponse = MockResponse( + CognitoType.CognitoIdentityProvider, + "respondToAuthChallenge", + ResponseType.Success, + mapOf( + "session" to "someSession", + "challengeName" to "CUSTOM_CHALLENGE", + "challengeParameters" to mapOf( + "Code" to "1234" + ) + ).toJsonElement() + ) + private val mockedIdentityIdResponse = MockResponse( CognitoType.CognitoIdentity, "getId", @@ -208,16 +220,6 @@ object SignInTestCaseGenerator : SerializableProvider { options = JsonObject(emptyMap()) ), validations = listOf( -// ExpectationShapes.Cognito( -// apiName = "signIn", -// // see [https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html] -// // see [https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_RespondToAuthChallenge.html] -// request = mapOf( -// "clientId" to "testAppClientId", // This should be pulled from configuration -// "authFlow" to AuthFlowType.UserSrpAuth, -// "authParameters" to mapOf("username" to username, "SRP_A" to "123") -// ).toJsonElement() -// ), mockedSignInSuccessExpectation, ExpectationShapes.State("SignedIn_SessionEstablished.json") ) @@ -266,13 +268,14 @@ object SignInTestCaseGenerator : SerializableProvider { ) ) - private val customAuthCase = baseCase.copy( + private val customAuthCase = FeatureTestCase( description = "Test that Custom Auth signIn invokes proper cognito request and returns custom challenge", preConditions = PreConditions( "authconfiguration.json", "SignedOut_Configured.json", mockedResponses = listOf( - mockedInitiateAuthForCustomAuthWithoutSRPResponse + mockedInitiateAuthForCustomAuthWithoutSRPResponse, + mockedCustomChallengeResponse ) ), api = API( @@ -285,7 +288,7 @@ object SignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInCustomAuthChallengeExpectation, - ExpectationShapes.State("SigningIn_SigningIn_CustomAuth.json") + ExpectationShapes.State("CustomSignIn_SigningIn.json") ) ) diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json new file mode 100644 index 0000000000..e69e8f6662 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json @@ -0,0 +1,26 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SigningIn", + "SignInState": { + "type": "SignInState.ResolvingChallenge", + "SignInChallengeState": { + "type": "SignInChallengeState.WaitingForAnswer", + "authChallenge": { + "challengeName": "CUSTOM_CHALLENGE", + "username": "username", + "session": null, + "parameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "username" + } + } + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SigningIn" + } +} diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json index b641b4d58f..f971a4c939 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json @@ -7,14 +7,12 @@ "SignInChallengeState": { "type": "SignInChallengeState.WaitingForAnswer", "authChallenge": { - "challengeName": "CUSTOM_CHALLENGE", + "challengeName": "SMS_MFA", "username": "username", "session": "someSession", "parameters": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "SRP_B": "def", - "USERNAME": "username" + "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", + "CODE_DELIVERY_DESTINATION": "+12345678911" } } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json deleted file mode 100644 index b641b4d58f..0000000000 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_CustomAuth.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "type": "AuthState.Configured", - "AuthenticationState": { - "type": "AuthenticationState.SigningIn", - "SignInState": { - "type": "SignInState.ResolvingChallenge", - "SignInChallengeState": { - "type": "SignInChallengeState.WaitingForAnswer", - "authChallenge": { - "challengeName": "CUSTOM_CHALLENGE", - "username": "username", - "session": "someSession", - "parameters": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "SRP_B": "def", - "USERNAME": "username" - } - } - } - } - }, - "AuthorizationState": { - "type": "AuthorizationState.SigningIn" - } -} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_after_refresh.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_after_refresh.json new file mode 100644 index 0000000000..b10484548e --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_after_refresh.json @@ -0,0 +1,53 @@ +{ + "description": "AuthSession object is successfully returned after refresh", + "preConditions": { + "amplify-configuration": "authconfiguration.json", + "state": "SignedIn_SessionEstablished.json", + "mockedResponses": [ + { + "type": "cognitoIdentityProvider", + "apiName": "initiateAuth", + "responseType": "success", + "response": { + "authenticationResult": { + "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "expiresIn": 300 + } + } + } + ] + }, + "api": { + "name": "fetchAuthSession", + "params": { + }, + "options": { + "forceRefresh": true + } + }, + "validations": [ + { + "type": "amplify", + "apiName": "fetchAuthSession", + "responseType": "success", + "response": { + "awsCredentialsResult": { + "accessKeyId": "someAccessKey", + "expiration": 2342134, + "secretAccessKey": "someSecretKey", + "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU" + }, + "identityIdResult": "someIdentityId", + "isSignedIn": true, + "userPoolTokensResult": { + "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU" + }, + "userSubResult": "userId" + } + } + ] +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_Identity_Pool.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_Identity_Pool.json new file mode 100644 index 0000000000..98d7623119 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_Identity_Pool.json @@ -0,0 +1,45 @@ +{ + "description": "AuthSession object is successfully returned for Identity Pool", + "preConditions": { + "amplify-configuration": "authconfiguration.json", + "state": "SignedOut_IdentityPoolConfigured.json", + "mockedResponses": [ + ] + }, + "api": { + "name": "fetchAuthSession", + "params": { + }, + "options": { + } + }, + "validations": [ + { + "type": "amplify", + "apiName": "fetchAuthSession", + "responseType": "success", + "response": { + "awsCredentialsResult": { + "accessKeyId": "someAccessKey", + "expiration": 2342134, + "secretAccessKey": "someSecretKey", + "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU" + }, + "identityIdResult": "someIdentityId", + "isSignedIn": false, + "userPoolTokensResult": { + "errorType": "SignedOutException", + "errorMessage": "You are currently signed out.", + "recoverySuggestion": "Please sign in and reattempt the operation.", + "cause": null + }, + "userSubResult": { + "errorType": "SignedOutException", + "errorMessage": "You are currently signed out.", + "recoverySuggestion": "Please sign in and reattempt the operation.", + "cause": null + } + } + } + ] +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/Test_that_API_is_called_with_given_payload_and_returns_successful_data.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_UserAndIdentity_Pool.json similarity index 95% rename from aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/Test_that_API_is_called_with_given_payload_and_returns_successful_data.json rename to aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_UserAndIdentity_Pool.json index aacf3ab58c..5c840db23c 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/Test_that_API_is_called_with_given_payload_and_returns_successful_data.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_UserAndIdentity_Pool.json @@ -1,5 +1,5 @@ { - "description": "Test that API is called with given payload and returns successful data", + "description": "AuthSession object is successfully returned for UserAndIdentity Pool", "preConditions": { "amplify-configuration": "authconfiguration.json", "state": "SignedIn_SessionEstablished.json", diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_User_Pool.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_User_Pool.json new file mode 100644 index 0000000000..58db064009 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/fetchAuthSession/AuthSession_object_is_successfully_returned_for_User_Pool.json @@ -0,0 +1,44 @@ +{ + "description": "AuthSession object is successfully returned for User Pool", + "preConditions": { + "amplify-configuration": "authconfiguration.json", + "state": "SignedIn_UserPoolSessionEstablished.json", + "mockedResponses": [ + ] + }, + "api": { + "name": "fetchAuthSession", + "params": { + }, + "options": { + } + }, + "validations": [ + { + "type": "amplify", + "apiName": "fetchAuthSession", + "responseType": "success", + "response": { + "awsCredentialsResult": { + "errorType": "ConfigurationException", + "errorMessage": "Could not fetch AWS Cognito credentials", + "recoverySuggestion": "Cognito Identity not configured. Please check amplifyconfiguration.json file.", + "cause": null + }, + "identityIdResult": { + "errorType": "ConfigurationException", + "errorMessage": "Could not retrieve Identity ID", + "recoverySuggestion": "Cognito Identity not configured. Please check amplifyconfiguration.json file.", + "cause": null + }, + "isSignedIn": true, + "userPoolTokensResult": { + "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU" + }, + "userSubResult": "userId" + } + } + ] +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json index 78db4e8205..d987c78b29 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json @@ -10,7 +10,6 @@ "responseType": "success", "response": { "challengeName": "CUSTOM_CHALLENGE", - "session": "someSession", "challengeParameters": { "SALT": "abc", "SECRET_BLOCK": "secretBlock", @@ -18,6 +17,18 @@ "USERNAME": "username" } } + }, + { + "type": "cognitoIdentityProvider", + "apiName": "respondToAuthChallenge", + "responseType": "success", + "response": { + "session": "someSession", + "challengeName": "CUSTOM_CHALLENGE", + "challengeParameters": { + "Code": "1234" + } + } } ] }, @@ -53,7 +64,7 @@ }, { "type": "state", - "expectedState": "SigningIn_SigningIn_CustomAuth.json" + "expectedState": "CustomSignin_SigningIn.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json index 5cc1ab4d0a..3dc784bfdb 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json @@ -28,7 +28,7 @@ "challengeName": "SMS_MFA", "challengeParameters": { "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", - "CODE_DELIVERY_DESTINATION": "+12345678900" + "CODE_DELIVERY_DESTINATION": "+12345678911" } } } @@ -55,7 +55,7 @@ "additionalInfo": { }, "codeDeliveryDetails": { - "destination": "+12345678900", + "destination": "+12345678911", "deliveryMedium": "SMS" } } From a35b9dc5b6f60627f5ff87ee48b3a04a347d396c Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 1 Dec 2022 12:33:53 -0600 Subject: [PATCH 3/7] lint format --- .../cognito/AWSCognitoAuthPluginFeatureTest.kt | 14 +++++++------- .../featuretest/generators/JsonGenerator.kt | 2 +- .../generators/SerializationTools.kt | 18 +++++++++--------- .../SignInTestCaseGenerator.kt | 5 ++++- .../utilities/AuthOptionsFactory.kt | 6 ++++-- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt index b80de48248..8b1a1f8a80 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt @@ -43,6 +43,12 @@ import io.mockk.mockk import io.mockk.mockkObject import io.mockk.mockkStatic import io.mockk.slot +import java.io.File +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import kotlin.reflect.full.callSuspend +import kotlin.reflect.full.declaredFunctions +import kotlin.test.assertEquals import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.test.resetMain @@ -55,12 +61,6 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized -import java.io.File -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit -import kotlin.reflect.full.callSuspend -import kotlin.reflect.full.declaredFunctions -import kotlin.test.assertEquals @RunWith(Parameterized::class) class AWSCognitoAuthPluginFeatureTest(private val testCase: FeatureTestCase) { @@ -201,7 +201,7 @@ class AWSCognitoAuthPluginFeatureTest(private val testCase: FeatureTestCase) { assertEquals(getState(validation.expectedState), authState) getStateLatch.countDown() } - getStateLatch.await(10, TimeUnit.MINUTES) + getStateLatch.await(10, TimeUnit.SECONDS) } } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt index 207d65c45a..837dd9116e 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/JsonGenerator.kt @@ -61,6 +61,6 @@ object JsonGenerator { } fun main() { - //cleanDirectory() + // cleanDirectory() JsonGenerator.generate() } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt index 2d133704b0..85572dcbcb 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt @@ -28,13 +28,6 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions import com.amplifyframework.auth.result.AuthSessionResult import com.amplifyframework.statemachine.codegen.states.AuthState import com.google.gson.Gson -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonNull -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive import java.io.BufferedWriter import java.io.File import java.io.FileOutputStream @@ -42,6 +35,13 @@ import java.io.FileWriter import kotlin.reflect.KClass import kotlin.reflect.KVisibility import kotlin.reflect.full.declaredMemberProperties +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive const val basePath = "aws-auth-cognito/src/test/resources/feature-test" @@ -185,7 +185,7 @@ fun Any?.toJsonElement(): JsonElement { } } -fun AWSCognitoAuthSignInOptions.toJsonElement(): JsonElement{ +fun AWSCognitoAuthSignInOptions.toJsonElement(): JsonElement { val responseMap = mutableMapOf( "metadata" to metadata, "authFlowType" to authFlowType @@ -233,4 +233,4 @@ fun reflectionBasedSerializer(value: Any): JsonElement { }.associate { it.name to it.getter.call(value) }.toMap().toJsonElement() -} \ No newline at end of file +} diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt index b2d199d851..3a0d82b0d8 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt @@ -284,7 +284,10 @@ object SignInTestCaseGenerator : SerializableProvider { "username" to username, "password" to "", ).toJsonElement(), - options = mapOf("signInOptions" to mapOf("authFlow" to AuthFlowType.CUSTOM_AUTH_WITHOUT_SRP.toString())).toJsonElement() + options = mapOf( + "signInOptions" to + mapOf("authFlow" to AuthFlowType.CUSTOM_AUTH_WITHOUT_SRP.toString()) + ).toJsonElement() ), validations = listOf( mockedSignInCustomAuthChallengeExpectation, diff --git a/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt b/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt index d2ad50d084..0c386a6690 100644 --- a/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt +++ b/aws-auth-cognito/src/test/java/featureTest/utilities/AuthOptionsFactory.kt @@ -77,8 +77,10 @@ object AuthOptionsFactory { } as T private fun getSignInOptions(optionsData: JsonObject): AuthSignInOptions { - return if(optionsData.containsKey("signInOptions")) { - val authFlowType = AuthFlowType.valueOf(((optionsData["signInOptions"] as Map)["authFlow"] as JsonPrimitive).content) + return if (optionsData.containsKey("signInOptions")) { + val authFlowType = AuthFlowType.valueOf( + ((optionsData["signInOptions"] as Map)["authFlow"] as JsonPrimitive).content + ) AWSCognitoAuthSignInOptions.builder().authFlowType(authFlowType).build() } else { AuthSignInOptions.defaults() From 66c9515c6e364980836d8a52409ffa04f136d254 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 1 Dec 2022 12:41:59 -0600 Subject: [PATCH 4/7] Fix for phone number --- .../generators/authstategenerators/AuthStateJsonGenerator.kt | 2 +- .../generators/testcasegenerators/SignInTestCaseGenerator.kt | 2 +- .../resources/feature-test/states/SigningIn_SigningIn.json | 2 +- ...okes_proper_cognito_request_and_returns_SMS_challenge.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt index b6285d05c6..d9dce558d4 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt @@ -92,7 +92,7 @@ object AuthStateJsonGenerator : SerializableProvider { session = "someSession", parameters = mapOf( "CODE_DELIVERY_DELIVERY_MEDIUM" to "SMS", - "CODE_DELIVERY_DESTINATION" to "+12345678911" + "CODE_DELIVERY_DESTINATION" to "+12345678900" ) ) ) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt index 3a0d82b0d8..1ef909297e 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt @@ -34,7 +34,7 @@ object SignInTestCaseGenerator : SerializableProvider { private const val userId = "userId" private const val username = "username" private const val password = "password" - private const val phone = "+12345678911" + private const val phone = "+12345678900" private val mockedInitiateAuthResponse = MockResponse( CognitoType.CognitoIdentityProvider, diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json index f971a4c939..dace0d38ce 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json @@ -12,7 +12,7 @@ "session": "someSession", "parameters": { "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", - "CODE_DELIVERY_DESTINATION": "+12345678911" + "CODE_DELIVERY_DESTINATION": "+12345678900" } } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json index 3dc784bfdb..5cc1ab4d0a 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json @@ -28,7 +28,7 @@ "challengeName": "SMS_MFA", "challengeParameters": { "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", - "CODE_DELIVERY_DESTINATION": "+12345678911" + "CODE_DELIVERY_DESTINATION": "+12345678900" } } } @@ -55,7 +55,7 @@ "additionalInfo": { }, "codeDeliveryDetails": { - "destination": "+12345678911", + "destination": "+12345678900", "deliveryMedium": "SMS" } } From 2888238c9d1b90dc133184ac7ca3c16aa58d28fd Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 1 Dec 2022 12:44:25 -0600 Subject: [PATCH 5/7] Recreate all tests --- ...kes_proper_cognito_request_and_returns_custom_challenge.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json index d987c78b29..c3f1b04a42 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json @@ -64,7 +64,7 @@ }, { "type": "state", - "expectedState": "CustomSignin_SigningIn.json" + "expectedState": "CustomSignIn_SigningIn.json" } ] } \ No newline at end of file From c695613d920cb1793c7b4cf99935a640f1efd1f8 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 5 Dec 2022 10:14:27 -0600 Subject: [PATCH 6/7] Removed un-ncessary serializer --- .../generators/SerializationTools.kt | 23 ++--- ..._request_and_returns_custom_challenge.json | 70 ------------- ...r_cognito_request_and_returns_success.json | 97 ------------------- ...ito_request_and_returns_SMS_challenge.json | 69 ------------- ...r_cognito_request_and_returns_success.json | 86 ---------------- 5 files changed, 7 insertions(+), 338 deletions(-) delete mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json delete mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Device_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json delete mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json delete mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt index 85572dcbcb..d9d9574e2d 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt @@ -28,13 +28,6 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions import com.amplifyframework.auth.result.AuthSessionResult import com.amplifyframework.statemachine.codegen.states.AuthState import com.google.gson.Gson -import java.io.BufferedWriter -import java.io.File -import java.io.FileOutputStream -import java.io.FileWriter -import kotlin.reflect.KClass -import kotlin.reflect.KVisibility -import kotlin.reflect.full.declaredMemberProperties import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray @@ -42,6 +35,13 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonNull import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive +import java.io.BufferedWriter +import java.io.File +import java.io.FileOutputStream +import java.io.FileWriter +import kotlin.reflect.KClass +import kotlin.reflect.KVisibility +import kotlin.reflect.full.declaredMemberProperties const val basePath = "aws-auth-cognito/src/test/resources/feature-test" @@ -185,15 +185,6 @@ fun Any?.toJsonElement(): JsonElement { } } -fun AWSCognitoAuthSignInOptions.toJsonElement(): JsonElement { - val responseMap = mutableMapOf( - "metadata" to metadata, - "authFlowType" to authFlowType - ) - - return responseMap.toJsonElement() -} - fun AuthException.toJsonElement(): JsonElement { val responseMap = mutableMapOf( "errorType" to this::class.simpleName, diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json deleted file mode 100644 index c3f1b04a42..0000000000 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_custom_challenge.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "description": "Test that Custom Auth signIn invokes proper cognito request and returns custom challenge", - "preConditions": { - "amplify-configuration": "authconfiguration.json", - "state": "SignedOut_Configured.json", - "mockedResponses": [ - { - "type": "cognitoIdentityProvider", - "apiName": "initiateAuth", - "responseType": "success", - "response": { - "challengeName": "CUSTOM_CHALLENGE", - "challengeParameters": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "SRP_B": "def", - "USERNAME": "username" - } - } - }, - { - "type": "cognitoIdentityProvider", - "apiName": "respondToAuthChallenge", - "responseType": "success", - "response": { - "session": "someSession", - "challengeName": "CUSTOM_CHALLENGE", - "challengeParameters": { - "Code": "1234" - } - } - } - ] - }, - "api": { - "name": "signIn", - "params": { - "username": "username", - "password": "" - }, - "options": { - "signInOptions": { - "authFlow": "CUSTOM_AUTH_WITHOUT_SRP" - } - } - }, - "validations": [ - { - "type": "amplify", - "apiName": "signIn", - "responseType": "success", - "response": { - "isSignedIn": false, - "nextStep": { - "signInStep": "CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE", - "additionalInfo": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "USERNAME": "username", - "SRP_B": "def" - } - } - } - }, - { - "type": "state", - "expectedState": "CustomSignIn_SigningIn.json" - } - ] -} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Device_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Device_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json deleted file mode 100644 index 6631e63727..0000000000 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Device_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json +++ /dev/null @@ -1,97 +0,0 @@ -{ - "description": "Test that Device SRP signIn invokes proper cognito request and returns success", - "preConditions": { - "amplify-configuration": "authconfiguration.json", - "state": "SignedOut_Configured.json", - "mockedResponses": [ - { - "type": "cognitoIdentityProvider", - "apiName": "initiateAuth", - "responseType": "success", - "response": { - "challengeName": "PASSWORD_VERIFIER", - "challengeParameters": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "SRP_B": "def", - "USERNAME": "username", - "USER_ID_FOR_SRP": "userId" - } - } - }, - { - "type": "cognitoIdentityProvider", - "apiName": "respondToAuthChallenge", - "responseType": "success", - "response": { - "authenticationResult": { - "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "expiresIn": 300, - "newDeviceMetadata": { - "deviceKey": "someDeviceKey", - "deviceGroupKey": "someDeviceGroupKey" - } - } - } - }, - { - "type": "cognitoIdentityProvider", - "apiName": "confirmDevice", - "responseType": "success", - "response": { - } - }, - { - "type": "cognitoIdentity", - "apiName": "getId", - "responseType": "success", - "response": { - "identityId": "someIdentityId" - } - }, - { - "type": "cognitoIdentity", - "apiName": "getCredentialsForIdentity", - "responseType": "success", - "response": { - "credentials": { - "accessKeyId": "someAccessKey", - "secretKey": "someSecretKey", - "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "expiration": 2342134 - } - } - } - ] - }, - "api": { - "name": "signIn", - "params": { - "username": "username", - "password": "password" - }, - "options": { - } - }, - "validations": [ - { - "type": "amplify", - "apiName": "signIn", - "responseType": "success", - "response": { - "isSignedIn": true, - "nextStep": { - "signInStep": "DONE", - "additionalInfo": { - } - } - } - }, - { - "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" - } - ] -} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json deleted file mode 100644 index 5cc1ab4d0a..0000000000 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "description": "Test that SRP signIn invokes proper cognito request and returns SMS challenge", - "preConditions": { - "amplify-configuration": "authconfiguration.json", - "state": "SignedOut_Configured.json", - "mockedResponses": [ - { - "type": "cognitoIdentityProvider", - "apiName": "initiateAuth", - "responseType": "success", - "response": { - "challengeName": "PASSWORD_VERIFIER", - "challengeParameters": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "SRP_B": "def", - "USERNAME": "username", - "USER_ID_FOR_SRP": "userId" - } - } - }, - { - "type": "cognitoIdentityProvider", - "apiName": "respondToAuthChallenge", - "responseType": "success", - "response": { - "session": "someSession", - "challengeName": "SMS_MFA", - "challengeParameters": { - "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", - "CODE_DELIVERY_DESTINATION": "+12345678900" - } - } - } - ] - }, - "api": { - "name": "signIn", - "params": { - "username": "username", - "password": "password" - }, - "options": { - } - }, - "validations": [ - { - "type": "amplify", - "apiName": "signIn", - "responseType": "success", - "response": { - "isSignedIn": false, - "nextStep": { - "signInStep": "CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE", - "additionalInfo": { - }, - "codeDeliveryDetails": { - "destination": "+12345678900", - "deliveryMedium": "SMS" - } - } - } - }, - { - "type": "state", - "expectedState": "SigningIn_SigningIn.json" - } - ] -} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json deleted file mode 100644 index 364b080df8..0000000000 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "description": "Test that SRP signIn invokes proper cognito request and returns success", - "preConditions": { - "amplify-configuration": "authconfiguration.json", - "state": "SignedOut_Configured.json", - "mockedResponses": [ - { - "type": "cognitoIdentityProvider", - "apiName": "initiateAuth", - "responseType": "success", - "response": { - "challengeName": "PASSWORD_VERIFIER", - "challengeParameters": { - "SALT": "abc", - "SECRET_BLOCK": "secretBlock", - "SRP_B": "def", - "USERNAME": "username", - "USER_ID_FOR_SRP": "userId" - } - } - }, - { - "type": "cognitoIdentityProvider", - "apiName": "respondToAuthChallenge", - "responseType": "success", - "response": { - "authenticationResult": { - "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "expiresIn": 300 - } - } - }, - { - "type": "cognitoIdentity", - "apiName": "getId", - "responseType": "success", - "response": { - "identityId": "someIdentityId" - } - }, - { - "type": "cognitoIdentity", - "apiName": "getCredentialsForIdentity", - "responseType": "success", - "response": { - "credentials": { - "accessKeyId": "someAccessKey", - "secretKey": "someSecretKey", - "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", - "expiration": 2342134 - } - } - } - ] - }, - "api": { - "name": "signIn", - "params": { - "username": "username", - "password": "password" - }, - "options": { - } - }, - "validations": [ - { - "type": "amplify", - "apiName": "signIn", - "responseType": "success", - "response": { - "isSignedIn": true, - "nextStep": { - "signInStep": "DONE", - "additionalInfo": { - } - } - } - }, - { - "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" - } - ] -} \ No newline at end of file From df12b0925e05d03da793a8283dbefd6a99c0e420 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 5 Dec 2022 10:15:34 -0600 Subject: [PATCH 7/7] reverted imports --- .../featuretest/generators/SerializationTools.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt index d9d9574e2d..0b2c34d7fb 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt @@ -28,13 +28,6 @@ import com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignInOptions import com.amplifyframework.auth.result.AuthSessionResult import com.amplifyframework.statemachine.codegen.states.AuthState import com.google.gson.Gson -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.JsonNull -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive import java.io.BufferedWriter import java.io.File import java.io.FileOutputStream @@ -42,6 +35,13 @@ import java.io.FileWriter import kotlin.reflect.KClass import kotlin.reflect.KVisibility import kotlin.reflect.full.declaredMemberProperties +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonNull +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive const val basePath = "aws-auth-cognito/src/test/resources/feature-test"