From 4900edb7f9db5952474586f83efd37b90995cde8 Mon Sep 17 00:00:00 2001 From: Robert McCahill <130065853+rmccahill@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:45:24 +0000 Subject: [PATCH] Update Native Auth password reset API response (#2281) Update relevant response classes to include the continuation token returned from the updated poll completion response, and updates constructors in test classes to reflect the change. --- changelog.txt | 1 + .../controllers/NativeAuthMsalController.kt | 5 ++++- .../ResetPasswordOAuth2StrategyTest.kt | 4 ++-- .../nativeauth/util/CommandResultUtilTest.kt | 22 +++++++++---------- .../results/ResetPasswordCommandResult.kt | 5 ++++- .../providers/NativeAuthResponseHandler.kt | 1 + .../ResetPasswordPollCompletionApiResponse.kt | 6 ++++- .../ResetPasswordPollCompletionApiResult.kt | 5 ++++- .../NativeAuthResponseHandlerTest.kt | 22 ++++++++++++++----- 9 files changed, 49 insertions(+), 22 deletions(-) diff --git a/changelog.txt b/changelog.txt index 03422b495c..5864db8663 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ V.Next - [MINOR] Add IsQrPinAvailableCommand, controllers behavior and define constants for the isQrAvailable API (#2219) - [MINOR] Add PreferredAuthMethod to interactive token flow (#2245) - [MINOR] Implement updates of the native auth web API (#2261) +- [MINOR] Update ResetPasswordPollCompletion related command, results, and responses to support signing in a user after a successful password reset. (#2281) V.17.0.0 --------- diff --git a/common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt b/common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt index add74be657..cd15f98099 100644 --- a/common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt +++ b/common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt @@ -951,7 +951,10 @@ class NativeAuthMsalController : BaseNativeAuthController() { } is ResetPasswordPollCompletionApiResult.PollingSucceeded -> { - ResetPasswordCommandResult.Complete + ResetPasswordCommandResult.Complete( + continuationToken = pollCompletionApiResult.continuationToken, + expiresIn = pollCompletionApiResult.expiresIn + ) } is ResetPasswordPollCompletionApiResult.InProgress -> { diff --git a/common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/ResetPasswordOAuth2StrategyTest.kt b/common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/ResetPasswordOAuth2StrategyTest.kt index d7c0ce27f7..a134f5f9a0 100644 --- a/common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/ResetPasswordOAuth2StrategyTest.kt +++ b/common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/ResetPasswordOAuth2StrategyTest.kt @@ -69,7 +69,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.powermock.core.classloader.annotations.PowerMockIgnore import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import java.util.UUID @@ -81,7 +81,7 @@ import java.util.UUID @RunWith( - PowerMockRunner::class + RobolectricTestRunner::class ) @PowerMockIgnore("javax.net.ssl.*") @PrepareForTest(DiagnosticContext::class) diff --git a/common/src/test/java/com/microsoft/identity/common/nativeauth/util/CommandResultUtilTest.kt b/common/src/test/java/com/microsoft/identity/common/nativeauth/util/CommandResultUtilTest.kt index fae675ddc8..56dd2cb5ed 100644 --- a/common/src/test/java/com/microsoft/identity/common/nativeauth/util/CommandResultUtilTest.kt +++ b/common/src/test/java/com/microsoft/identity/common/nativeauth/util/CommandResultUtilTest.kt @@ -147,7 +147,7 @@ class CommandResultUtilTestSignUpStartCommandResult(private val resultValue: Any fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -217,7 +217,7 @@ class CommandResultUtilTestSignUpSubmitCodeCommandResult(private val resultValue fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -287,7 +287,7 @@ class CommandResultUtilTestSignUpSignUpSubmitUserAttributesCommandResult(private fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -357,7 +357,7 @@ class CommandResultUtilTestSignUpSubmitPasswordCommandResult(private val resultV fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -424,7 +424,7 @@ class CommandResultUtilTestSignUpResendCodeCommandResult(private val resultValue fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -531,7 +531,7 @@ class CommandResultUtilTestSignInStartCommandResult(private val resultValue: Any fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -600,7 +600,7 @@ class CommandResultUtilTestSignInWithContinuationTokenCommandResult(private val fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -668,7 +668,7 @@ class CommandResultUtilTestSignInSubmitCodeCommandResult(private val resultValue fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -735,7 +735,7 @@ class CommandResultUtilTestSignInResendCodeCommandResult(private val resultValue fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -803,7 +803,7 @@ class CommandResultUtilTestSignInSubmitPasswordCommandResult(private val resultV fun testCheckAndWrapCommandResultTypeCompletedStatusWrongType() { val commandResult = CommandResult( ResultStatus.COMPLETED, - ResetPasswordCommandResult.Complete, + ResetPasswordCommandResult.Complete("", null), null ) @@ -849,7 +849,7 @@ private val resetPasswordCodeRequiredCommandResult = ResetPasswordCommandResult. codeLength = CODE_LENGTH ) -private val resetPasswordCompleteCommandResult = ResetPasswordCommandResult.Complete +private val resetPasswordCompleteCommandResult = ResetPasswordCommandResult.Complete("", null) private val resetPasswordEmailNotVerifiedCommandResult = ResetPasswordCommandResult.EmailNotVerified( error = ERROR, diff --git a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/controllers/results/ResetPasswordCommandResult.kt b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/controllers/results/ResetPasswordCommandResult.kt index cee3b30e40..e87c1c5988 100644 --- a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/controllers/results/ResetPasswordCommandResult.kt +++ b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/controllers/results/ResetPasswordCommandResult.kt @@ -67,5 +67,8 @@ interface ResetPasswordCommandResult { data class PasswordResetFailed(val error: String, val errorDescription: String, val correlationId: String = DiagnosticContext.INSTANCE.threadCorrelationId) : ResetPasswordSubmitNewPasswordCommandResult - object Complete : ResetPasswordSubmitNewPasswordCommandResult + data class Complete ( + val continuationToken: String?, + val expiresIn: Int? + ) : ResetPasswordSubmitNewPasswordCommandResult } \ No newline at end of file diff --git a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandler.kt b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandler.kt index e3d5e80f4f..98bb106d52 100644 --- a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandler.kt +++ b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandler.kt @@ -458,6 +458,7 @@ class NativeAuthResponseHandler { errorUri = null, status = null, continuationToken = null, + expiresIn = null, subError = null ) } else { diff --git a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResponse.kt b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResponse.kt index c0438e6dc8..14034d16e9 100644 --- a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResponse.kt +++ b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResponse.kt @@ -47,6 +47,7 @@ class ResetPasswordPollCompletionApiResponse( @Expose override var statusCode: Int, @Expose @SerializedName("status") val status: String?, @SerializedName("continuation_token") val continuationToken: String?, + @SerializedName("expires_in") val expiresIn: Int?, @SerializedName("error") val error: String?, @SerializedName("error_description") val errorDescription: String?, @SerializedName("error_uri") val errorUri: String?, @@ -115,7 +116,10 @@ class ResetPasswordPollCompletionApiResponse( ResetPasswordPollCompletionApiResult.InProgress } status.isPollSucceeded() -> { - ResetPasswordPollCompletionApiResult.PollingSucceeded + ResetPasswordPollCompletionApiResult.PollingSucceeded( + continuationToken = continuationToken, + expiresIn = expiresIn + ) } else -> { ResetPasswordPollCompletionApiResult.PollingFailed( diff --git a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResult.kt b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResult.kt index fce44972ec..b93972fed9 100644 --- a/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResult.kt +++ b/common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/responses/resetpassword/ResetPasswordPollCompletionApiResult.kt @@ -48,7 +48,10 @@ sealed interface ResetPasswordPollCompletionApiResult { errorDescription = errorDescription, ), ResetPasswordPollCompletionApiResult - object PollingSucceeded : ResetPasswordPollCompletionApiResult + data class PollingSucceeded( + val continuationToken: String?, + val expiresIn: Int? + ) : ResetPasswordPollCompletionApiResult data class UserNotFound( override val error: String, diff --git a/common4j/src/test/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandlerTest.kt b/common4j/src/test/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandlerTest.kt index 23bf6621a2..522d9887eb 100644 --- a/common4j/src/test/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandlerTest.kt +++ b/common4j/src/test/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthResponseHandlerTest.kt @@ -1878,7 +1878,8 @@ class NativeAuthResponseHandlerTest { error = null, errorDescription = null, errorUri = null, - subError = null + subError = null, + expiresIn = null ) val apiResult = resetPasswordPollCompletionApiResponse.toResult() @@ -1894,7 +1895,8 @@ class NativeAuthResponseHandlerTest { error = null, errorDescription = null, errorUri = null, - subError = null + subError = null, + expiresIn = null ) val apiResult = resetPasswordPollCompletionApiResponse.toResult() @@ -1910,7 +1912,8 @@ class NativeAuthResponseHandlerTest { error = null, errorDescription = null, errorUri = null, - subError = null + subError = null, + expiresIn = null ) val apiResult = resetPasswordPollCompletionApiResponse.toResult() @@ -1927,6 +1930,7 @@ class NativeAuthResponseHandlerTest { subError = passwordBannedError, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -1943,6 +1947,7 @@ class NativeAuthResponseHandlerTest { subError = passwordTooShortError, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -1959,6 +1964,7 @@ class NativeAuthResponseHandlerTest { subError = passwordTooLongError, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -1975,6 +1981,7 @@ class NativeAuthResponseHandlerTest { subError = passwordRecentlyUsedError, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -1991,6 +1998,7 @@ class NativeAuthResponseHandlerTest { subError = passwordTooWeakError, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -2007,6 +2015,7 @@ class NativeAuthResponseHandlerTest { subError = null, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -2023,6 +2032,7 @@ class NativeAuthResponseHandlerTest { subError = null, status = null, continuationToken = null, + expiresIn = null ) val apiResult = resetPasswordSubmitApiResponse.toResult() @@ -2038,7 +2048,8 @@ class NativeAuthResponseHandlerTest { error = null, errorDescription = null, errorUri = null, - subError = null + subError = null, + expiresIn = null ) val apiResult = resetPasswordPollCompletionApiResponse.toResult() @@ -2054,7 +2065,8 @@ class NativeAuthResponseHandlerTest { error = null, errorDescription = null, errorUri = null, - subError = null + subError = null, + expiresIn = null ) val apiResult = resetPasswordPollCompletionApiResponse.toResult()