From e753b5fab93eaff05d21c1a7da02c4788658c258 Mon Sep 17 00:00:00 2001 From: afranken Date: Tue, 10 Dec 2024 18:09:29 +0100 Subject: [PATCH] Add test for cors headers for PUT --- .../adobe/testing/s3mock/its/PlainHttpIT.kt | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/PlainHttpIT.kt b/integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/PlainHttpIT.kt index fe6a87a86..72c4f50b4 100644 --- a/integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/PlainHttpIT.kt +++ b/integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/PlainHttpIT.kt @@ -176,19 +176,23 @@ internal class PlainHttpIT : S3TestBase() { @Test fun testCorsHeaders(testInfo: TestInfo) { val targetBucket = givenBucketV2(testInfo) - val httpOptions = HttpOptions("$serviceEndpoint/$targetBucket").apply { - this.setHeader(BasicHeader("Origin", "http://someurl.com")) - this.setHeader(BasicHeader("Access-Control-Request-Method", "GET")) - this.setHeader(BasicHeader("Access-Control-Request-Headers", "Content-Type, x-requested-with")) - } - httpClient.execute(httpOptions).use { - assertThat(it.getFirstHeader("Access-Control-Allow-Origin").value).isEqualTo("http://someurl.com") - assertThat(it.getFirstHeader("Access-Control-Allow-Methods").value).isEqualTo("GET") - assertThat(it.getFirstHeader("Access-Control-Allow-Headers").value) - .isEqualTo("Content-Type, x-requested-with") - assertThat(it.getFirstHeader("Access-Control-Allow-Credentials").value).isEqualTo("true") - assertThat(it.getFirstHeader("Allow").value).contains("GET") + arrayOf("GET", "PUT").forEach { method -> + val httpOptions = HttpOptions("$serviceEndpoint/$targetBucket").apply { + this.setHeader(BasicHeader("Origin", "http://someurl.com")) + this.setHeader(BasicHeader("Access-Control-Request-Method", method)) + this.setHeader(BasicHeader("Access-Control-Request-Headers", "Content-Type, x-requested-with")) + } + + httpClient.execute(httpOptions).use { + assertThat(it.statusLine.statusCode).isEqualTo(HttpStatus.SC_OK) + assertThat(it.getFirstHeader("Access-Control-Allow-Origin").value).isEqualTo("http://someurl.com") + assertThat(it.getFirstHeader("Access-Control-Allow-Methods").value).isEqualTo(method) + assertThat(it.getFirstHeader("Access-Control-Allow-Headers").value) + .isEqualTo("Content-Type, x-requested-with") + assertThat(it.getFirstHeader("Access-Control-Allow-Credentials").value).isEqualTo("true") + assertThat(it.getFirstHeader("Allow").value).contains(method) + } } }