From 5b7e9695613bb1c56b3fdff8410be8534353bea7 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 8 Dec 2022 11:30:25 -0600 Subject: [PATCH 1/2] Added the test case for custom auth with SRP --- .../SignInTestCaseGenerator.kt | 42 ++++++-- .../states/CustomSignIn_SigningIn.json | 2 +- ..._request_and_returns_custom_challenge.json | 73 ++++++++++++++ ...equest_and_returns_password_challenge.json | 74 ++++++++++++++ ...r_cognito_request_and_returns_success.json | 97 +++++++++++++++++++ ...ito_request_and_returns_SMS_challenge.json | 69 +++++++++++++ ...r_cognito_request_and_returns_success.json | 86 ++++++++++++++++ 7 files changed, 436 insertions(+), 7 deletions(-) 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 create mode 100644 aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json create 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 create 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 create 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/testcasegenerators/SignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt index 1ef909297e..8bbabe82a0 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 @@ -113,7 +113,7 @@ object SignInTestCaseGenerator : SerializableProvider { ).toJsonElement() ) - private val mockedCustomChallengeResponse = MockResponse( + private val mockedRespondToAuthCustomChallengeResponse = MockResponse( CognitoType.CognitoIdentityProvider, "respondToAuthChallenge", ResponseType.Success, @@ -121,7 +121,10 @@ object SignInTestCaseGenerator : SerializableProvider { "session" to "someSession", "challengeName" to "CUSTOM_CHALLENGE", "challengeParameters" to mapOf( - "Code" to "1234" + "SALT" to "abc", + "SECRET_BLOCK" to "secretBlock", + "SRP_B" to "def", + "USERNAME" to username ) ).toJsonElement() ) @@ -185,8 +188,8 @@ object SignInTestCaseGenerator : SerializableProvider { "additionalInfo" to mapOf( "SALT" to "abc", "SECRET_BLOCK" to "secretBlock", - "USERNAME" to "username", - "SRP_B" to "def" + "SRP_B" to "def", + "USERNAME" to username ) ) ).toJsonElement() @@ -275,7 +278,7 @@ object SignInTestCaseGenerator : SerializableProvider { "SignedOut_Configured.json", mockedResponses = listOf( mockedInitiateAuthForCustomAuthWithoutSRPResponse, - mockedCustomChallengeResponse + mockedRespondToAuthCustomChallengeResponse ) ), api = API( @@ -295,5 +298,32 @@ object SignInTestCaseGenerator : SerializableProvider { ) ) - override val serializables: List = listOf(baseCase, challengeCase, deviceSRPTestCase, customAuthCase) + private val customAuthWithSRPCase = FeatureTestCase( + description = "Test that Custom Auth signIn invokes proper cognito request and returns password challenge", + preConditions = PreConditions( + "authconfiguration.json", + "SignedOut_Configured.json", + mockedResponses = listOf( + mockedInitiateAuthResponse, + mockedRespondToAuthCustomChallengeResponse + ) + ), + api = API( + AuthAPI.signIn, + params = mapOf( + "username" to username, + "password" to "", + ).toJsonElement(), + options = mapOf( + "signInOptions" to + mapOf("authFlow" to AuthFlowType.CUSTOM_AUTH_WITH_SRP.toString()) + ).toJsonElement() + ), + validations = listOf( + mockedSignInCustomAuthChallengeExpectation, + ExpectationShapes.State("CustomSignIn_SigningIn.json") + ) + ) + + override val serializables: List = listOf(baseCase, challengeCase, deviceSRPTestCase, customAuthCase, customAuthWithSRPCase) } 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 index e69e8f6662..5ccb17e359 100644 --- 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 @@ -9,7 +9,7 @@ "authChallenge": { "challengeName": "CUSTOM_CHALLENGE", "username": "username", - "session": null, + "session": "someSession", "parameters": { "SALT": "abc", "SECRET_BLOCK": "secretBlock", 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..22049673b4 --- /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,73 @@ +{ + "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": { + "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", + "SRP_B": "def", + "USERNAME": "username" + } + } + } + }, + { + "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_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json new file mode 100644 index 0000000000..36e642f1f5 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json @@ -0,0 +1,74 @@ +{ + "description": "Test that Custom Auth signIn invokes proper cognito request and returns password 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": "CUSTOM_CHALLENGE", + "challengeParameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "username" + } + } + } + ] + }, + "api": { + "name": "signIn", + "params": { + "username": "username", + "password": "" + }, + "options": { + "signInOptions": { + "authFlow": "CUSTOM_AUTH_WITH_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", + "SRP_B": "def", + "USERNAME": "username" + } + } + } + }, + { + "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 new file mode 100644 index 0000000000..6631e63727 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Device_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json @@ -0,0 +1,97 @@ +{ + "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 new file mode 100644 index 0000000000..5cc1ab4d0a --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_SMS_challenge.json @@ -0,0 +1,69 @@ +{ + "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 new file mode 100644 index 0000000000..364b080df8 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_SRP_signIn_invokes_proper_cognito_request_and_returns_success.json @@ -0,0 +1,86 @@ +{ + "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 484b3e557c1a5857185ccf535bbec9469cb0225a Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 15 Dec 2022 12:22:08 -0600 Subject: [PATCH 2/2] ktlint --- .../testcasegenerators/SignInTestCaseGenerator.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 8bbabe82a0..a5eb5b284c 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 @@ -315,8 +315,7 @@ object SignInTestCaseGenerator : SerializableProvider { "password" to "", ).toJsonElement(), options = mapOf( - "signInOptions" to - mapOf("authFlow" to AuthFlowType.CUSTOM_AUTH_WITH_SRP.toString()) + "signInOptions" to mapOf("authFlow" to AuthFlowType.CUSTOM_AUTH_WITH_SRP.toString()) ).toJsonElement() ), validations = listOf( @@ -325,5 +324,7 @@ object SignInTestCaseGenerator : SerializableProvider { ) ) - override val serializables: List = listOf(baseCase, challengeCase, deviceSRPTestCase, customAuthCase, customAuthWithSRPCase) + override val serializables: List = listOf( + baseCase, challengeCase, deviceSRPTestCase, customAuthCase, customAuthWithSRPCase + ) }