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
2 changes: 1 addition & 1 deletion src/main/kotlin/io/github/guidewire/oss/DataSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private fun postTestRun(endpoint: String, fernUrl: String, payload: String): Htt

var response = client.send(request, HttpResponse.BodyHandlers.ofString())
if (response.statusCode() == 307) {
val locationHeader = response.headers().firstValue("location")
val locationHeader = response.headers().firstValue("location").orElseThrow { RuntimeException("Location header not found in 307 response") }
response = postTestRun(fernUrl + locationHeader, fernUrl, payload)
}
return response
Expand Down
38 changes: 38 additions & 0 deletions src/test/kotlin/DataSenderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,44 @@ class DataSenderTest {
)
}

@Test
fun `sendTestRun should follow redirects`() {
// Setup mock server for initial redirect
stubFor(
post(urlEqualTo("/api/testrun/"))
.willReturn(
aResponse()
.withStatus(307)
.withHeader("Location", "/api/testrun/redirect")
)
)

// Setup mock server for the redirected endpoint
stubFor(
post(urlEqualTo("/api/testrun/redirect"))
.withHeader("Content-Type", equalTo("application/json"))
.willReturn(
aResponse()
.withStatus(200)
.withBody("{\"status\":\"success\"}")
)
)

// Test API call
val result = sendTestRun(testRun, "http://localhost:${wireMockServer.port()}", true)

// Verify
assertTrue(result.isSuccess)
verify(
postRequestedFor(urlEqualTo("/api/testrun/"))
.withHeader("Content-Type", equalTo("application/json"))
)
verify(
postRequestedFor(urlEqualTo("/api/testrun/redirect"))
.withHeader("Content-Type", equalTo("application/json"))
)
}

@Test
fun `sendTestRun should handle server errors`() {
// Setup mock server to return error
Expand Down
Loading