Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore(Auth): Implementation of the custom auth with SRP parity testing use case #2167

Merged
merged 3 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -113,15 +113,18 @@ object SignInTestCaseGenerator : SerializableProvider {
).toJsonElement()
)

private val mockedCustomChallengeResponse = MockResponse(
private val mockedRespondToAuthCustomChallengeResponse = MockResponse(
CognitoType.CognitoIdentityProvider,
"respondToAuthChallenge",
ResponseType.Success,
mapOf(
"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()
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -275,7 +278,7 @@ object SignInTestCaseGenerator : SerializableProvider {
"SignedOut_Configured.json",
mockedResponses = listOf(
mockedInitiateAuthForCustomAuthWithoutSRPResponse,
mockedCustomChallengeResponse
mockedRespondToAuthCustomChallengeResponse
)
),
api = API(
Expand All @@ -295,5 +298,33 @@ object SignInTestCaseGenerator : SerializableProvider {
)
)

override val serializables: List<Any> = 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<Any> = listOf(
baseCase, challengeCase, deviceSRPTestCase, customAuthCase, customAuthWithSRPCase
)
}
Expand Up @@ -9,7 +9,7 @@
"authChallenge": {
"challengeName": "CUSTOM_CHALLENGE",
"username": "username",
"session": null,
"session": "someSession",
"parameters": {
"SALT": "abc",
"SECRET_BLOCK": "secretBlock",
Expand Down
@@ -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"
}
]
}
@@ -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"
}
]
}
@@ -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"
}
]
}