Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,33 @@ internal class RealAWSCognitoAuthPlugin(
)
}

val authSignUpResult = AuthSignUpResult(
false,
AuthNextSignUpStep(
AuthSignUpStep.CONFIRM_SIGN_UP_STEP,
mapOf(),
AuthCodeDeliveryDetails(
deliveryDetails?.getValue("DESTINATION") ?: "",
AuthCodeDeliveryDetails.DeliveryMedium.fromString(
deliveryDetails?.getValue("MEDIUM")
),
deliveryDetails?.getValue("ATTRIBUTE")
)
),
response?.userSub
)
val authSignUpResult = if (response?.userConfirmed == true) {
AuthSignUpResult(
true,
AuthNextSignUpStep(
AuthSignUpStep.DONE,
mapOf(),
null
),
response.userSub
)
} else {
AuthSignUpResult(
false,
AuthNextSignUpStep(
AuthSignUpStep.CONFIRM_SIGN_UP_STEP,
mapOf(),
AuthCodeDeliveryDetails(
deliveryDetails?.getValue("DESTINATION") ?: "",
AuthCodeDeliveryDetails.DeliveryMedium.fromString(
deliveryDetails?.getValue("MEDIUM")
),
deliveryDetails?.getValue("ATTRIBUTE")
)
),
response?.userSub
)
}
onSuccess.accept(authSignUpResult)
logger.verbose("SignUp Execution complete")
} catch (exception: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ object SignUpTestCaseGenerator : SerializableProvider {
"attributeName" to "attributeName"
)

private val emptyCodeDeliveryDetails = mapOf(
"destination" to "",
"deliveryMedium" to "",
"attributeName" to ""
)

val baseCase = FeatureTestCase(
description = "Test that signup invokes proper cognito request and returns success",
preConditions = PreConditions(
Expand Down Expand Up @@ -98,5 +104,45 @@ object SignUpTestCaseGenerator : SerializableProvider {
)
)

override val serializables: List<Any> = listOf(baseCase)
val signupSuccessCase = baseCase.copy(
description = "Sign up finishes if user is confirmed in the first step",
preConditions = baseCase.preConditions.copy(
mockedResponses = listOf(
MockResponse(
CognitoType.CognitoIdentityProvider,
"signUp",
ResponseType.Success,
mapOf("codeDeliveryDetails" to emptyCodeDeliveryDetails, "userConfirmed" to true).toJsonElement()
)
)
),
validations = listOf(
ExpectationShapes.Cognito.CognitoIdentityProvider(
apiName = "signUp",
// see [https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SignUp.html]
request = mapOf(
"clientId" to "testAppClientId", // This should be pulled from configuration
"username" to username,
"password" to password,
"userAttributes" to listOf(mapOf("name" to "email", "value" to email))
).toJsonElement()
),
ExpectationShapes.Amplify(
apiName = AuthAPI.signUp,
responseType = ResponseType.Success,
response =
AuthSignUpResult(
true,
AuthNextSignUpStep(
AuthSignUpStep.DONE,
emptyMap(),
null
),
null
).toJsonElement()
)
)
)

override val serializables: List<Any> = listOf(baseCase, signupSuccessCase)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import io.mockk.coEvery
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.boolean

/**
* Factory to mock aws sdk's cognito API calls and responses.
Expand All @@ -67,6 +68,9 @@ class CognitoMockFactory(
setupError(mockResponse, responseObject)
SignUpResponse.invoke {
this.codeDeliveryDetails = parseCodeDeliveryDetails(responseObject)
this.userConfirmed = if (responseObject.containsKey("userConfirmed")) {
(responseObject["userConfirmed"] as? JsonPrimitive)?.boolean ?: false
} else false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"description": "AuthSession object is successfully returned for UserAndIdentity Pool",
"preConditions": {
"amplify-configuration": "authconfiguration.json",
"state": "SignedIn_SessionEstablished.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": true,
"userPoolTokensResult": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU",
"idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU"
},
"userSubResult": "userId"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"description": "Sign up finishes if user is confirmed in the first step",
"preConditions": {
"amplify-configuration": "authconfiguration.json",
"state": "SignedOut_Configured.json",
"mockedResponses": [
{
"type": "cognitoIdentityProvider",
"apiName": "signUp",
"responseType": "success",
"response": {
"codeDeliveryDetails": {
"destination": "",
"deliveryMedium": "",
"attributeName": ""
},
"userConfirmed": true
}
}
]
},
"api": {
"name": "signUp",
"params": {
"username": "user",
"password": "password"
},
"options": {
"userAttributes": {
"email": "[email protected]"
}
}
},
"validations": [
{
"type": "cognitoIdentityProvider",
"apiName": "signUp",
"request": {
"clientId": "testAppClientId",
"username": "user",
"password": "password",
"userAttributes": [
{
"name": "email",
"value": "[email protected]"
}
]
}
},
{
"type": "amplify",
"apiName": "signUp",
"responseType": "success",
"response": {
"isSignUpComplete": true,
"nextStep": {
"signUpStep": "DONE",
"additionalInfo": {
}
}
}
}
]
}