playwright-java
playwright-java copied to clipboard
[Bug]: api request with tls certificates is not working
Version
1.46.0
Steps to reproduce
Hello, we started using playwright with java for API Automation as the similar setup was being used by few other members for UI Automation. Everything was working fine until we hit this major bump (blocker) which we are not able to resolve from last few days.
Scenario is to generate access token while hitting an end-point using certificates which then used by other requests along side certificates.
Following is the code which is giving trouble and yielding HTTP 403 error : ` try(Playwright pw = Playwright.create()) { APIRequestContext apiRequest;
HashMap <String, String> headers = new HashMap<> (); headers.put("Content-Type","application/x-www-form-urlencoded"); headers.put("Accept", "application/json");
ClientCertificate certConf = new ClientCertificate ("*") .setCertPath(Paths.get("cert.cer")) .setKeyPath("Paths.get("Key.key")) .setPassphrase("");
apiRequest = pw.request().newContext(new APIRequest.NewContextOptions() .setBaseURL("<hostURL>") .setIgnoreHTTPErrors(true) .setExtraHTTPHeaders(headers) .setClientCertificates(Arrays.asList(certConf)));
FormData form = FormData.create() .set("cs1", "dsdsfdsfdsg") .set("cs2", "were-rewrwe");
APIResponse response = apiRequest.post("/token", RequestOptions.create().setForm(form)); System.out.println(response.status()); System.out.println(response.text()); } catch(Expcetion e) { e.printStackTrace(); } `
Expected behavior
Expected is 200 with valid Response data
Actual behavior
Getting 403 as the response status and text as FORBIDDEN
Additional context
Using same certificates in same config works with both Bruno/Postman as well other API library RESTAssured (while using relaxedHTTPSValidation() method inside RestAssured.config() while configuring the certificates in keystore())
Environment
- OS : Windows 11
- Memory : 16 GB
- Java : 1.8 & 17
- playwright : 1.46