-
Notifications
You must be signed in to change notification settings - Fork 126
feat(auth): Added parity test for fetchDevices,rememberDevice,forgetDevice and fetchUserAttributes #2174
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
Merged
Merged
feat(auth): Added parity test for fetchDevices,rememberDevice,forgetDevice and fetchUserAttributes #2174
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
f316f03
refactor feature testing fw
sktimalsina 2831773
documentation and move verify to test
sktimalsina aeaf9b2
added fetchAuthSession test case generator
0a8911e
add new default serializer and fix options
sktimalsina 6401b4f
fix serializer for AuthSessionResult and success test case
sktimalsina b339cd3
add generated test case
sktimalsina 1f5040e
Merge branch 'dev-preview' into feature/banji/test-case-generator
sktimalsina c9537ff
added fetchAuthSession test case generator
ef1474c
Merge remote-tracking branch 'origin/dev-preview' into feature/banji/…
6b68575
Merge branch 'dev-preview' into feature/banji/test-case-generator
sktimalsina 10cc6e1
Merge branch 'dev-preview' into feature/banji/test-case-generator
div5yesh f1791cf
added fetchAuthSession test case generator for different auth flow types
2d6586a
Merge remote-tracking branch 'origin/feature/banji/test-case-generato…
26305a2
Merge branch 'dev-preview' into feature/banji/test-case-generator
banji180 03d2d0b
added fetchAuthSession test case generator for different auth flow types
429ac40
Merge remote-tracking branch 'origin/feature/banji/test-case-generato…
d083490
Merge remote-tracking branch 'origin/dev-preview' into feature/banji/…
80d2e33
Merge branch 'main' into feature/banji/test-case-generator
sktimalsina ebddbd4
added GetCurrentUserTestCaseGenerator
a083f50
Merge branch 'main' into feature/banji/test-case-generator
div5yesh e31feda
added GetCurrentUserTestCaseGenerator
11b3b54
Merge remote-tracking branch 'origin/feature/banji/test-case-generato…
3eba5a4
added GetCurrentUserTestCaseGenerator
294cb4e
fix(auth): Fix State Machine token race condition (#2100)
mattcreaser a87e9ad
Update release_pr.yml (#2105)
div5yesh 9d6a48d
chore: add retries to identify flaky tests (#2099)
sktimalsina 175c3a4
fix: Errors across storage and analytics category (#2096)
sdhuka af1693d
fix(auth): Fix authFlowType getter annotation and correct for null sa…
tylerjroach 5c63566
fix(auth): add missing client and analytics metadata (#2110)
div5yesh acf8930
fix: callbacks not invoked when attached using getTransfer api (#2111)
sdhuka 1bbdc48
Prevent attempting to read backed up EncryptedSharedPreferences that …
tylerjroach e69c425
fix(auth): device metadata migration (#2114)
div5yesh 17ca43a
Number of attributes being too high is not retryable (#2112)
tjleing d57749f
Change errors returned on some apis while federated (#2116)
tylerjroach b4b539b
release: Amplify Android 2.0.0 (#2115)
sktimalsina cb8b1f8
Merge remote-tracking branch 'origin/main' into feature/banji/test-ca…
ab549ff
Merge remote-tracking branch 'origin/main' into feature/banji/test-ca…
de8631b
added test case generators for forgot and remember device auth calls
2eeab44
fixed test issue with overloaded auth api functions
476b22f
Merge branch 'main' into feature/banji/test-case-generator
banji180 3470e9e
Added tests to captor factory
a0ac6a7
Added license to classes
2378ba7
Added error case to reset password test case generator
00e8316
Merge branch 'main' into feature/banji/test-case-generator
banji180 fa75c11
Merge branch 'main' into feature/banji/test-case-generator
gpanshu 715e075
Merge branch 'main' into feature/banji/test-case-generator
banji180 5cc1ec4
fixed lint issue
2622d8c
added json files
aaffd84
Merge branch 'main' into feature/banji/test-case-generator
banji180 4cdedf6
added missing json files
55ab30d
added missing json files
a5939c1
Merge branch 'main' into feature/banji/test-case-generator
banji180 e254c3f
Merge branch 'main' into feature/banji/test-case-generator
banji180 15aeba1
Merge branch 'main' into feature/banji/test-case-generator
banji180 a951cb3
empty
b93fa7c
empty commit
91bb45a
Merge branch 'main' into feature/banji/test-case-generator
awsmobilesdk 75771ff
Merge branch 'main' into feature/banji/test-case-generator
banji180 67e1dc6
Merge branch 'main' into feature/banji/test-case-generator
banji180 074e708
Merge remote-tracking branch 'origin/main' into feature/banji/test-ca…
4272a44
Updated year in new files
5467d68
Merge branch 'main' into feature/banji/test-case-generator
banji180 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 protected]"), | ||
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 protected]" | ||
}, | ||
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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.