Skip to content

Commit cda3711

Browse files
authored
Merge pull request #505 from hpark-miovision/handle_auth_response_with_empty_token
Fix empty token handling in RawAuthResponse constructor
2 parents d281a69 + 0dffcd2 commit cda3711

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)