Skip to content
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

fix(liveness): Liveness web socket expiration retry #2615

Merged
merged 20 commits into from
Nov 9, 2023
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
2 changes: 1 addition & 1 deletion aws-analytics-pinpoint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("com.android.library")
id("kotlin-android")
}
Expand Down
2 changes: 1 addition & 1 deletion aws-auth-cognito/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("com.android.library")
id("kotlin-android")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package com.amplifyframework.auth.cognito
import aws.sdk.kotlin.runtime.http.operation.customUserAgentMetadata
import aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient
import aws.sdk.kotlin.services.cognitoidentityprovider.CognitoIdentityProviderClient
import aws.sdk.kotlin.services.cognitoidentityprovider.endpoints.CognitoIdentityProviderEndpointProvider
import aws.smithy.kotlin.runtime.client.RequestInterceptorContext
import aws.smithy.kotlin.runtime.client.endpoints.Endpoint
import aws.smithy.kotlin.runtime.client.endpoints.EndpointProvider
import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor
import com.amplifyframework.statemachine.codegen.data.AuthConfiguration

Expand All @@ -36,7 +36,7 @@ interface AWSCognitoAuthService {
CognitoIdentityProviderClient {
this.region = it.region
this.endpointProvider = it.endpoint?.let { endpoint ->
EndpointProvider { Endpoint(endpoint) }
CognitoIdentityProviderEndpointProvider { Endpoint(endpoint) }
}
this.interceptors += object : HttpInterceptor {
override suspend fun modifyBeforeSerialization(context: RequestInterceptorContext<Any>): Any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ class RealAWSCognitoAuthPluginTest {
authService.cognitoIdentityProviderClient?.getUser(any())
} returns GetUserResponse.invoke {
this.userAttributes = userAttributes
username = ""
}

every {
Expand Down Expand Up @@ -1806,6 +1807,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SMS_MFA", "SOFTWARE_TOKEN_MFA")
preferredMfaSetting = "SOFTWARE_TOKEN_MFA"
userAttributes = listOf()
username = ""
}
}
plugin.fetchMFAPreference(onSuccess, onError)
Expand Down Expand Up @@ -1842,6 +1845,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}
plugin.updateMFAPreference(MFAPreference.ENABLED, MFAPreference.PREFERRED, onSuccess, onError)
Expand Down Expand Up @@ -1887,6 +1892,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SMS_MFA", "SOFTWARE_TOKEN_MFA")
preferredMfaSetting = "SOFTWARE_TOKEN_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -1937,6 +1944,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SMS_MFA", "SOFTWARE_TOKEN_MFA")
preferredMfaSetting = "SMS_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2040,6 +2049,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2090,6 +2101,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2140,6 +2153,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2190,6 +2205,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2240,6 +2257,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2290,6 +2309,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2340,6 +2361,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = null
preferredMfaSetting = null
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2390,6 +2413,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SOFTWARE_TOKEN_MFA")
preferredMfaSetting = "SOFTWARE_TOKEN_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2440,6 +2465,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SMS_MFA")
preferredMfaSetting = "SMS_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2490,6 +2517,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SMS_MFA")
preferredMfaSetting = "SMS_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2540,6 +2569,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SOFTWARE_TOKEN_MFA")
preferredMfaSetting = "SOFTWARE_TOKEN_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down Expand Up @@ -2590,6 +2621,8 @@ class RealAWSCognitoAuthPluginTest {
GetUserResponse.invoke {
userMfaSettingList = listOf("SMS_MFA")
preferredMfaSetting = "SMS_MFA"
userAttributes = listOf()
username = ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CognitoMockFactory(
this.userConfirmed = if (responseObject.containsKey("userConfirmed")) {
(responseObject["userConfirmed"] as? JsonPrimitive)?.boolean ?: false
} else false
this.userSub = ""
}
}
}
Expand Down Expand Up @@ -139,6 +140,7 @@ class CognitoMockFactory(
value = "000-000-0000"
}
)
username = ""
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"signUpStep": "DONE",
"additionalInfo": {
}
}
},
"userId": ""
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"deliveryMedium": "EMAIL",
"attributeName": "attributeName"
}
}
},
"userId": ""
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion aws-auth-plugins-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("com.android.library")
id("kotlin-android")
}
Expand Down
2 changes: 1 addition & 1 deletion aws-logging-cloudwatch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("com.android.library")
id("kotlin-android")
}
Expand Down
2 changes: 1 addition & 1 deletion aws-pinpoint-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("com.android.library")
id("kotlin-android")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.amplifyframework.pinpoint.core.database.PinpointDatabase
import com.amplifyframework.pinpoint.core.endpointProfile.EndpointProfile
import com.amplifyframework.pinpoint.core.models.PinpointEvent
import com.amplifyframework.pinpoint.core.util.millisToIsoDate
import java.util.concurrent.atomic.AtomicBoolean
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
Expand All @@ -59,7 +60,7 @@ class EventRecorder(
AWS_PINPOINT_ANALYTICS_LOG_NAMESPACE.format(EventRecorder::class.java.simpleName)
)
) {
private var isSyncInProgress = false
private var isSyncInProgress = AtomicBoolean(false)
private val defaultMaxSubmissionAllowed = 3
private val defaultMaxSubmissionSize = 1024 * 100
private val serviceDefinedMaxEventsPerBatch: Int = 100
Expand All @@ -79,12 +80,10 @@ class EventRecorder(
}
}

@Synchronized
internal suspend fun submitEvents(): List<AnalyticsEvent> {
return withContext(coroutineDispatcher) {
val result = runCatching {
if (!isSyncInProgress) {
isSyncInProgress = true
if (isSyncInProgress.compareAndSet(false, true)) {
processEvents()
} else {
logger.info("Sync is already in progress, skipping")
Expand All @@ -93,11 +92,11 @@ class EventRecorder(
}
when {
result.isSuccess -> {
isSyncInProgress = false
isSyncInProgress.set(false)
result.getOrNull() ?: emptyList()
}
else -> {
isSyncInProgress = false
isSyncInProgress.set(false)
logger.error("Failed to submit events ${result.exceptionOrNull()}")
emptyList()
}
Expand Down
2 changes: 1 addition & 1 deletion aws-predictions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.10"
id("com.android.library")
id("kotlin-android")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ internal class AWSV4Signer {
timeFormatter.isLenient = false
}

// used in incorrect time flow where we send an invalid response first to get time offset
fun resetPriorSignature() {
priorSignature = ""
}

fun getSignedUri(
uri: URI,
credentials: Credentials,
Expand Down
Loading
Loading