-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): Added parity test for fetchDevices,rememberDevice,forgetD…
…evice and fetchUserAttributes (#2174) Co-authored-by: Sunil Timalsina <sunil.timalsina@gmail.com> Co-authored-by: Banji Jolaoso <banjij@amazon.com> Co-authored-by: Divyesh Chitroda <div5yesh@gmail.com> Co-authored-by: Matt Creaser <mattwcc@amazon.com> Co-authored-by: Saijad Dhuka <83975678+sdhuka@users.noreply.github.com> Co-authored-by: Tyler Roach <tjroach@amazon.com> Co-authored-by: Thomas Leing <bluezebragames@gmail.com> Co-authored-by: Thomas Leing <leint@amazon.com> Co-authored-by: gpanshu <91897496+gpanshu@users.noreply.github.com> Co-authored-by: AWS Mobile SDK Bot <46607340+awsmobilesdk@users.noreply.github.com>
- Loading branch information
1 parent
c467c4d
commit 9e368fe
Showing
20 changed files
with
984 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...th/cognito/featuretest/generators/testcasegenerators/FetchAuthSessionTestCaseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...k/auth/cognito/featuretest/generators/testcasegenerators/FetchDevicesTestCaseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.auth.cognito.featuretest.generators.testcasegenerators | ||
|
||
import aws.sdk.kotlin.services.cognitoidentityprovider.model.AttributeType | ||
import aws.sdk.kotlin.services.cognitoidentityprovider.model.DeviceType | ||
import aws.smithy.kotlin.runtime.time.Instant | ||
import com.amplifyframework.auth.AuthDevice | ||
import com.amplifyframework.auth.cognito.featuretest.API | ||
import com.amplifyframework.auth.cognito.featuretest.AuthAPI | ||
import com.amplifyframework.auth.cognito.featuretest.CognitoType | ||
import com.amplifyframework.auth.cognito.featuretest.ExpectationShapes | ||
import com.amplifyframework.auth.cognito.featuretest.FeatureTestCase | ||
import com.amplifyframework.auth.cognito.featuretest.MockResponse | ||
import com.amplifyframework.auth.cognito.featuretest.PreConditions | ||
import com.amplifyframework.auth.cognito.featuretest.ResponseType | ||
import com.amplifyframework.auth.cognito.featuretest.generators.SerializableProvider | ||
import com.amplifyframework.auth.cognito.featuretest.generators.toJsonElement | ||
import com.amplifyframework.auth.exceptions.SignedOutException | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
object FetchDevicesTestCaseGenerator : SerializableProvider { | ||
|
||
private val expectedSuccess = listOf<AuthDevice>(AuthDevice.fromId("deviceKey")).toJsonElement() | ||
|
||
private val mockCognitoResponse = MockResponse( | ||
CognitoType.CognitoIdentityProvider, | ||
"listDevices", | ||
ResponseType.Success, | ||
mapOf( | ||
"devices" to listOf<DeviceType>( | ||
DeviceType.invoke { | ||
deviceAttributes = listOf<AttributeType>( | ||
AttributeType.invoke { | ||
name = "name" | ||
value = "value" | ||
} | ||
) | ||
deviceKey = "deviceKey" | ||
deviceCreateDate = Instant.now() | ||
deviceLastAuthenticatedDate = Instant.now() | ||
deviceLastModifiedDate = Instant.now() | ||
} | ||
) | ||
).toJsonElement() | ||
) | ||
|
||
private val apiReturnValidation = ExpectationShapes.Amplify( | ||
AuthAPI.fetchDevices, | ||
ResponseType.Success, | ||
expectedSuccess, | ||
) | ||
|
||
private val baseCase = FeatureTestCase( | ||
description = "Test that Cognito is called with given payload and returns successful data", | ||
preConditions = PreConditions( | ||
"authconfiguration.json", | ||
"SignedIn_SessionEstablished.json", | ||
mockedResponses = listOf(mockCognitoResponse) | ||
), | ||
api = API( | ||
AuthAPI.fetchDevices, | ||
JsonObject(emptyMap()), | ||
JsonObject(emptyMap()), | ||
), | ||
validations = listOf(apiReturnValidation) | ||
) | ||
|
||
private val successCase: FeatureTestCase = baseCase.copy( | ||
description = "List of devices returned when fetch devices API succeeds", | ||
preConditions = baseCase.preConditions.copy(mockedResponses = listOf(mockCognitoResponse)), | ||
validations = baseCase.validations.plus(apiReturnValidation) | ||
) | ||
|
||
private val errorCase: FeatureTestCase | ||
get() { | ||
val errorResponse = SignedOutException() | ||
return baseCase.copy( | ||
description = "AuthException is thrown when forgetDevice API is called without signing in", | ||
preConditions = baseCase.preConditions.copy( | ||
state = "SignedOut_Configured.json", | ||
mockedResponses = listOf( | ||
MockResponse( | ||
CognitoType.CognitoIdentityProvider, | ||
"forgetDevice", | ||
ResponseType.Failure, | ||
errorResponse.toJsonElement() | ||
) | ||
) | ||
), | ||
validations = listOf( | ||
ExpectationShapes.Amplify( | ||
AuthAPI.forgetDevice, | ||
ResponseType.Failure, | ||
com.amplifyframework.auth.exceptions.SignedOutException().toJsonElement(), | ||
) | ||
) | ||
) | ||
} | ||
|
||
override val serializables: List<Any> = listOf(baseCase, errorCase, successCase) | ||
} |
112 changes: 112 additions & 0 deletions
112
...cognito/featuretest/generators/testcasegenerators/FetchUserAttributesTestCaseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.auth.cognito.featuretest.generators.testcasegenerators | ||
import aws.sdk.kotlin.services.cognitoidentityprovider.model.AttributeType | ||
import com.amplifyframework.auth.AuthUserAttribute | ||
import com.amplifyframework.auth.AuthUserAttributeKey | ||
import com.amplifyframework.auth.cognito.featuretest.API | ||
import com.amplifyframework.auth.cognito.featuretest.AuthAPI | ||
import com.amplifyframework.auth.cognito.featuretest.CognitoType | ||
import com.amplifyframework.auth.cognito.featuretest.ExpectationShapes | ||
import com.amplifyframework.auth.cognito.featuretest.FeatureTestCase | ||
import com.amplifyframework.auth.cognito.featuretest.MockResponse | ||
import com.amplifyframework.auth.cognito.featuretest.PreConditions | ||
import com.amplifyframework.auth.cognito.featuretest.ResponseType | ||
import com.amplifyframework.auth.cognito.featuretest.generators.SerializableProvider | ||
import com.amplifyframework.auth.cognito.featuretest.generators.toJsonElement | ||
import com.amplifyframework.auth.exceptions.SignedOutException | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
object FetchUserAttributesTestCaseGenerator : SerializableProvider { | ||
|
||
private val expectedSuccess = listOf<AuthUserAttribute>( | ||
AuthUserAttribute(AuthUserAttributeKey.email(), "email@email.com"), | ||
AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "000-000-0000") | ||
).toJsonElement() | ||
|
||
private val mockCognitoResponse = MockResponse( | ||
CognitoType.CognitoIdentityProvider, | ||
"getUser", | ||
ResponseType.Success, | ||
mapOf( | ||
"userAttributes" to listOf<AttributeType>( | ||
AttributeType.invoke { | ||
name = "email" | ||
value = "email@email.com" | ||
}, | ||
AttributeType.invoke { | ||
name = "phone" | ||
value = "000-000-0000" | ||
} | ||
) | ||
).toJsonElement() | ||
) | ||
|
||
private val apiReturnValidation = ExpectationShapes.Amplify( | ||
AuthAPI.fetchUserAttributes, | ||
ResponseType.Success, | ||
expectedSuccess, | ||
) | ||
|
||
private val baseCase = FeatureTestCase( | ||
description = "Test that Cognito is called with given payload and returns successful data", | ||
preConditions = PreConditions( | ||
"authconfiguration.json", | ||
"SignedIn_SessionEstablished.json", | ||
mockedResponses = listOf(mockCognitoResponse) | ||
), | ||
api = API( | ||
AuthAPI.fetchUserAttributes, | ||
JsonObject(emptyMap()), | ||
JsonObject(emptyMap()), | ||
), | ||
validations = listOf(apiReturnValidation) | ||
) | ||
|
||
private val successCase: FeatureTestCase = baseCase.copy( | ||
description = "List of user attributes returned when fetch user attributes API succeeds", | ||
preConditions = baseCase.preConditions.copy(mockedResponses = listOf(mockCognitoResponse)), | ||
validations = baseCase.validations.plus(apiReturnValidation) | ||
) | ||
|
||
private val errorCase: FeatureTestCase | ||
get() { | ||
val errorResponse = SignedOutException() | ||
return baseCase.copy( | ||
description = "AuthException is thrown when fetchUserAttributes API is called without signing in", | ||
preConditions = baseCase.preConditions.copy( | ||
state = "SignedOut_Configured.json", | ||
mockedResponses = listOf( | ||
MockResponse( | ||
CognitoType.CognitoIdentityProvider, | ||
"getUser", | ||
ResponseType.Failure, | ||
errorResponse.toJsonElement() | ||
) | ||
) | ||
), | ||
validations = listOf( | ||
ExpectationShapes.Amplify( | ||
AuthAPI.fetchUserAttributes, | ||
ResponseType.Failure, | ||
SignedOutException().toJsonElement(), | ||
) | ||
) | ||
) | ||
} | ||
|
||
override val serializables: List<Any> = listOf(baseCase, errorCase, successCase) | ||
} |
96 changes: 96 additions & 0 deletions
96
...k/auth/cognito/featuretest/generators/testcasegenerators/ForgetDeviceTestCaseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.auth.cognito.featuretest.generators.testcasegenerators | ||
|
||
import com.amplifyframework.auth.AuthDevice | ||
import com.amplifyframework.auth.cognito.featuretest.API | ||
import com.amplifyframework.auth.cognito.featuretest.AuthAPI | ||
import com.amplifyframework.auth.cognito.featuretest.CognitoType | ||
import com.amplifyframework.auth.cognito.featuretest.ExpectationShapes | ||
import com.amplifyframework.auth.cognito.featuretest.FeatureTestCase | ||
import com.amplifyframework.auth.cognito.featuretest.MockResponse | ||
import com.amplifyframework.auth.cognito.featuretest.PreConditions | ||
import com.amplifyframework.auth.cognito.featuretest.ResponseType | ||
import com.amplifyframework.auth.cognito.featuretest.generators.SerializableProvider | ||
import com.amplifyframework.auth.cognito.featuretest.generators.toJsonElement | ||
import com.amplifyframework.auth.exceptions.SignedOutException | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
object ForgetDeviceTestCaseGenerator : SerializableProvider { | ||
private val mockCognitoResponse = MockResponse( | ||
CognitoType.CognitoIdentityProvider, | ||
"updateDeviceStatus", | ||
ResponseType.Success, | ||
JsonObject(emptyMap()) | ||
) | ||
|
||
private val apiReturnValidation = ExpectationShapes.Amplify( | ||
AuthAPI.forgetDevice, | ||
ResponseType.Success, | ||
JsonObject(emptyMap()), | ||
) | ||
|
||
private val baseCase = FeatureTestCase( | ||
description = "Test that Cognito is called with given payload and returns successful data", | ||
preConditions = PreConditions( | ||
"authconfiguration.json", | ||
"SignedIn_SessionEstablished.json", | ||
mockedResponses = listOf(mockCognitoResponse) | ||
), | ||
api = API( | ||
AuthAPI.forgetDevice, | ||
mapOf( | ||
"device" to AuthDevice.fromId("id", "test") | ||
).toJsonElement(), | ||
JsonObject(emptyMap()), | ||
), | ||
validations = listOf(apiReturnValidation) | ||
) | ||
|
||
private val successCase: FeatureTestCase = baseCase.copy( | ||
description = "Nothing is returned when forget device succeeds", | ||
preConditions = baseCase.preConditions.copy(mockedResponses = listOf(mockCognitoResponse)), | ||
validations = baseCase.validations.plus(apiReturnValidation) | ||
) | ||
|
||
private val errorCase: FeatureTestCase | ||
get() { | ||
val errorResponse = SignedOutException() | ||
return baseCase.copy( | ||
description = "AuthException is thrown when forgetDevice API is called without signing in", | ||
preConditions = baseCase.preConditions.copy( | ||
state = "SignedOut_Configured.json", | ||
mockedResponses = listOf( | ||
MockResponse( | ||
CognitoType.CognitoIdentityProvider, | ||
"forgetDevice", | ||
ResponseType.Failure, | ||
errorResponse.toJsonElement() | ||
) | ||
) | ||
), | ||
validations = listOf( | ||
ExpectationShapes.Amplify( | ||
AuthAPI.forgetDevice, | ||
ResponseType.Failure, | ||
SignedOutException().toJsonElement(), | ||
) | ||
) | ||
) | ||
} | ||
|
||
override val serializables: List<Any> = listOf(baseCase, errorCase, successCase) | ||
} |
15 changes: 15 additions & 0 deletions
15
...auth/cognito/featuretest/generators/testcasegenerators/GetCurrentUserTestCaseGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.