Skip to content

Commit

Permalink
NP-46823 ApigatewayHandler, redirect response cors header (#495)
Browse files Browse the repository at this point in the history
* Redirects should contain header ACCESS_CONTROL_ALLOW_ORIGIN

* Bump version
  • Loading branch information
monaullah committed May 24, 2024
1 parent bec6b64 commit 74109eb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ private void sendRedirectResponse(RedirectException exception)

private GatewayResponse<Void> createRedirectResponse(RedirectException exception)
throws GatewayResponseSerializingException {
var responseHeaders = Map.of(HttpHeaders.LOCATION, exception.getLocation().toString());
var responseHeaders = Map.of(HttpHeaders.LOCATION, exception.getLocation().toString(),
ACCESS_CONTROL_ALLOW_ORIGIN, allowedOrigin);
return new GatewayResponse<>(EMPTY_BODY, responseHeaders, exception.getStatusCode(), isBase64Encoded,
objectMapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static no.unit.nva.testutils.RandomDataGenerator.objectMapper;
import static no.unit.nva.testutils.RandomDataGenerator.randomString;
import static no.unit.nva.testutils.RandomDataGenerator.randomUri;
import static no.unit.nva.testutils.TestHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
import static no.unit.nva.testutils.TestHeaders.WILDCARD;
import static nva.commons.apigateway.ApiGatewayHandler.REQUEST_ID;
import static nva.commons.apigateway.MediaTypes.APPLICATION_PROBLEM_JSON;
import static nva.commons.apigateway.RestConfig.defaultRestObjectMapper;
Expand Down Expand Up @@ -391,6 +393,7 @@ void handlerSendsRedirectionWhenItReceivesARedirectException() throws IOExceptio
var response = getResponse(Void.class, request, handler);
assertThat(response.getStatusCode(), is(equalTo(expectedRedirectStatusCode)));
assertThat(response.getHeaders(), hasEntry(HttpHeaders.LOCATION, expectedRedirectLocation.toString()));
assertThat(response.getHeaders(), hasEntry(ACCESS_CONTROL_ALLOW_ORIGIN, WILDCARD));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'com.github.bibsysdev'
version = '1.39.1'
version = '1.39.2'


java.sourceCompatibility = JavaVersion.VERSION_17 // source-code version and must be <= targetCompatibility
Expand Down

0 comments on commit 74109eb

Please sign in to comment.