Skip to content

Commit 676c481

Browse files
Fix empty token handling in RawAuthResponse constructor
RawAuthResponse constructor first checks to ensure provided token is not null and is not empty. Existing implementation used != operator to detect non-empty string, thus failed to handle when provided token is actually empty, i.e. "". The token comparison logic in RawAuthResponse constructor is now updated to use isEmpty() instead, more specifically, (token != null && !token.isEmpty()) to properly handle "" case. New test case with sample json has been added for validation; the test prior to the change would fail with java.lang.ArrayIndexOutOfBoundsException.
1 parent 3a41831 commit 676c481

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

client/src/main/java/io/split/engine/sse/dtos/RawAuthResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public RawAuthResponse(boolean pushEnabled, String token) {
2222
this.pushEnabled = pushEnabled;
2323
this.token = token;
2424

25-
if (token != null && token != "") {
25+
if (token != null && !token.isEmpty()) {
2626
String tokenDecoded = decodeJwt();
2727
this.jwt = Json.fromJson(tokenDecoded, Jwt.class);
2828
} else {

client/src/test/java/io/split/engine/sse/AuthApiClientTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ public void authenticateWithPushDisabledShouldReturnSuccess() throws IOException
8585
Assert.assertTrue(StringUtils.isEmpty(result.getToken()));
8686
}
8787

88+
@Test
89+
public void authenticateWithPushDisabledWithEmptyTokenShouldReturnSuccess() throws IOException, IllegalAccessException,
90+
NoSuchMethodException, InvocationTargetException, URISyntaxException {
91+
CloseableHttpClient httpClientMock = TestHelper.mockHttpClient("streaming-auth-push-disabled-empty-token.json",
92+
HttpStatus.SC_OK);
93+
SplitHttpClient splitHttpClient = SplitHttpClientImpl.create(httpClientMock, new RequestDecorator(null),
94+
"qwerty", metadata());
95+
96+
AuthApiClient authApiClient = new AuthApiClientImp("www.split-test.io", splitHttpClient, TELEMETRY_STORAGE);
97+
AuthenticationResponse result = authApiClient.Authenticate();
98+
99+
Assert.assertFalse(result.isPushEnabled());
100+
Assert.assertTrue(StringUtils.isEmpty(result.getChannels()));
101+
Assert.assertFalse(result.isRetry());
102+
Assert.assertTrue(StringUtils.isEmpty(result.getToken()));
103+
}
104+
88105
@Test
89106
public void authenticateServerErrorShouldReturnErrorWithRetry() throws IOException, IllegalAccessException,
90107
NoSuchMethodException, InvocationTargetException, URISyntaxException {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"pushEnabled":false,"token":""}

0 commit comments

Comments
 (0)