Skip to content

Commit

Permalink
Add test for cors headers for PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
afranken committed Dec 10, 2024
1 parent d232514 commit e753b5f
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit e753b5f

Please sign in to comment.