feat(cognito): align user pool client config APIs with AWS behavior (#1360)

* feat(cognito): align CreateUserPoolClient and DescribeUserPoolClient with AWS behavior

* feat(cognito): align user pool client config APIs with AWS behavior
This commit is contained in:
shrimptails-f authored and GitHub committed 2026-06-16 00:34:17 -05:00
1 parent 174bb81dbf
commit 571d81afe3
7 files changed
+962 -33

No files matched your search

@@ -1514,6 +1514,253 @@ class CognitoIntegrationTest {
assertFalse(hasGenderAfterDelete, "custom:gender should be deleted");
}
// =========================================================================
// Issue #1306 — User pool client extended configuration and token validity
// =========================================================================
@Test
@Order(95)
void userPoolClientPersistsExtendedConfigurationFields() throws Exception {
JsonNode poolResponse = cognitoJson("CreateUserPool", """
{
"PoolName": "ExtendedClientPool"
}
""");
String extendedPoolId = poolResponse.path("UserPool").path("Id").asText();
JsonNode createResp = cognitoJson("CreateUserPoolClient", """
{
"UserPoolId": "%s",
"ClientName": "extended-client",
"GenerateSecret": true,
"AllowedOAuthFlowsUserPoolClient": true,
"AllowedOAuthFlows": ["code"],
"AllowedOAuthScopes": ["aws.cognito.signin.user.admin", "openid"],
"AnalyticsConfiguration": {
"ApplicationId": "d70b2ba36a8c4dc5a04a0451a31a1e12",
"ExternalId": "my-external-id",
"RoleArn": "arn:aws:iam::123456789012:role/test-cognitouserpool-role",
"UserDataShared": true
},
"CallbackURLs": ["https://example.com", "http://localhost", "myapp://example"],
"DefaultRedirectURI": "https://example.com",
"ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"],
"AccessTokenValidity": 15,
"IdTokenValidity": 20,
"LogoutURLs": ["https://example.com/logout"],
"ReadAttributes": ["email", "address", "preferred_username"],
"RefreshTokenValidity": 7,
"TokenValidityUnits": {
"AccessToken": "minutes",
"IdToken": "minutes",
"RefreshToken": "days"
},
"RefreshTokenRotation": {
"Feature": "ENABLED",
"RetryGracePeriodSeconds": 30
},
"EnableTokenRevocation": true,
"PreventUserExistenceErrors": "ENABLED",
"SupportedIdentityProviders": ["COGNITO", "Google"],
"WriteAttributes": ["family_name", "email"]
}
""".formatted(extendedPoolId));
JsonNode created = createResp.path("UserPoolClient");
String extendedClientId = created.path("ClientId").asText();
assertTrue(created.path("AllowedOAuthFlowsUserPoolClient").asBoolean());
assertEquals(1, created.path("AllowedOAuthFlows").size());
assertEquals("code", created.path("AllowedOAuthFlows").get(0).asText());
assertEquals(2, created.path("AllowedOAuthScopes").size());
assertEquals("d70b2ba36a8c4dc5a04a0451a31a1e12",
created.path("AnalyticsConfiguration").path("ApplicationId").asText());
assertEquals("my-external-id", created.path("AnalyticsConfiguration").path("ExternalId").asText());
assertEquals("arn:aws:iam::123456789012:role/test-cognitouserpool-role",
created.path("AnalyticsConfiguration").path("RoleArn").asText());
assertTrue(created.path("AnalyticsConfiguration").path("UserDataShared").asBoolean());
assertEquals(3, created.path("CallbackURLs").size());
assertEquals("https://example.com", created.path("DefaultRedirectURI").asText());
assertEquals(2, created.path("ExplicitAuthFlows").size());
assertEquals(15, created.path("AccessTokenValidity").asInt());
assertEquals(20, created.path("IdTokenValidity").asInt());
assertEquals(1, created.path("LogoutURLs").size());
assertEquals(3, created.path("ReadAttributes").size());
assertEquals(7, created.path("RefreshTokenValidity").asInt());
assertEquals("minutes", created.path("TokenValidityUnits").path("AccessToken").asText());
assertEquals("minutes", created.path("TokenValidityUnits").path("IdToken").asText());
assertEquals("days", created.path("TokenValidityUnits").path("RefreshToken").asText());
assertEquals("ENABLED", created.path("RefreshTokenRotation").path("Feature").asText());
assertEquals(30, created.path("RefreshTokenRotation").path("RetryGracePeriodSeconds").asInt());
assertTrue(created.path("EnableTokenRevocation").asBoolean());
assertEquals("ENABLED", created.path("PreventUserExistenceErrors").asText());
assertEquals(2, created.path("SupportedIdentityProviders").size());
assertEquals(2, created.path("WriteAttributes").size());
cognitoJson("UpdateUserPoolClient", """
{
"UserPoolId": "%s",
"ClientId": "%s",
"AllowedOAuthFlowsUserPoolClient": false,
"AllowedOAuthFlows": ["implicit"],
"AllowedOAuthScopes": ["email"],
"AnalyticsConfiguration": {
"ApplicationId": "updated-app-id",
"ExternalId": "updated-external-id",
"RoleArn": "arn:aws:iam::123456789012:role/updated-role",
"UserDataShared": false
},
"CallbackURLs": ["https://updated.example.com/callback"],
"DefaultRedirectURI": "https://updated.example.com/callback",
"ExplicitAuthFlows": ["ALLOW_USER_SRP_AUTH"],
"AccessTokenValidity": 25,
"IdTokenValidity": 30,
"LogoutURLs": ["https://updated.example.com/logout"],
"ReadAttributes": ["email"],
"RefreshTokenValidity": 14,
"TokenValidityUnits": {
"AccessToken": "minutes",
"IdToken": "minutes",
"RefreshToken": "days"
},
"RefreshTokenRotation": {
"Feature": "DISABLED",
"RetryGracePeriodSeconds": 0
},
"EnableTokenRevocation": false,
"PreventUserExistenceErrors": "LEGACY",
"SupportedIdentityProviders": ["COGNITO"],
"WriteAttributes": ["email"]
}
""".formatted(extendedPoolId, extendedClientId));
JsonNode describeResp = cognitoJson("DescribeUserPoolClient", """
{
"UserPoolId": "%s",
"ClientId": "%s"
}
""".formatted(extendedPoolId, extendedClientId));
JsonNode described = describeResp.path("UserPoolClient");
assertFalse(described.path("AllowedOAuthFlowsUserPoolClient").asBoolean());
assertEquals(1, described.path("AllowedOAuthFlows").size());
assertEquals("implicit", described.path("AllowedOAuthFlows").get(0).asText());
assertEquals(1, described.path("AllowedOAuthScopes").size());
assertEquals("email", described.path("AllowedOAuthScopes").get(0).asText());
assertEquals("updated-app-id", described.path("AnalyticsConfiguration").path("ApplicationId").asText());
assertEquals("updated-external-id", described.path("AnalyticsConfiguration").path("ExternalId").asText());
assertEquals("arn:aws:iam::123456789012:role/updated-role",
described.path("AnalyticsConfiguration").path("RoleArn").asText());
assertFalse(described.path("AnalyticsConfiguration").path("UserDataShared").asBoolean());
assertEquals(1, described.path("CallbackURLs").size());
assertEquals("https://updated.example.com/callback", described.path("DefaultRedirectURI").asText());
assertEquals(1, described.path("ExplicitAuthFlows").size());
assertEquals("ALLOW_USER_SRP_AUTH", described.path("ExplicitAuthFlows").get(0).asText());
assertEquals(25, described.path("AccessTokenValidity").asInt());
assertEquals(30, described.path("IdTokenValidity").asInt());
assertEquals(1, described.path("LogoutURLs").size());
assertEquals(1, described.path("ReadAttributes").size());
assertEquals(14, described.path("RefreshTokenValidity").asInt());
assertEquals("minutes", described.path("TokenValidityUnits").path("AccessToken").asText());
assertEquals("minutes", described.path("TokenValidityUnits").path("IdToken").asText());
assertEquals("days", described.path("TokenValidityUnits").path("RefreshToken").asText());
assertEquals("DISABLED", described.path("RefreshTokenRotation").path("Feature").asText());
assertEquals(0, described.path("RefreshTokenRotation").path("RetryGracePeriodSeconds").asInt());
assertFalse(described.path("EnableTokenRevocation").asBoolean());
assertEquals("LEGACY", described.path("PreventUserExistenceErrors").asText());
assertEquals(1, described.path("SupportedIdentityProviders").size());
assertEquals("COGNITO", described.path("SupportedIdentityProviders").get(0).asText());
assertEquals(1, described.path("WriteAttributes").size());
assertEquals("email", described.path("WriteAttributes").get(0).asText());
}
@Test
@Order(96)
void configuredTokenValidityControlsAuthResultAndJwtExpiry() throws Exception {
JsonNode poolResponse = cognitoJson("CreateUserPool", """
{
"PoolName": "TokenValidityPool"
}
""");
String validityPoolId = poolResponse.path("UserPool").path("Id").asText();
String validityUsername = "validity+" + UUID.randomUUID() + "@example.com";
String validityPassword = "Perm1234!";
JsonNode clientResp = cognitoJson("CreateUserPoolClient", """
{
"UserPoolId": "%s",
"ClientName": "token-validity-client",
"ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"],
"AccessTokenValidity": 15,
"IdTokenValidity": 20,
"RefreshTokenValidity": 7,
"TokenValidityUnits": {
"AccessToken": "minutes",
"IdToken": "minutes",
"RefreshToken": "days"
}
}
""".formatted(validityPoolId));
String validityClientId = clientResp.path("UserPoolClient").path("ClientId").asText();
cognitoAction("AdminCreateUser", """
{
"UserPoolId": "%s",
"Username": "%s",
"UserAttributes": [
{ "Name": "email", "Value": "%s" },
{ "Name": "email_verified", "Value": "true" }
],
"MessageAction": "SUPPRESS"
}
""".formatted(validityPoolId, validityUsername, validityUsername))
.then()
.statusCode(200);
cognitoAction("AdminSetUserPassword", """
{
"UserPoolId": "%s",
"Username": "%s",
"Password": "%s",
"Permanent": true
}
""".formatted(validityPoolId, validityUsername, validityPassword))
.then()
.statusCode(200);
JsonNode auth = cognitoJson("InitiateAuth", """
{
"ClientId": "%s",
"AuthFlow": "USER_PASSWORD_AUTH",
"AuthParameters": {
"USERNAME": "%s",
"PASSWORD": "%s"
}
}
""".formatted(validityClientId, validityUsername, validityPassword));
JsonNode result = auth.path("AuthenticationResult");
JsonNode accessPayload = decodeJwtPayload(result.path("AccessToken").asText());
JsonNode idPayload = decodeJwtPayload(result.path("IdToken").asText());
assertEquals(900, result.path("ExpiresIn").asInt());
assertEquals(900L, accessPayload.path("exp").asLong() - accessPayload.path("iat").asLong());
assertEquals(1200L, idPayload.path("exp").asLong() - idPayload.path("iat").asLong());
JsonNode refreshAuth = cognitoJson("GetTokensFromRefreshToken", """
{
"ClientId": "%s",
"RefreshToken": "%s"
}
""".formatted(validityClientId, result.path("RefreshToken").asText()));
JsonNode refreshResult = refreshAuth.path("AuthenticationResult");
JsonNode refreshedAccessPayload = decodeJwtPayload(refreshResult.path("AccessToken").asText());
JsonNode refreshedIdPayload = decodeJwtPayload(refreshResult.path("IdToken").asText());
assertEquals(900, refreshResult.path("ExpiresIn").asInt());
assertEquals(900L, refreshedAccessPayload.path("exp").asLong() - refreshedAccessPayload.path("iat").asLong());
assertEquals(1200L, refreshedIdPayload.path("exp").asLong() - refreshedIdPayload.path("iat").asLong());
}
private static Response cognitoAction(String action, String body) {
return given()
.header("X-Amz-Target", "AWSCognitoIdentityProviderService." + action)
@@ -268,6 +268,79 @@ class CognitoJsonHandlerTest {
assertTrue(emailAttr.get("Required").asBoolean(), "email must be required per the override");
}
// =========================================================================
// Issue #1306 — DescribeUserPoolClient extended configuration
// =========================================================================
@Test
void describeUserPoolClientReturnsExtendedConfigurationFields() {
ObjectNode poolReq = mapper.createObjectNode();
poolReq.put("PoolName", "client-pool");
JsonNode poolBody = (JsonNode) handler.handle("CreateUserPool", poolReq, "us-east-1").getEntity();
String poolId = poolBody.get("UserPool").get("Id").asText();
ObjectNode clientReq = mapper.createObjectNode();
clientReq.put("UserPoolId", poolId);
clientReq.put("ClientName", "extended-client");
clientReq.put("GenerateSecret", true);
clientReq.put("AllowedOAuthFlowsUserPoolClient", true);
clientReq.putArray("AllowedOAuthFlows").add("code");
clientReq.putArray("AllowedOAuthScopes").add("openid").add("email");
clientReq.putObject("AnalyticsConfiguration")
.put("ApplicationId", "d70b2ba36a8c4dc5a04a0451a31a1e12")
.put("ExternalId", "my-external-id")
.put("RoleArn", "arn:aws:iam::123456789012:role/test-cognitouserpool-role")
.put("UserDataShared", true);
clientReq.putArray("CallbackURLs").add("https://example.com").add("http://localhost");
clientReq.put("DefaultRedirectURI", "https://example.com");
clientReq.putArray("ExplicitAuthFlows").add("ALLOW_USER_AUTH").add("ALLOW_REFRESH_TOKEN_AUTH");
clientReq.put("AccessTokenValidity", 6);
clientReq.put("IdTokenValidity", 7);
clientReq.putArray("LogoutURLs").add("https://example.com/logout");
clientReq.put("PreventUserExistenceErrors", "ENABLED");
clientReq.putArray("ReadAttributes").add("email").add("address");
clientReq.put("RefreshTokenValidity", 8);
clientReq.putArray("SupportedIdentityProviders").add("COGNITO").add("Google");
clientReq.putObject("TokenValidityUnits")
.put("AccessToken", "hours")
.put("IdToken", "minutes")
.put("RefreshToken", "days");
clientReq.putArray("WriteAttributes").add("family_name").add("email");
clientReq.putObject("RefreshTokenRotation")
.put("Feature", "ENABLED")
.put("RetryGracePeriodSeconds", 30);
clientReq.put("EnableTokenRevocation", true);
JsonNode clientBody = (JsonNode) handler.handle("CreateUserPoolClient", clientReq, "us-east-1").getEntity();
String clientId = clientBody.get("UserPoolClient").get("ClientId").asText();
ObjectNode describeReq = mapper.createObjectNode();
describeReq.put("UserPoolId", poolId);
describeReq.put("ClientId", clientId);
JsonNode describeBody = (JsonNode) handler.handle("DescribeUserPoolClient", describeReq, "us-east-1").getEntity();
JsonNode client = describeBody.get("UserPoolClient");
assertTrue(client.get("AllowedOAuthFlowsUserPoolClient").asBoolean());
assertEquals("code", client.get("AllowedOAuthFlows").get(0).asText());
assertEquals("openid", client.get("AllowedOAuthScopes").get(0).asText());
assertEquals("d70b2ba36a8c4dc5a04a0451a31a1e12", client.get("AnalyticsConfiguration").get("ApplicationId").asText());
assertEquals("https://example.com", client.get("CallbackURLs").get(0).asText());
assertEquals("https://example.com", client.get("DefaultRedirectURI").asText());
assertEquals("ALLOW_USER_AUTH", client.get("ExplicitAuthFlows").get(0).asText());
assertEquals(6, client.get("AccessTokenValidity").asInt());
assertEquals(7, client.get("IdTokenValidity").asInt());
assertEquals("https://example.com/logout", client.get("LogoutURLs").get(0).asText());
assertEquals("ENABLED", client.get("PreventUserExistenceErrors").asText());
assertEquals("email", client.get("ReadAttributes").get(0).asText());
assertEquals(8, client.get("RefreshTokenValidity").asInt());
assertEquals("COGNITO", client.get("SupportedIdentityProviders").get(0).asText());
assertEquals("hours", client.get("TokenValidityUnits").get("AccessToken").asText());
assertEquals("family_name", client.get("WriteAttributes").get(0).asText());
assertEquals("ENABLED", client.get("RefreshTokenRotation").get("Feature").asText());
assertTrue(client.get("EnableTokenRevocation").asBoolean());
}
@Test
void tagResourceRejectsReservedKey() {
ObjectNode createRequest = mapper.createObjectNode();
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
@@ -120,6 +121,191 @@ class CognitoServiceTest {
assertEquals("ResourceConflictException", exception.getErrorCode());
}
// =========================================================================
// Issue #1306 — CreateUserPoolClient extended configuration
// =========================================================================
@Test
void createUserPoolClientPersistsExtendedConfiguration() {
UserPool pool = service.createUserPool(Map.of("PoolName", "ClientPool"), "us-east-1");
Map<String, Object> analyticsConfiguration = Map.of(
"ApplicationId", "d70b2ba36a8c4dc5a04a0451a31a1e12",
"ExternalId", "my-external-id",
"RoleArn", "arn:aws:iam::123456789012:role/test-cognitouserpool-role",
"UserDataShared", true
);
Map<String, String> tokenValidityUnits = Map.of(
"AccessToken", "hours",
"IdToken", "minutes",
"RefreshToken", "days"
);
Map<String, Object> refreshTokenRotation = Map.of(
"Feature", "ENABLED",
"RetryGracePeriodSeconds", 30
);
UserPoolClient client = service.createUserPoolClient(
pool.getId(),
"my-test-app-client",
true,
true,
List.of(" code ", "code"),
List.of("aws.cognito.signin.user.admin", "openid"),
analyticsConfiguration,
List.of("https://example.com", "http://localhost", "myapp://example"),
"https://example.com",
List.of("ALLOW_USER_AUTH", "ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_USER_PASSWORD_AUTH",
"ALLOW_REFRESH_TOKEN_AUTH"),
6,
6,
List.of("https://example.com/logout"),
"ENABLED",
List.of("email", "address", "preferred_username"),
6,
List.of("SignInWithApple", "MySSO"),
tokenValidityUnits,
List.of("family_name", "email"),
refreshTokenRotation,
true
);
assertNotNull(client.getClientId());
assertEquals(pool.getId(), client.getUserPoolId());
assertEquals("my-test-app-client", client.getClientName());
assertTrue(client.isGenerateSecret());
assertNotNull(client.getClientSecret());
assertEquals(1, client.getUserPoolClientSecrets().size());
assertTrue(client.isAllowedOAuthFlowsUserPoolClient());
assertEquals(List.of("code"), client.getAllowedOAuthFlows());
assertEquals(List.of("aws.cognito.signin.user.admin", "openid"), client.getAllowedOAuthScopes());
assertEquals(analyticsConfiguration, client.getAnalyticsConfiguration());
assertEquals(List.of("https://example.com", "http://localhost", "myapp://example"), client.getCallbackURLs());
assertEquals("https://example.com", client.getDefaultRedirectURI());
assertEquals(List.of("ALLOW_USER_AUTH", "ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_USER_PASSWORD_AUTH",
"ALLOW_REFRESH_TOKEN_AUTH"), client.getExplicitAuthFlows());
assertEquals(6, client.getAccessTokenValidity());
assertEquals(6, client.getIdTokenValidity());
assertEquals(List.of("https://example.com/logout"), client.getLogoutURLs());
assertEquals("ENABLED", client.getPreventUserExistenceErrors());
assertEquals(List.of("email", "address", "preferred_username"), client.getReadAttributes());
assertEquals(6, client.getRefreshTokenValidity());
assertEquals(List.of("SignInWithApple", "MySSO"), client.getSupportedIdentityProviders());
assertEquals(tokenValidityUnits, client.getTokenValidityUnits());
assertEquals(List.of("family_name", "email"), client.getWriteAttributes());
assertEquals(refreshTokenRotation, client.getRefreshTokenRotation());
assertEquals(Boolean.TRUE, client.getEnableTokenRevocation());
}
@Test
void createUserPoolClientGeneratesIdSecretTimestampsAndNormalizesLists() {
UserPool pool = service.createUserPool(Map.of("PoolName", "ClientPool"), "us-east-1");
UserPoolClient client = service.createUserPoolClient(
pool.getId(),
"basic-client",
true,
true,
List.of(" code ", "code", "implicit", "", "implicit"),
new ArrayList<>(java.util.Arrays.asList(" openid ", "openid", "email", null, "email"))
);
assertNotNull(client.getClientId());
assertEquals(26, client.getClientId().length());
assertTrue(client.getClientId().chars().allMatch(Character::isLetterOrDigit));
assertTrue(client.isGenerateSecret());
assertNotNull(client.getClientSecret());
assertFalse(client.getClientSecret().isBlank());
assertEquals(1, client.getUserPoolClientSecrets().size());
assertEquals(client.getClientSecret(), client.getUserPoolClientSecrets().get(0).getClientSecretValue());
assertTrue(client.getCreationDate() > 0);
assertTrue(client.getLastModifiedDate() > 0);
assertEquals(client.getCreationDate(), client.getLastModifiedDate());
assertEquals(List.of("code", "implicit"), client.getAllowedOAuthFlows());
assertEquals(List.of("openid", "email"), client.getAllowedOAuthScopes());
}
@Test
void createUserPoolClientAppliesAwsLikeDefaultsForSupportedIdentityProvidersAndTokenRevocation() {
UserPool pool = service.createUserPool(Map.of("PoolName", "ClientPool"), "us-east-1");
UserPoolClient client = service.createUserPoolClient(
pool.getId(),
"defaulted-client",
false,
false,
List.of(),
List.of()
);
assertEquals(List.of("COGNITO"), client.getSupportedIdentityProviders());
assertEquals(Boolean.TRUE, client.getEnableTokenRevocation());
}
@Test
void updateUserPoolClientAllowsClearingListFieldsWithEmptyArrays() {
UserPool pool = service.createUserPool(Map.of("PoolName", "ClientPool"), "us-east-1");
UserPoolClient client = service.createUserPoolClient(
pool.getId(),
"client",
false,
false,
List.of(),
List.of(),
null,
List.of("https://example.com"),
"https://example.com",
List.of("ALLOW_USER_AUTH"),
null,
null,
List.of("https://example.com/logout"),
null,
List.of("email"),
null,
List.of("COGNITO", "Google"),
null,
List.of("family_name"),
null,
null
);
service.updateUserPoolClient(
pool.getId(),
client.getClientId(),
null,
null,
null,
null,
null,
List.of(),
null,
List.of(),
null,
null,
List.of(),
null,
List.of(),
null,
List.of(),
null,
List.of(),
null,
null
);
UserPoolClient updated = service.describeUserPoolClient(pool.getId(), client.getClientId());
assertEquals(List.of(), updated.getCallbackURLs());
assertEquals(List.of(), updated.getExplicitAuthFlows());
assertEquals(List.of(), updated.getLogoutURLs());
assertEquals(List.of(), updated.getReadAttributes());
assertEquals(List.of(), updated.getSupportedIdentityProviders());
assertEquals(List.of(), updated.getWriteAttributes());
}
@Test
void createUserPoolWithBlankOverrideIdThrowsValidation() {
AwsException exception = assertThrows(
@@ -888,11 +1074,12 @@ class CognitoServiceTest {
assertNotNull(refreshToken);
// Should be parseable as base64 structured token
String decoded = new String(Base64.getDecoder().decode(refreshToken), StandardCharsets.UTF_8);
String[] parts = decoded.split("\\|", 4);
assertEquals(4, parts.length, "Refresh token should encode 4 pipe-separated fields");
String[] parts = decoded.split("\\|", 5);
assertEquals(5, parts.length, "Refresh token should encode 5 pipe-separated fields");
assertEquals(pool.getId(), parts[0]);
assertEquals("alice", parts[1]);
assertEquals(client.getClientId(), parts[2]);
assertFalse(parts[3].isBlank(), "Refresh token should encode its issued-at timestamp");
}
@Test
@@ -923,6 +1110,46 @@ class CognitoServiceTest {
service.getTokensFromRefreshToken(client.getClientId(), "not-a-valid-refresh-token"));
}
// =========================================================================
// Issue #1306 — Refresh token expiry respects client token validity
// =========================================================================
@Test
void getTokensFromRefreshTokenExpiredTokenThrows() {
UserPool pool = createPoolAndUser();
UserPoolClient client = service.createUserPoolClient(
pool.getId(),
"c",
false,
false,
List.of(),
List.of(),
null,
List.of(),
null,
List.of(),
null,
null,
List.of(),
null,
List.of(),
1,
List.of(),
Map.of("RefreshToken", "seconds"),
List.of(),
null,
null
);
long issuedAt = (System.currentTimeMillis() / 1000L) - 5;
String raw = pool.getId() + "|alice|" + client.getClientId() + "|" + issuedAt + "|" + java.util.UUID.randomUUID();
String expiredRefreshToken = Base64.getEncoder().withoutPadding().encodeToString(raw.getBytes(StandardCharsets.UTF_8));
AwsException exception = assertThrows(AwsException.class, () ->
service.getTokensFromRefreshToken(client.getClientId(), expiredRefreshToken));
assertEquals("NotAuthorizedException", exception.getErrorCode());
}
@Test
void refreshTokenAuthFlowReturnsNewTokens() {
UserPool pool = createPoolAndUser();