Skip to content

Commit 5381bf4

Browse files
committed
fix: remove resumption-token length cap
1 parent 394a044 commit 5381bf4

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/internal/ResumptionTokens.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* This class is an internal implementation detail and is not part of the supported API.
1515
*/
1616
final class ResumptionTokens {
17-
private static final int MAX_TOKEN_LENGTH = 4096;
1817
private static final Base64.Encoder ENCODER = Base64.getUrlEncoder().withoutPadding();
1918
private static final Base64.Decoder DECODER = Base64.getUrlDecoder();
2019

@@ -55,15 +54,12 @@ static String encode(String runId, String configKey, String variationKey,
5554
*
5655
* @param token the URL-safe Base64 token
5756
* @return the decoded fields
58-
* @throws IllegalArgumentException if the token is malformed, oversized, or missing required fields
57+
* @throws IllegalArgumentException if the token is malformed or missing required fields
5958
*/
6059
static Decoded decode(String token) {
6160
if (token == null) {
6261
throw new IllegalArgumentException("Resumption token must not be null");
6362
}
64-
if (token.length() > MAX_TOKEN_LENGTH) {
65-
throw new IllegalArgumentException("Resumption token exceeds maximum length of " + MAX_TOKEN_LENGTH + " characters");
66-
}
6763

6864
String json;
6965
try {

lib/sdk/server-ai/src/test/java/com/launchdarkly/sdk/server/ai/internal/ResumptionTokensTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ public void versionIsPreservedOnRoundTrip() {
8686
assertThat(ResumptionTokens.decode(token).getVersion(), is(1));
8787
}
8888

89+
// ---- large keys -----------------------------------------------------------
90+
91+
@Test
92+
public void roundTripsLongKeys() {
93+
String key = new String(new char[5000]).replace('\0', 'a');
94+
String token = ResumptionTokens.encode("run", key, null, 1, null);
95+
ResumptionTokens.Decoded d = ResumptionTokens.decode(token);
96+
assertThat(d.getConfigKey(), is(key));
97+
}
98+
8999
// ---- decode error handling ------------------------------------------------
90100

91101
@Test(expected = IllegalArgumentException.class)
92102
public void decodeRejectsNull() {
93103
ResumptionTokens.decode(null);
94104
}
95105

96-
@Test(expected = IllegalArgumentException.class)
97-
public void decodeRejectsOversizedToken() {
98-
// Build a token larger than 4096 bytes
99-
String largeValue = new String(new char[5000]).replace('\0', 'x');
100-
String json = "{\"runId\":\"" + largeValue + "\",\"configKey\":\"c\",\"version\":1}";
101-
String token = java.util.Base64.getUrlEncoder().withoutPadding()
102-
.encodeToString(json.getBytes(java.nio.charset.StandardCharsets.UTF_8));
103-
ResumptionTokens.decode(token);
104-
}
105-
106106
@Test(expected = IllegalArgumentException.class)
107107
public void decodeRejectsInvalidBase64() {
108108
ResumptionTokens.decode("not-valid-base64!!!!");

0 commit comments

Comments
 (0)