Skip to content

Commit 8d659a9

Browse files
committed
test: assert IPv6 redirect is followed and cover the no-userinfo path
Capture the reissued response in the IPv6 userinfo-stripping test and assert the redirect was followed exactly once (status 200, two calls) so a regression that skips the reissue fails with a clear message instead of an IndexOutOfBoundsException on fake.requests[1]. Add a sibling test for an IPv6 literal Location with no userinfo, exercising the pass-through (no-rebuild) branch and confirming the bracketed host, port, path, and query survive there too.
1 parent dc50897 commit 8d659a9

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

sdk-core/src/test/kotlin/org/dexpace/sdk/core/http/pipeline/steps/RedirectStepTest.kt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,12 @@ class RedirectStepTest {
984984
.append(DefaultRedirectStep())
985985
.build()
986986

987-
pipeline.send(getRequest("https://api.example.com/v1"))
987+
val response = pipeline.send(getRequest("https://api.example.com/v1"))
988+
989+
// Pin that the redirect was actually followed exactly once, so a regression that skips
990+
// the reissue fails on these assertions rather than an IndexOutOfBoundsException below.
991+
assertEquals(200, response.status.code)
992+
assertEquals(2, fake.callCount)
988993

989994
val reissued = fake.requests[1]
990995
assertNull(reissued.url.userInfo, "userinfo must be stripped from an IPv6 Location")
@@ -997,6 +1002,39 @@ class RedirectStepTest {
9971002
assertEquals("https://[2001:db8::1]:8443/v2/resource?q=1", reissued.url.toString())
9981003
}
9991004

1005+
@Test
1006+
fun `IPv6 literal host without userinfo passes through with brackets preserved`() {
1007+
// The early-return branch (no userinfo to strip) hands the resolved IPv6 URI through
1008+
// unchanged via toURL(); confirm the bracketed host, port, path, and query survive on
1009+
// that non-rebuilding path too.
1010+
val fake =
1011+
FakeHttpClient()
1012+
.enqueue {
1013+
status(302).header(
1014+
"Location",
1015+
"https://[2001:db8::1]:8443/v2/resource?q=1",
1016+
)
1017+
}.enqueue { status(200) }
1018+
1019+
val pipeline =
1020+
HttpPipelineBuilder(fake)
1021+
.append(DefaultRedirectStep())
1022+
.build()
1023+
1024+
val response = pipeline.send(getRequest("https://api.example.com/v1"))
1025+
1026+
assertEquals(200, response.status.code)
1027+
assertEquals(2, fake.callCount)
1028+
1029+
val reissued = fake.requests[1]
1030+
assertNull(reissued.url.userInfo, "no userinfo was present")
1031+
assertEquals("[2001:db8::1]", reissued.url.host, "IPv6 literal host (with brackets) must be preserved")
1032+
assertEquals(8443, reissued.url.port, "port must be preserved")
1033+
assertEquals("/v2/resource", reissued.url.path, "path must be preserved")
1034+
assertEquals("q=1", reissued.url.query, "query must be preserved")
1035+
assertEquals("https://[2001:db8::1]:8443/v2/resource?q=1", reissued.url.toString())
1036+
}
1037+
10001038
// ----------------- Other non-3xx status codes don't trigger redirect -----------------
10011039

10021040
@Test

0 commit comments

Comments
 (0)