forked from unitycatalog/unitycatalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send non empty data as part of expired cookie in the header (unitycat…
…alog#750) **PR Checklist** - [ ] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Logout endpoint was implemented to expire cookie as part of the task unitycatalog#593 and changes are pushed as part of PR unitycatalog#678 but when the endpoint was called it gets hung indefinitely , On further investigation non empty data needs to be send as part of the header when we expire the cookie. This PR has the fix for the same. --------- Signed-off-by: sudharshanraja-db <[email protected]>
- Loading branch information
1 parent
d02929b
commit 737a07a
Showing
2 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
server/src/test/java/io/unitycatalog/server/service/AuthServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.unitycatalog.server.service; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.linecorp.armeria.client.WebClient; | ||
import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
import com.linecorp.armeria.common.HttpHeaderNames; | ||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.common.MediaType; | ||
import com.linecorp.armeria.common.RequestHeaders; | ||
import com.linecorp.armeria.common.RequestHeadersBuilder; | ||
import com.linecorp.armeria.common.auth.AuthToken; | ||
import io.unitycatalog.server.base.BaseServerTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class AuthServiceTest extends BaseServerTest { | ||
|
||
private static final String LOGOUT_ENDPOINT = "/api/1.0/unity-control/auth/logout"; | ||
private WebClient client; | ||
private static final String EMPTY_RESPONSE = "{}"; | ||
|
||
|
||
@BeforeEach | ||
public void setUp() { | ||
super.setUp(); | ||
String uri = serverConfig.getServerUrl(); | ||
String token = serverConfig.getAuthToken(); | ||
client = WebClient.builder(uri).auth(AuthToken.ofOAuth2(token)).build(); | ||
} | ||
|
||
@Test | ||
public void testLogout() { | ||
|
||
// Logout with cookie should return status as 200 and empty json content | ||
RequestHeaders headersWithCookie = buildRequestHeader(true); | ||
|
||
AggregatedHttpResponse response = client.execute(headersWithCookie).aggregate().join(); | ||
assertEquals(HttpStatus.OK, response.status()); | ||
assertThat(response.contentUtf8()).isEqualTo(EMPTY_RESPONSE); | ||
|
||
// Logout without cookie should return 200 status | ||
RequestHeaders headersWithoutCookie = buildRequestHeader(false); | ||
response = client.execute(headersWithoutCookie).aggregate().join(); | ||
assertEquals(HttpStatus.OK, response.status()); | ||
assertThat(response.contentUtf8()).isEqualTo(EMPTY_RESPONSE); | ||
} | ||
|
||
public RequestHeaders buildRequestHeader(boolean includeCookie) { | ||
RequestHeadersBuilder builder = | ||
RequestHeaders.builder() | ||
.method(HttpMethod.POST) | ||
.path(LOGOUT_ENDPOINT) | ||
.contentType(MediaType.JSON); | ||
|
||
if (includeCookie) { | ||
builder.add(HttpHeaderNames.COOKIE, "UC_TOKEN=1234"); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
} |