Skip to content

Commit

Permalink
addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanshu committed Sep 6, 2023
1 parent f29b348 commit 0b3b3ad
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal class CognitoAuthExceptionConverter {
is InvalidPasswordException ->
com.amplifyframework.auth.cognito.exceptions.service.InvalidPasswordException(error)
is InvalidParameterException ->
com.amplifyframework.auth.cognito.exceptions.service.InvalidParameterException(error)
com.amplifyframework.auth.cognito.exceptions.service.InvalidParameterException(cause = error)
is ExpiredCodeException -> CodeExpiredException(error)
is CodeMismatchException -> com.amplifyframework.auth.cognito.exceptions.service.CodeMismatchException(
error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ import com.amplifyframework.statemachine.codegen.states.SetupTOTPState
import com.amplifyframework.statemachine.codegen.states.SignInChallengeState
import com.amplifyframework.statemachine.codegen.states.SignInState
import com.amplifyframework.statemachine.codegen.states.SignOutState
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch

internal class RealAWSCognitoAuthPlugin(
private val configuration: AuthConfiguration,
Expand Down Expand Up @@ -2225,7 +2225,7 @@ internal class RealAWSCognitoAuthPlugin(
onError: Consumer<AuthException>
) {
if (sms == null && totp == null) {
onError.accept(InvalidParameterException("No valid MFA Preferences were provided. Please try again."))
onError.accept(InvalidParameterException("No mfa settings given"))
return
}
fetchMFAPreference({ userPreference ->
Expand Down Expand Up @@ -2258,6 +2258,7 @@ internal class RealAWSCognitoAuthPlugin(
}
}
}?.also {
println("Ankit's test $it")
onSuccess.call()
}
} ?: onError.accept(SignedOutException())
Expand All @@ -2271,7 +2272,6 @@ internal class RealAWSCognitoAuthPlugin(
}
}
}

else -> onError.accept(InvalidStateException())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ internal open class AuthHelper {
fun getSecretHash(userId: String?, clientId: String?, clientSecret: String?): String? {
return when {
userId == null -> throw InvalidParameterException(
Exception("user ID cannot be null")
cause = Exception("user ID cannot be null")
)
clientId == null -> throw InvalidParameterException(
Exception("client ID cannot be null")
cause = Exception("client ID cannot be null")
)
clientSecret.isNullOrEmpty() -> null
else ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import aws.sdk.kotlin.services.cognitoidentityprovider.model.ConfirmForgotPasswo
import aws.sdk.kotlin.services.cognitoidentityprovider.model.ConfirmSignUpRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.ConfirmSignUpResponse
import aws.sdk.kotlin.services.cognitoidentityprovider.model.DeliveryMediumType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.GetUserAttributeVerificationCodeRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.GetUserAttributeVerificationCodeResponse
import aws.sdk.kotlin.services.cognitoidentityprovider.model.GetUserRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.GetUserResponse
import aws.sdk.kotlin.services.cognitoidentityprovider.model.ResendConfirmationCodeRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.ResendConfirmationCodeResponse
Expand All @@ -42,12 +40,10 @@ import aws.sdk.kotlin.services.cognitoidentityprovider.model.SignUpResponse
import aws.sdk.kotlin.services.cognitoidentityprovider.model.SmsMfaSettingsType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.SoftwareTokenMfaNotFoundException
import aws.sdk.kotlin.services.cognitoidentityprovider.model.SoftwareTokenMfaSettingsType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.UpdateUserAttributesRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.UpdateUserAttributesResponse
import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifySoftwareTokenRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifySoftwareTokenResponse
import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifySoftwareTokenResponseType
import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifyUserAttributeRequest
import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifyUserAttributeResponse
import com.amplifyframework.auth.AuthCodeDeliveryDetails
import com.amplifyframework.auth.AuthException
Expand Down Expand Up @@ -105,6 +101,10 @@ import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.verify
import org.json.JSONObject
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import java.util.Date
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
Expand All @@ -113,10 +113,6 @@ import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.json.JSONObject
import org.junit.Before
import org.junit.Ignore
import org.junit.Test

class RealAWSCognitoAuthPluginTest {

Expand Down Expand Up @@ -513,7 +509,7 @@ class RealAWSCognitoAuthPluginTest {
}

coEvery {
authService.cognitoIdentityProviderClient?.getUser(any<GetUserRequest>())
authService.cognitoIdentityProviderClient?.getUser(any())
} returns GetUserResponse.invoke {
this.userAttributes = userAttributes
}
Expand Down Expand Up @@ -916,7 +912,6 @@ class RealAWSCognitoAuthPluginTest {
// GIVEN
val onSuccess = mockk<Consumer<AuthCodeDeliveryDetails>>()
val onError = mockk<Consumer<AuthException>>()
val userId = "123456"
val username = "user"

val resultCaptor = slot<AuthCodeDeliveryDetails>()
Expand Down Expand Up @@ -1023,7 +1018,7 @@ class RealAWSCognitoAuthPluginTest {
}

coEvery {
authService.cognitoIdentityProviderClient?.updateUserAttributes(any<UpdateUserAttributesRequest>())
authService.cognitoIdentityProviderClient?.updateUserAttributes(any())
} returns UpdateUserAttributesResponse.invoke {
}

Expand Down Expand Up @@ -1071,7 +1066,7 @@ class RealAWSCognitoAuthPluginTest {
}

coEvery {
authService.cognitoIdentityProviderClient?.updateUserAttributes(any<UpdateUserAttributesRequest>())
authService.cognitoIdentityProviderClient?.updateUserAttributes(any())
} returns UpdateUserAttributesResponse.invoke {
}

Expand Down Expand Up @@ -1123,7 +1118,7 @@ class RealAWSCognitoAuthPluginTest {
}

coEvery {
authService.cognitoIdentityProviderClient?.updateUserAttributes(any<UpdateUserAttributesRequest>())
authService.cognitoIdentityProviderClient?.updateUserAttributes(any())
} returns UpdateUserAttributesResponse.invoke {
codeDeliveryDetailsList = listOf(
CodeDeliveryDetailsType.invoke {
Expand Down Expand Up @@ -1295,7 +1290,7 @@ class RealAWSCognitoAuthPluginTest {

val expectedException = CognitoIdentityProviderException("Some Cognito Message")
coEvery {
authService.cognitoIdentityProviderClient?.verifyUserAttribute(any<VerifyUserAttributeRequest>())
authService.cognitoIdentityProviderClient?.verifyUserAttribute(any())
} answers {
throw expectedException
}
Expand Down Expand Up @@ -1332,7 +1327,7 @@ class RealAWSCognitoAuthPluginTest {
}

coEvery {
authService.cognitoIdentityProviderClient?.verifyUserAttribute(any<VerifyUserAttributeRequest>())
authService.cognitoIdentityProviderClient?.verifyUserAttribute(any())
} returns VerifyUserAttributeResponse.invoke {
}
every {
Expand Down Expand Up @@ -1441,7 +1436,7 @@ class RealAWSCognitoAuthPluginTest {
val expectedException = CognitoIdentityProviderException("Some Cognito Message")
coEvery {
authService.cognitoIdentityProviderClient?.getUserAttributeVerificationCode(
any<GetUserAttributeVerificationCodeRequest>()
any()
)
} answers {
throw expectedException
Expand Down Expand Up @@ -1479,7 +1474,7 @@ class RealAWSCognitoAuthPluginTest {

coEvery {
authService.cognitoIdentityProviderClient?.getUserAttributeVerificationCode(
any<GetUserAttributeVerificationCodeRequest>()
any()
)
} returns GetUserAttributeVerificationCodeResponse.invoke {
codeDeliveryDetails = CodeDeliveryDetailsType.invoke {
Expand Down Expand Up @@ -1548,7 +1543,7 @@ class RealAWSCognitoAuthPluginTest {
configJsonObject.put("Endpoint", invalidEndpoint)
val expectedErrorMessage = "Invalid endpoint value $invalidEndpoint. Expected fully qualified hostname with " +
"no scheme, no path and no query"
var message = try {
val message = try {
UserPoolConfiguration.fromJson(configJsonObject).build()
} catch (ex: Exception) {
ex.message
Expand All @@ -1566,7 +1561,7 @@ class RealAWSCognitoAuthPluginTest {
configJsonObject.put("Endpoint", invalidEndpoint)
val expectedErrorMessage = "Invalid endpoint value $invalidEndpoint. Expected fully qualified hostname with " +
"no scheme, no path and no query"
var message = try {
val message = try {
UserPoolConfiguration.fromJson(configJsonObject).build()
} catch (ex: Exception) {
ex.message
Expand All @@ -1585,7 +1580,7 @@ class RealAWSCognitoAuthPluginTest {
configJsonObject.put("Endpoint", invalidEndpoint)
val expectedErrorMessage = "Invalid endpoint value $invalidEndpoint. Expected fully qualified hostname with " +
"no scheme, no path and no query"
var message = try {
val message = try {
UserPoolConfiguration.fromJson(configJsonObject).build()
} catch (ex: Exception) {
ex.message
Expand Down Expand Up @@ -1716,8 +1711,6 @@ class RealAWSCognitoAuthPluginTest {
val onSuccess = mockk<Action>()
every { onSuccess.call() }.answers { listenLatch.countDown() }
val onError = mockk<Consumer<AuthException>>()

val session = "SESSION"
val code = "123456"
val friendlyDeviceName = "DEVICE_NAME"
coEvery {
Expand Down Expand Up @@ -1760,9 +1753,7 @@ class RealAWSCognitoAuthPluginTest {
val authException = slot<AuthException>()
every { onError.accept(capture(authException)) }.answers { listenLatch.countDown() }

val session = "SESSION"
val code = "123456"
val friendlyDeviceName = "DEVICE_NAME"
val errorMessage = "Invalid code"
coEvery {
mockCognitoIPClient.verifySoftwareToken(
Expand Down Expand Up @@ -2012,7 +2003,6 @@ class RealAWSCognitoAuthPluginTest {
val onError = mockk<Consumer<AuthException>>()
val authException = slot<AuthException>()
every { onError.accept(capture(authException)) }.answers { listenLatch.countDown() }
val setUserMFAPreferenceRequest = slot<SetUserMfaPreferenceRequest>()
coEvery {
mockCognitoIPClient.getUser {
accessToken = credentials.signedInData.cognitoUserPoolTokens.accessToken
Expand Down

0 comments on commit 0b3b3ad

Please sign in to comment.