Skip to content

Commit ccd2e07

Browse files
div5yesheeatonawsmikepschneiderlawmichamikschn-aws
authored
chore: merge main into push-notifications (#129)
* fix(core): remove unused dynamic nav dependency (#2132) * fix(datastore): remove typename from ModelMetadata (#2122) * fix(datastore): remove typename from ModelMetadata * Test a potential fix * Test a potential fix * fix: callbacks not invoked when attached using getTransfer api (#2111) * fix: listener not invoked when attached using getTransfer api * address PR comments * default state to unknown * add comment * add comment * override getRequest in storage operation & make SocketExcpetion retryable * add nullable annotation * address nullable request Co-authored-by: Tyler Roach <[email protected]> * Prevent attempting to read backed up EncryptedSharedPreferences that are no longer readable (#2113) * fix(auth): device metadata migration (#2114) * Number of attributes being too high is not retryable (#2112) * Number of attributes being too high is not retryable * Match iOS at not retrying bad request error -- covering multiple 400 errors * Fix lint * Fix lint * Update Kotlin SDK version Co-authored-by: Thomas Leing <[email protected]> * Change errors returned on some apis while federated (#2116) * release: Amplify Android 2.0.0 (#2115) * release: Amplify Android 2.0.0 * add core-kotlin changelog * add more info in changelog * revert unintended change * remove breaking change for analytics * fix(datastore): remove typename from ModelMetadata * fix(datastore): remove typename from ModelMetadata * remove unneeded file * small cleanup * remove print statements * fix comment * force tests * force tests * force tests Co-authored-by: Michael Law <[email protected]> Co-authored-by: Michael Schneider <[email protected]> Co-authored-by: Saijad Dhuka <[email protected]> Co-authored-by: Tyler Roach <[email protected]> Co-authored-by: Divyesh Chitroda <[email protected]> Co-authored-by: Thomas Leing <[email protected]> Co-authored-by: Thomas Leing <[email protected]> Co-authored-by: Sunil Timalsina <[email protected]> * chore: Remove deprecated maven plugin (#2137) * Remove deprecated maven project * Fix task name grep * chore: Remove Javadoc tasks (#2139) * Remove deprecated maven project * Fix task name grep * Remove Javadoc tasks * fix: Change order of updating state in local cache (#2141) * fix: fix integration test and added logger to integration test (#2143) * fix: Change order of updating state in local cache * change order for updating status and add logger to integ tests * change log level to debug * Fix for when move to idle state is called twice (#2152) * Update README.md (#2120) remove dev-preview APIs note. * Dengdan stress test (#2153) * Initial commit * Work in progress * finish codes * change build * update build * test excludeStressTest * Revert "Merge branch 'main' into dengdan-stress-test" This reverts commit b50840e, reversing changes made to 3bacf1b. * remove categories * remove external changes * remove external changes * remove more changes * Update copyright and refactor * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * linting * Update StorageStressTest.kt * Delete StorageStressTest.kt * Delete amplifyconfigurationupdated.json * Delete amplifyconfigurationupdated.json * Update DataStoreStressTest.kt * Fix(Auth): Sign up if successful should return DONE instead of Confirm sign up (#2130) * If sign up is successful in the first try return DONE * Sign up should send DONE if it is successful * revert jsongenerator cleandir fun * lint fix * Feat(Auth Test): Custom party testing for Custom Test without SRP (#2149) * Adding custom auth test cases * Updating test cases for Custom Auth to ensure they pass * lint format * Fix for phone number * Recreate all tests * Unignore storage and pinpoint tests (#2156) * unignore tests * extend timeout to 60s Co-authored-by: Saijad Dhuka <[email protected]> * feat(Geo): Add Kotlin Geo Facade (#2155) * Add Kotlin Geo Facade * Add return docs to the function comments * Add tests to verify options are passed * fix: Add missing apis in storage Kotlin & RxJava facade (#2160) * fix: Add pause, resume api to kotlin and rxJava facade * add unit tests * remove irrelevant code changes * add assertion * Update DeviceFarm build config (#2168) * fix: user metadata was persisted empty in the database (#2165) * fix: usermeta was persisted as empty in the database * fix compilation error * fix compilation error * avoid adding metadata if it is null * Add Geo Rx Bindings (#2159) * chore: Re-add storage tests (#2163) * Readd storage tests * rename file * reduce stress Co-authored-by: Saijad Dhuka <[email protected]> * Add a network status listener to restart DataStore after the network … (#2148) * Add a network status listener to restart DataStore after the network comes back online. * Add Reachability monitor * working pretty well * cleanup * update test * fix: fix integration test and added logger to integration test (#2143) * fix: Change order of updating state in local cache * change order for updating status and add logger to integ tests * change log level to debug * Fix for when move to idle state is called twice (#2152) * Update README.md (#2120) remove dev-preview APIs note. * Dengdan stress test (#2153) * Initial commit * Work in progress * finish codes * change build * update build * test excludeStressTest * Revert "Merge branch 'main' into dengdan-stress-test" This reverts commit b50840e, reversing changes made to 3bacf1b. * remove categories * remove external changes * remove external changes * remove more changes * Update copyright and refactor * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * Update StorageStressTest.kt * linting * Update StorageStressTest.kt * Delete StorageStressTest.kt * Delete amplifyconfigurationupdated.json * Delete amplifyconfigurationupdated.json * Update DataStoreStressTest.kt * force build * force build * force build * fix typo * Add a network status listener to restart DataStore after the network comes back online. * Add Reachability monitor * working pretty well * cleanup * update test * force build * force build * force build * fix typo * reply to comments * Add testImplementation lin eto compile tests correctly in intellij * reply to comments * make ReachabilityMonitor expose the observable * Update datastore plugin to use the reachability monitor * cleanup * cleanup * cleanup * force tests Co-authored-by: Michael Schneider <[email protected]> Co-authored-by: Saijad Dhuka <[email protected]> Co-authored-by: gpanshu <[email protected]> Co-authored-by: Divyesh Chitroda <[email protected]> Co-authored-by: dengdan154 <[email protected]> * chore: Upgrade Gradle, AGP, and KtLint (#2172) * Remove deprecated maven project * Fix task name grep * Upgrade Gradle to 7.5.1 * Upgrade AGP * Add VERSION_NAME back to BuildConfig This was removed for library projects in AGP 4.1. We may consider renaming this in the future to disambiguate the Amplify version and the application version. * Update KtLint and fix all new lint errors * Use JDK11 on codebuild * Use JDK11 in workflows * Upgrade compileSdkVersion to 31 * Try using custom commands to install Android SDK 31 * Update device farm buildspec with manual Android SDK install * Fix additional ktlint errors * Upgrade Desugar to JDK11-compatible version * Upgrade Robolectric * Set locale explicitly to match expectation * fix(geo): Increase Geo timeout so that it runs successfully on a Pixel 3a XL (#2177) * Increase Geo timeout so that it runs successfully on a Pixel 3a XL * Fix lint Co-authored-by: Thomas Leing <[email protected]> * Add a buildspec file for nightly tests (#2180) * Chore(Auth): Implementation of the custom auth with SRP parity testing use case (#2167) * Added the test case for custom auth with SRP * ktlint * release: Amplify Android 2.1.0 (manually created) (#2185) Co-authored-by: Thomas Leing <[email protected]> * chore: Add PR checker workflow (#2188) * fix(Auth): Fix for when loading credentials the success/error is fired twice (#2184) * chore: update changelog for Amplify Android 2.1.0 (#2193) * feat(Auth): Overriding sign in when the State machine is already in the signing in state (#2187) * chore: fix inconsistency with endpointWithAttributes test (#2196) * chore: update changelog for v2.1.0 (#2198) * chore: replace md5 with sha-256 for file data validation (#2199) * chore: Remove unused version and group properties (#2186) * chore: Add a label that will disable the PR title check (#2195) Co-authored-by: gpanshu <[email protected]> * chore: add release tag to PR title checker config (#2194) Co-authored-by: Matt Creaser <[email protected]> * fix(datastore): Fix lock contention issue when running DataStore.start() from the callback of DataStore.stop() (#2208) Co-authored-by: Michael Schneider <[email protected]> * chore: Add group and version back to all subprojects (#2213) Co-authored-by: Erica Eaton <[email protected]> Co-authored-by: Michael Schneider <[email protected]> Co-authored-by: Michael Law <[email protected]> Co-authored-by: Michael Schneider <[email protected]> Co-authored-by: Saijad Dhuka <[email protected]> Co-authored-by: Tyler Roach <[email protected]> Co-authored-by: Thomas Leing <[email protected]> Co-authored-by: Thomas Leing <[email protected]> Co-authored-by: Sunil Timalsina <[email protected]> Co-authored-by: Matt Creaser <[email protected]> Co-authored-by: gpanshu <[email protected]> Co-authored-by: dengdan154 <[email protected]>
1 parent a4d0c2c commit ccd2e07

File tree

27 files changed

+343
-52
lines changed

27 files changed

+343
-52
lines changed

.github/pr-title-checker-config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"color": "FF5733"
55
},
66
"CHECKS": {
7-
"prefixes": ["chore: ", "refactor: ", "perf: ", "test: ", "docs: "],
7+
"prefixes": ["chore: ", "refactor: ", "perf: ", "test: ", "docs: ", "release: "],
88
"regexp": "(fix|feat)\\((all|analytics|api|auth|core|datastore|geo|predictions|storage|notifications)\\): ",
99
"regexpFlags": "",
10-
"ignoreLabels" : []
10+
"ignoreLabels" : ["ignore-pr-title"]
1111
},
1212
"MESSAGES": {
1313
"success": "All OK",

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44
- feat(Geo): Add Kotlin Geo Facade (#2155)
55
- Add a network status listener to restart DataStore after the network comes back online. (#2148)
6+
- feat(auth): Overriding sign in when the State machine is already in the signing in state (#2187)
67

78
### Miscellaneous
89
- chore: Remove deprecated maven plugin (#2137)
@@ -17,6 +18,8 @@
1718
- chore: Upgrade Gradle, AGP, and KtLint (#2172)
1819
- Add a buildspec file for nightly tests (#2180)
1920
- Chore(Auth): Implementation of the custom auth with SRP parity testing use case (#2167)
21+
- chore: Add PR checker workflow (#2188)
22+
- fix(auth): Fix for when loading credentials the success/error is fired twice (#2184)
2023

2124
### Bug fixes
2225
- fix(core): remove unused dynamic nav dependency (#2132)

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ Copy-paste this, and complete the workflow in the UI. It will invite you to
430430
- The title of your PR must be of below format since next release version is determined from PR titles in the commit history.
431431
- For a bugfix: `fix(category): description of changes`
432432
- For a feature: `feat(catgory): add awesome feature`
433+
- For a release: `release: release version`
433434
- Everything else: `chore: fix build script`
434435
- Valid categories are:
435436
- all

aws-analytics-pinpoint/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ apply from: rootProject.file("configuration/publishing.gradle")
2222
apply plugin: 'kotlin-android'
2323
apply plugin: 'org.jlleitschuh.gradle.ktlint'
2424

25+
group = POM_GROUP
26+
2527
dependencies {
2628
implementation project(path: ':core')
2729
implementation project(path: ':aws-auth-cognito')
@@ -47,4 +49,3 @@ dependencies {
4749
implementation dependency.androidx.test.junit
4850
androidTestImplementation project(path: ':aws-analytics-pinpoint')
4951
}
50-

aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin
3434
import com.amplifyframework.core.Amplify
3535
import com.amplifyframework.hub.HubChannel
3636
import com.amplifyframework.hub.HubEvent
37+
import com.amplifyframework.logging.AndroidLoggingPlugin
38+
import com.amplifyframework.logging.LogLevel
3739
import com.amplifyframework.testutils.HubAccumulator
3840
import com.amplifyframework.testutils.Resources
3941
import com.amplifyframework.testutils.Sleep
@@ -88,7 +90,7 @@ class PinpointAnalyticsInstrumentationTest {
8890

8991
// Act: Record the event
9092
Amplify.Analytics.recordEvent(event)
91-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
93+
Sleep.milliseconds(DEFAULT_TIMEOUT)
9294
Amplify.Analytics.flushEvents()
9395
val hubEvents = hubAccumulator.await(10, TimeUnit.SECONDS)
9496
val submittedEvents = combineAndFilterEvents(hubEvents)
@@ -116,15 +118,15 @@ class PinpointAnalyticsInstrumentationTest {
116118
.addProperty("DemoDoubleProperty2", 2.0)
117119
.build()
118120
Amplify.Analytics.recordEvent(event1)
119-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
121+
Sleep.milliseconds(DEFAULT_TIMEOUT)
120122
val eventName2 = "Amplify-event" + UUID.randomUUID().toString()
121123
val event2 = AnalyticsEvent.builder()
122124
.name(eventName2)
123125
.addProperty("DemoProperty1", "DemoValue1")
124126
.addProperty("DemoProperty2", 2.0)
125127
.build()
126128
Amplify.Analytics.recordEvent(event2)
127-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
129+
Sleep.milliseconds(DEFAULT_TIMEOUT)
128130
Amplify.Analytics.flushEvents()
129131
val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS)
130132
val hubEvent = analyticsHubEventAccumulator.awaitFirst()
@@ -187,9 +189,9 @@ class PinpointAnalyticsInstrumentationTest {
187189

188190
// Act: Record two events: the one created above and another just with a key
189191
Amplify.Analytics.recordEvent(event)
190-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
192+
Sleep.milliseconds(DEFAULT_TIMEOUT)
191193
Amplify.Analytics.recordEvent("amplify-test-event")
192-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
194+
Sleep.milliseconds(DEFAULT_TIMEOUT)
193195
Amplify.Analytics.flushEvents()
194196
val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS)
195197
val submittedEvents = combineAndFilterEvents(hubEvents)
@@ -224,10 +226,10 @@ class PinpointAnalyticsInstrumentationTest {
224226

225227
// Act: Record an event, unregister the global property, and record another event
226228
Amplify.Analytics.recordEvent("amplify-test-event-with-property")
227-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
229+
Sleep.milliseconds(DEFAULT_TIMEOUT)
228230
Amplify.Analytics.unregisterGlobalProperties("GlobalProperty")
229231
Amplify.Analytics.recordEvent("amplify-test-event-without-property")
230-
Sleep.milliseconds(RECORD_INSERTION_TIMEOUT)
232+
Sleep.milliseconds(DEFAULT_TIMEOUT)
231233
Amplify.Analytics.flushEvents()
232234
val hubEvents = analyticsHubEventAccumulator.await(10, TimeUnit.SECONDS)
233235
val submittedEvents = combineAndFilterEvents(hubEvents)
@@ -280,9 +282,16 @@ class PinpointAnalyticsInstrumentationTest {
280282
.customProperties(properties)
281283
.userAttributes(userAttributes)
282284
.build()
283-
Amplify.Analytics.identifyUser(UUID.randomUUID().toString(), pinpointUserProfile)
285+
val uuid = UUID.randomUUID().toString()
286+
Amplify.Analytics.identifyUser(uuid, pinpointUserProfile)
284287
Sleep.milliseconds(PINPOINT_ROUNDTRIP_TIMEOUT)
285-
val endpointResponse = fetchEndpointResponse()
288+
var endpointResponse = fetchEndpointResponse()
289+
var retry_count = 0
290+
while (retry_count < MAX_RETRIES && endpointResponse.attributes.isNullOrEmpty()) {
291+
Sleep.milliseconds(DEFAULT_TIMEOUT)
292+
endpointResponse = fetchEndpointResponse()
293+
retry_count++
294+
}
286295
assertCommonEndpointResponseProperties(endpointResponse)
287296
Assert.assertEquals(
288297
"User attribute value",
@@ -308,7 +317,7 @@ class PinpointAnalyticsInstrumentationTest {
308317
}
309318

310319
private fun assertCommonEndpointResponseProperties(endpointResponse: EndpointResponse) {
311-
Log.i("DEBUG", endpointResponse.toString())
320+
Log.d("PinpointAnalyticsInstrumentationTest", endpointResponse.toString())
312321
val attributes = endpointResponse.attributes!!
313322
Assert.assertEquals("[email protected]", attributes["email"]!![0])
314323
Assert.assertEquals("test-user", attributes["name"]!![0])
@@ -367,7 +376,8 @@ class PinpointAnalyticsInstrumentationTest {
367376
private const val CONFIGURATION_NAME = "amplifyconfiguration"
368377
private const val COGNITO_CONFIGURATION_TIMEOUT = 10 * 1000L
369378
private const val PINPOINT_ROUNDTRIP_TIMEOUT = 10 * 1000L
370-
private const val RECORD_INSERTION_TIMEOUT = 5 * 1000L
379+
private const val DEFAULT_TIMEOUT = 5 * 1000L
380+
private const val MAX_RETRIES = 10
371381
private const val UNIQUE_ID_KEY = "UniqueId"
372382
private const val PREFERENCES_AND_FILE_MANAGER_SUFFIX = "515d6767-01b7-49e5-8273-c8d11b0f331d"
373383
private lateinit var synchronousAuth: SynchronousAuth
@@ -388,6 +398,7 @@ class PinpointAnalyticsInstrumentationTest {
388398
setUniqueId()
389399
Amplify.Auth.addPlugin(AWSCognitoAuthPlugin() as AuthPlugin<*>)
390400
Amplify.addPlugin(AWSPinpointAnalyticsPlugin())
401+
Amplify.Logging.addPlugin(AndroidLoggingPlugin(LogLevel.DEBUG))
391402
Amplify.configure(context)
392403
Sleep.milliseconds(COGNITO_CONFIGURATION_TIMEOUT)
393404
synchronousAuth = SynchronousAuth.delegatingTo(Amplify.Auth)

aws-api-appsync/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ apply plugin: 'com.android.library'
1717
apply from: rootProject.file('configuration/checkstyle.gradle')
1818
apply from: rootProject.file('configuration/publishing.gradle')
1919

20+
group = POM_GROUP
21+
2022
dependencies {
2123
implementation project(':core')
2224

aws-api/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ apply plugin: 'kotlin-android'
1818
apply from: rootProject.file("configuration/checkstyle.gradle")
1919
apply from: rootProject.file("configuration/publishing.gradle")
2020

21+
group = POM_GROUP
22+
2123
dependencies {
2224
api project(':core')
2325
implementation project(':aws-api-appsync')
@@ -45,4 +47,3 @@ dependencies {
4547
androidTestImplementation dependency.androidx.test.junit
4648
androidTestImplementation dependency.rxjava
4749
}
48-

aws-auth-cognito/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ apply plugin: 'kotlin-android'
2222
apply from: rootProject.file("configuration/publishing.gradle")
2323
apply from: rootProject.file("configuration/checkstyle.gradle")
2424

25+
group = POM_GROUP
26+
2527
dependencies {
2628
implementation project(path: ':core')
2729
implementation dependency.kotlin.coroutines
@@ -56,4 +58,4 @@ dependencies {
5658
androidTestImplementation dependency.androidx.test.junit
5759
androidTestImplementation project(path: ':testutils')
5860
androidTestImplementation project(path: ':aws-auth-cognito')
59-
}
61+
}

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context:
5656
) {
5757
var capturedSuccess: Result<AmplifyCredential>? = null
5858
var capturedError: Exception? = null
59-
val token = StateChangeListenerToken()
59+
var token: StateChangeListenerToken? = StateChangeListenerToken()
6060
credentialStoreStateMachine.listen(
61-
token,
61+
token as StateChangeListenerToken,
6262
{ storeState ->
6363
logger.verbose("Credential Store State Change: $storeState")
64-
6564
when (storeState) {
6665
is CredentialStoreState.Success -> {
6766
capturedSuccess = Result.success(storeState.storedCredentials)
@@ -72,11 +71,13 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context:
7271
is CredentialStoreState.Idle -> {
7372
val success = capturedSuccess
7473
val error = capturedError
75-
if (success != null) {
76-
credentialStoreStateMachine.cancel(token)
74+
if (success != null && token != null) {
75+
credentialStoreStateMachine.cancel(token!!)
76+
token = null
7777
onSuccess(success)
78-
} else if (error != null) {
79-
credentialStoreStateMachine.cancel(token)
78+
} else if (error != null && token != null) {
79+
credentialStoreStateMachine.cancel(token!!)
80+
token = null
8081
onError(error)
8182
}
8283
}

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,37 @@ internal class RealAWSCognitoAuthPlugin(
464464
onError: Consumer<AuthException>
465465
) {
466466
authStateMachine.getCurrentState { authState ->
467+
val signInOptions = options as? AWSCognitoAuthSignInOptions ?: AWSCognitoAuthSignInOptions.builder()
468+
.authFlowType(configuration.authFlowType)
469+
.build()
467470
when (authState.authNState) {
468471
is AuthenticationState.NotConfigured -> onError.accept(
469472
InvalidUserPoolConfigurationException()
470473
)
471474
// Continue sign in
472-
is AuthenticationState.SignedOut, is AuthenticationState.Configured -> {
473-
val signInOptions = options as? AWSCognitoAuthSignInOptions ?: AWSCognitoAuthSignInOptions.builder()
474-
.authFlowType(configuration.authFlowType)
475-
.build()
476-
475+
is AuthenticationState.SignedOut,
476+
is AuthenticationState.Configured -> {
477477
_signIn(username, password, signInOptions, onSuccess, onError)
478478
}
479479
is AuthenticationState.SignedIn -> onError.accept(SignedInException())
480+
is AuthenticationState.SigningIn -> {
481+
val token = StateChangeListenerToken()
482+
authStateMachine.listen(
483+
token,
484+
{ authState ->
485+
when (authState.authNState) {
486+
is AuthenticationState.SignedOut -> {
487+
authStateMachine.cancel(token)
488+
_signIn(username, password, signInOptions, onSuccess, onError)
489+
}
490+
else -> Unit
491+
}
492+
},
493+
{
494+
authStateMachine.send(AuthenticationEvent(AuthenticationEvent.EventType.CancelSignIn()))
495+
}
496+
)
497+
}
480498
else -> onError.accept(InvalidStateException())
481499
}
482500
}
@@ -706,6 +724,30 @@ internal class RealAWSCognitoAuthPlugin(
706724
)
707725
}
708726
is AuthenticationState.SignedIn -> onError.accept(SignedInException())
727+
is AuthenticationState.SigningIn -> {
728+
val token = StateChangeListenerToken()
729+
authStateMachine.listen(
730+
token,
731+
{ authState ->
732+
when (authState.authNState) {
733+
is AuthenticationState.SignedOut -> {
734+
authStateMachine.cancel(token)
735+
_signInWithHostedUI(
736+
callingActivity = callingActivity,
737+
options = options,
738+
onSuccess = onSuccess,
739+
onError = onError,
740+
provider = provider
741+
)
742+
}
743+
else -> Unit
744+
}
745+
},
746+
{
747+
authStateMachine.send(AuthenticationEvent(AuthenticationEvent.EventType.CancelSignIn()))
748+
}
749+
)
750+
}
709751
else -> onError.accept(InvalidStateException())
710752
}
711753
}

aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.amplifyframework.auth.cognito
1818
import aws.sdk.kotlin.services.cognitoidentityprovider.CognitoIdentityProviderClient
1919
import aws.sdk.kotlin.services.cognitoidentityprovider.model.AnalyticsMetadataType
2020
import aws.sdk.kotlin.services.cognitoidentityprovider.model.AttributeType
21-
import aws.sdk.kotlin.services.cognitoidentityprovider.model.ChangePasswordRequest
2221
import aws.sdk.kotlin.services.cognitoidentityprovider.model.ChangePasswordResponse
2322
import aws.sdk.kotlin.services.cognitoidentityprovider.model.CodeDeliveryDetailsType
2423
import aws.sdk.kotlin.services.cognitoidentityprovider.model.CognitoIdentityProviderException
@@ -44,7 +43,6 @@ import com.amplifyframework.auth.AuthException
4443
import com.amplifyframework.auth.AuthUserAttribute
4544
import com.amplifyframework.auth.AuthUserAttributeKey
4645
import com.amplifyframework.auth.cognito.exceptions.configuration.InvalidUserPoolConfigurationException
47-
import com.amplifyframework.auth.cognito.exceptions.invalidstate.SignedInException
4846
import com.amplifyframework.auth.cognito.helpers.AuthHelper
4947
import com.amplifyframework.auth.cognito.helpers.SRPHelper
5048
import com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions
@@ -223,6 +221,7 @@ class RealAWSCognitoAuthPluginTest {
223221
val expectedAuthError = InvalidUserPoolConfigurationException()
224222
currentState = AuthenticationState.NotConfigured()
225223

224+
coEvery { authConfiguration.authFlowType } returns AuthFlowType.USER_SRP_AUTH
226225
// WHEN
227226
plugin.signIn("user", "password", AuthSignInOptions.defaults(), onSuccess, onError)
228227

@@ -236,7 +235,7 @@ class RealAWSCognitoAuthPluginTest {
236235
// GIVEN
237236
val onSuccess = mockk<Consumer<AuthSignInResult>>()
238237
val onError = mockk<Consumer<AuthException>>(relaxed = true)
239-
val expectedAuthError = SignedInException()
238+
coEvery { authConfiguration.authFlowType } returns AuthFlowType.USER_SRP_AUTH
240239
currentState = AuthenticationState.SignedIn(
241240
SignedInData(
242241
"userId",
@@ -253,7 +252,7 @@ class RealAWSCognitoAuthPluginTest {
253252

254253
// THEN
255254
verify(exactly = 0) { onSuccess.accept(any()) }
256-
verify { onError.accept(expectedAuthError) }
255+
verify { onError.accept(any()) }
257256
}
258257

259258
@Test
@@ -290,7 +289,7 @@ class RealAWSCognitoAuthPluginTest {
290289
}
291290

292291
coEvery {
293-
authService.cognitoIdentityProviderClient?.changePassword(any<ChangePasswordRequest>())
292+
authService.cognitoIdentityProviderClient?.changePassword(any())
294293
} returns ChangePasswordResponse.invoke { }
295294

296295
// WHEN

aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,30 @@ object SignInTestCaseGenerator : SerializableProvider {
271271
)
272272
)
273273

274+
private val signInWhenAlreadySigningInAuthCase = FeatureTestCase(
275+
description = "Test that overriding signIn when already signing in returns success",
276+
preConditions = PreConditions(
277+
"authconfiguration.json",
278+
"SigningIn_SigningIn.json",
279+
mockedResponses = listOf(
280+
mockedInitiateAuthResponse,
281+
mockedSMSChallengeResponse,
282+
)
283+
),
284+
api = API(
285+
AuthAPI.signIn,
286+
params = mapOf(
287+
"username" to username,
288+
"password" to password
289+
).toJsonElement(),
290+
options = JsonObject(emptyMap())
291+
),
292+
validations = listOf(
293+
mockedSignInSMSChallengeExpectation,
294+
ExpectationShapes.State("SigningIn_SigningIn.json")
295+
)
296+
)
297+
274298
private val customAuthCase = FeatureTestCase(
275299
description = "Test that Custom Auth signIn invokes proper cognito request and returns custom challenge",
276300
preConditions = PreConditions(
@@ -325,6 +349,11 @@ object SignInTestCaseGenerator : SerializableProvider {
325349
)
326350

327351
override val serializables: List<Any> = listOf(
328-
baseCase, challengeCase, deviceSRPTestCase, customAuthCase, customAuthWithSRPCase
352+
baseCase,
353+
challengeCase,
354+
deviceSRPTestCase,
355+
customAuthCase,
356+
customAuthWithSRPCase,
357+
signInWhenAlreadySigningInAuthCase
329358
)
330359
}

0 commit comments

Comments
 (0)