diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java index 42ab44d3..85239e40 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java @@ -434,7 +434,7 @@ public class Utils { } String pfxBase64 = base64Buffer(cert.pfx, cert.pfxPath); if (pfxBase64 != null) { - params.addProperty("pfx", pfxBase64); + jsonCert.addProperty("pfx", pfxBase64); } } catch (IOException e) { throw new PlaywrightException("Failed to read from file", e); diff --git a/playwright/src/test/java/com/microsoft/playwright/TestClientCertificates.java b/playwright/src/test/java/com/microsoft/playwright/TestClientCertificates.java index 98589bf2..161c2198 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestClientCertificates.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestClientCertificates.java @@ -1,7 +1,6 @@ package com.microsoft.playwright; import com.microsoft.playwright.options.ClientCertificate; -import com.microsoft.playwright.options.Proxy; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -120,6 +119,25 @@ public class TestClientCertificates extends TestBase { request.dispose(); } + @Test + public void passWithTrustedClientCertificatesPfx() { + APIRequest.NewContextOptions requestOptions = new APIRequest.NewContextOptions() + .setIgnoreHTTPSErrors(true) // TODO: remove once we can pass a custom CA. + .setClientCertificates(asList( + new ClientCertificate(customServer.origin) + .setPfxPath(asset("client-certificates/client/trusted/client_keystore.p12")) + .setPassphrase("passphrase"))); + + APIRequestContext request = playwright.request().newContext(requestOptions); + APIResponse response = request.get(customServer.url); + + assertEquals(customServer.url, response.url()); + assertEquals(200, response.status()); + assertTrue(response.text().contains("Hello CN=Alice, your certificate was issued by O=Client Certificate Demo,CN=localhost!"), response.text()); + + request.dispose(); + } + static boolean isWebKitMacOS() { return isWebKit() && isMac; } diff --git a/playwright/src/test/resources/client-certificates/client/trusted/client_keystore.p12 b/playwright/src/test/resources/client-certificates/client/trusted/client_keystore.p12 new file mode 100644 index 00000000..4bc4f2d0 Binary files /dev/null and b/playwright/src/test/resources/client-certificates/client/trusted/client_keystore.p12 differ