cstamas opened a new pull request, #2373: URL: https://github.com/apache/maven-resolver/pull/2373
The HTTP transports handled authentication with missing credentials differently, and partly wrongly. This affects two setups that are valid: - **No username:** an `Authentication` that carries no username, for example only an SSL context or hostname verifier. - **No password:** a username without a password, for example a token passed as the username. ### Before | Case | Apache | JDK | Jetty | URL | |---|---|---|---|---| | No username, server | **NPE** | **NPE** | **sent `null:null`** | ok | | No username, proxy | ok | **NPE** | **sent `null:null`** | ok | | No password, server | **sent `user:null`** → 401 | **NPE** | ok | **sent nothing** → 401 | | No password, proxy | **sent `user:null`** → 407 | **NPE** | ok | **sent nothing** → 407 | ### After All four transports follow the same rules: - **No username:** no Basic credentials are sent. - **No password:** `user:` is sent, with an empty password. ### What changed - **`JdkTransporter`:** builds `PasswordAuthentication` only when a username is present, and uses an empty password when none is given. Both server and proxy. - **`JettyTransporter`:** builds `BasicAuthentication` and the preemptive `BasicResult` only when a username is present, and uses an empty password when none is given. Both server and proxy. - **`DeferredCredentialsProvider` (Apache):** does not pass `null` credentials to `BasicCredentialsProvider` (that was the NPE), and turns a `null` password into an empty one. HttpClient 4 would otherwise encode it as `"null"`. - **`UrlTransporter`:** a username alone is now enough to authenticate. Before, it needed both username and password. Both server and proxy. ### Tests New regression tests in the shared `HttpTransporterTest`, so they run on all four transports: - `testGet_AuthenticationWithoutUsername` and `testGet_ProxyAuthenticationWithoutUsername`: no `Authorization` or `Proxy-Authorization` header is sent. - `testGet_AuthenticatedWithoutPassword` and `testGet_ProxyAuthenticatedWithoutPassword`: a username with an empty password is accepted. Without the fixes, 13 of these 16 test runs (4 tests on 4 transports) fail. With them, all pass. Note: #2372 (bearer token) touches the same JDK and Jetty blocks, so whichever PR is merged second needs a small rebase. --- To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0) check one of the following: - [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0) - [ ] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
