Skip to content

Commit

Permalink
Merge branch 'main' into fix-loadcredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanshu committed Dec 16, 2022
2 parents 780b16b + 1f210b7 commit 26097a9
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 7 deletions.
Original file line number Diff line number Diff line change
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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"authChallenge": {
"challengeName": "CUSTOM_CHALLENGE",
"username": "username",
"session": null,
"session": "someSession",
"parameters": {
"SALT": "abc",
"SECRET_BLOCK": "secretBlock",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit 26097a9

Please sign in to comment.