diff --git a/client/src/main/java/org/asynchttpclient/Realm.java b/client/src/main/java/org/asynchttpclient/Realm.java index b41203dd1..7aa12f376 100644 --- a/client/src/main/java/org/asynchttpclient/Realm.java +++ b/client/src/main/java/org/asynchttpclient/Realm.java @@ -249,7 +249,8 @@ public int getMaxIterationCount() { /** * Returns the lazily computed and cached HTTP Basic authorization header for this immutable realm. - * Concurrent first calls may compute the same value more than once. + * Always encodes {@link #getPrincipal()} and {@link #getPassword()} as a Basic header, regardless + * of {@link #getScheme()}. Concurrent first calls may compute the same value more than once. * * @return the Basic authorization header * @since 3.0.12 diff --git a/client/src/test/java/org/asynchttpclient/util/AuthenticatorUtilsTest.java b/client/src/test/java/org/asynchttpclient/util/AuthenticatorUtilsTest.java index 4b542eb2e..36d29657e 100644 --- a/client/src/test/java/org/asynchttpclient/util/AuthenticatorUtilsTest.java +++ b/client/src/test/java/org/asynchttpclient/util/AuthenticatorUtilsTest.java @@ -39,6 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -66,6 +67,19 @@ void preemptiveBasicAuthorizationHeaderIsMemoizedOnRealm() { assertSame(first, proxy); } + @Test + void basicAuthHeaderCacheIsNotSharedAcrossRealms() { + Realm realmA = new Realm.Builder("user", "pass") + .setScheme(Realm.AuthScheme.BASIC) + .build(); + Realm realmB = new Realm.Builder("user", "pass") + .setScheme(Realm.AuthScheme.BASIC) + .build(); + + assertEquals(realmA.getBasicAuthHeader(), realmB.getBasicAuthHeader()); + assertNotSame(realmA.getBasicAuthHeader(), realmB.getBasicAuthHeader()); + } + @Test void computeBodyHashEmptyBody() throws Exception { Request request = new RequestBuilder("GET")