Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cwms-data-api/src/main/java/cwms/cda/ApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ public void init() {
ctx.json(errResponse);
})
.routes(this::configureRoutes)
.options("/*", ctx -> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this wildcards to all paths and sub paths and will also include all path versions when that comes along

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how it behaved in the tests. Hopefully it stays that way in future versions.

ctx.header("Access-Control-Allow-Origin", "*"); // Allow requests from any origin
ctx.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); // Specify allowed methods
ctx.header("Access-Control-Allow-Headers", "Content-Type, Authorization"); // Specify allowed headers
ctx.status(200); // Respond with a 200 OK status
})
.javalinServlet();
logger.atInfo().log("Javalin initialized.");
}
Expand Down
58 changes: 58 additions & 0 deletions cwms-data-api/src/test/java/cwms/cda/api/BaseLineTestIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cwms.cda.api;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import javax.servlet.http.HttpServletResponse;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import fixtures.CwmsDataApiSetupCallback;
import io.restassured.filter.log.LogDetail;

/**
* Location for tests that aren't specifically related to a given endpoint.
*/
@Tag("integration")
@ExtendWith(CwmsDataApiSetupCallback.class)
class BaseLineTestIT extends DataApiTestIT {

@ParameterizedTest
@ValueSource(strings = {"/blobs/", "/timeseries", "/levels"})
void test_options_handling_known_url(String url) throws Exception {
given()
.log().ifValidationFails(LogDetail.ALL,true)
.when()
.redirects().follow(true)
.redirects().max(3)
.options(url)
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.header("Access-Control-Allow-Methods", equalTo("GET, POST, PUT, DELETE, OPTIONS"))
.header("Access-Control-Allow-Headers", equalTo("Content-Type, Authorization"));
}

@ParameterizedTest
@ValueSource(strings = {"/flurgle/", "/blah/", "/levels-i-do-not-exist"})
void test_options_handling_unknown_url(String url) throws Exception {
given()
.log().ifValidationFails(LogDetail.ALL,true)
.when()
.redirects().follow(true)
.redirects().max(3)
.options(url)
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.header("Access-Control-Allow-Methods", nullValue())
.header("Access-Control-Allow-Headers", nullValue());
}
}
Loading