-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move OIDC access token from cookie to special header (#3513)
* POC Signed-off-by: Pavel Jares <[email protected]> * fix Signed-off-by: Pavel Jares <[email protected]> * replace old constructors Signed-off-by: achmelo <[email protected]> * update IT Signed-off-by: achmelo <[email protected]> * fix Signed-off-by: Pavel Jares <[email protected]> * update IT Signed-off-by: achmelo <[email protected]> * fix IT Signed-off-by: Pavel Jares <[email protected]> * exception handler for no MF ID, unit test Signed-off-by: achmelo <[email protected]> * unit tests for request modification Signed-off-by: Pavel Jares <[email protected]> * license Signed-off-by: achmelo <[email protected]> * minor changes Signed-off-by: Pavel Jares <[email protected]> * lowercase header Signed-off-by: achmelo <[email protected]> * remove import Signed-off-by: achmelo <[email protected]> * remove authorization header from httpservletrequest Signed-off-by: achmelo <[email protected]> * test no ID and invalid token Signed-off-by: achmelo <[email protected]> * ignore cookies if auth cookie only remains Signed-off-by: achmelo <[email protected]> * expect no cookie in request Signed-off-by: achmelo <[email protected]> * fix sonar Signed-off-by: Pavel Jares <[email protected]> --------- Signed-off-by: Pavel Jares <[email protected]> Signed-off-by: achmelo <[email protected]> Co-authored-by: achmelo <[email protected]> (cherry picked from commit 6248308)
- Loading branch information
Showing
15 changed files
with
416 additions
and
83 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
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
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
99 changes: 99 additions & 0 deletions
99
...vice/src/test/java/org/zowe/apiml/cloudgatewayservice/filters/TokenFilterFactoryTest.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,99 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.cloudgatewayservice.filters; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.cloud.client.ServiceInstance; | ||
import org.springframework.cloud.gateway.filter.GatewayFilterChain; | ||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; | ||
import org.springframework.mock.web.server.MockServerWebExchange; | ||
import org.zowe.apiml.constants.ApimlConstants; | ||
import org.zowe.apiml.zaas.ZaasTokenResponse; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class TokenFilterFactoryTest { | ||
|
||
@Nested | ||
class RequestUpdate { | ||
|
||
private MockServerHttpRequest testRequestMutation(ZaasTokenResponse response) { | ||
MockServerHttpRequest request = MockServerHttpRequest.get("/url").build(); | ||
MockServerWebExchange exchange = MockServerWebExchange.from(request); | ||
|
||
new TokenFilterFactory(null, null, null) { | ||
@Override | ||
public String getEndpointUrl(ServiceInstance instance) { | ||
return null; | ||
} | ||
}.processResponse(exchange, mock(GatewayFilterChain.class), response); | ||
|
||
return request; | ||
} | ||
|
||
@Nested | ||
class ValidResponse { | ||
|
||
@Test | ||
void givenHeaderResponse_whenHandling_thenUpdateTheRequest() { | ||
MockServerHttpRequest request = testRequestMutation(ZaasTokenResponse.builder() | ||
.headerName("headerName") | ||
.token("headerValue") | ||
.build() | ||
); | ||
assertEquals("headerValue", request.getHeaders().getFirst("headerName")); | ||
} | ||
|
||
@Test | ||
void givenCookieResponse_whenHandling_thenUpdateTheRequest() { | ||
MockServerHttpRequest request = testRequestMutation(ZaasTokenResponse.builder() | ||
.cookieName("cookieName") | ||
.token("cookieValue") | ||
.build() | ||
); | ||
assertEquals("cookieName=\"cookieValue\"", request.getHeaders().getFirst("cookie")); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
class InvalidResponse { | ||
|
||
@Test | ||
void givenEmptyResponse_whenHandling_thenNoUpdate() { | ||
MockServerHttpRequest request = testRequestMutation(ZaasTokenResponse.builder() | ||
.token("jwt") | ||
.build() | ||
); | ||
assertEquals(1, request.getHeaders().size()); | ||
assertTrue(request.getHeaders().containsKey(ApimlConstants.AUTH_FAIL_HEADER)); | ||
} | ||
|
||
@Test | ||
void givenCookieAndHeaderInResponse_whenHandling_thenSetBoth() { | ||
MockServerHttpRequest request = testRequestMutation(ZaasTokenResponse.builder() | ||
.cookieName("cookie") | ||
.headerName("header") | ||
.token("jwt") | ||
.build() | ||
); | ||
assertEquals("jwt", request.getHeaders().getFirst("header")); | ||
assertEquals("cookie=\"jwt\"", request.getHeaders().getFirst("cookie")); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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
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
Oops, something went wrong.