From d4adc9eccb92edafb836aae60f78e4292fee1470 Mon Sep 17 00:00:00 2001 From: James Richardson Date: Mon, 24 Jul 2023 17:53:51 +0100 Subject: [PATCH] moshi config was incorrect for successful user password auth reponse - certain fields are null --- .../amazon/cognito/action/InitiateAuth.kt | 4 +-- .../cognito/ActualCognitoResponsesTest.kt | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 amazon/cognito/client/src/test/kotlin/org/http4k/connect/amazon/cognito/ActualCognitoResponsesTest.kt diff --git a/amazon/cognito/client/src/main/kotlin/org/http4k/connect/amazon/cognito/action/InitiateAuth.kt b/amazon/cognito/client/src/main/kotlin/org/http4k/connect/amazon/cognito/action/InitiateAuth.kt index a6a7de660..c145f0b21 100644 --- a/amazon/cognito/client/src/main/kotlin/org/http4k/connect/amazon/cognito/action/InitiateAuth.kt +++ b/amazon/cognito/client/src/main/kotlin/org/http4k/connect/amazon/cognito/action/InitiateAuth.kt @@ -25,7 +25,7 @@ data class InitiateAuth( @JsonSerializable data class AuthInitiated( val AuthenticationResult: AuthenticationResult, - val ChallengeName: ChallengeName, + val ChallengeName: ChallengeName?, val ChallengeParameters: Map, - val Session: Session + val Session: Session? ) diff --git a/amazon/cognito/client/src/test/kotlin/org/http4k/connect/amazon/cognito/ActualCognitoResponsesTest.kt b/amazon/cognito/client/src/test/kotlin/org/http4k/connect/amazon/cognito/ActualCognitoResponsesTest.kt new file mode 100644 index 000000000..b2eb5dade --- /dev/null +++ b/amazon/cognito/client/src/test/kotlin/org/http4k/connect/amazon/cognito/ActualCognitoResponsesTest.kt @@ -0,0 +1,32 @@ +package org.http4k.connect.amazon.cognito + +import com.natpryce.hamkrest.assertion.assertThat +import com.natpryce.hamkrest.equalTo +import org.http4k.connect.amazon.cognito.action.AuthInitiated +import org.http4k.connect.amazon.cognito.model.AccessToken +import org.http4k.connect.amazon.cognito.model.IdToken +import org.http4k.connect.amazon.cognito.model.RefreshToken +import org.junit.jupiter.api.Test + +class ActualCognitoResponsesTest { + + val factory = CognitoMoshi + + @Test + fun `deserialising a user password response with no challenges requested`() { + val response = factory.asA("""{"AuthenticationResult": + {"AccessToken":"access-token", + "ExpiresIn":3600, + "IdToken":"id-token", + "RefreshToken":"refresh-token", + "TokenType":"Bearer"}, + "ChallengeParameters":{}} + """.trimIndent()) + assertThat(response.AuthenticationResult.AccessToken, equalTo(AccessToken.of("access-token"))) + assertThat(response.AuthenticationResult.ExpiresIn, equalTo(3600)) + assertThat(response.AuthenticationResult.IdToken, equalTo(IdToken.of("id-token"))) + assertThat(response.AuthenticationResult.RefreshToken, equalTo(RefreshToken.of("refresh-token"))) + assertThat(response.AuthenticationResult.TokenType, equalTo("Bearer")) + assertThat(response.ChallengeParameters, equalTo(mapOf())) + } +}