Repository navigation
Read the password to encrypt from the standard input when there is no console (fix #10230) - #13589
Conversation
gnodet-bot
left a comment
There was a problem hiding this comment.
Two minor style and documentation issues in the new readPassword helper.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
47935ec to
76af3a4
Compare
|
Both points addressed in 76af3a4. The Javadoc of |
gnodet-bot
left a comment
There was a problem hiding this comment.
Clean refactoring that correctly extracts the duplicated password-reading logic into a single readPassword method. The fail-fast behavior on missing passwords is a strict improvement over the old silent-empty-output behavior.
One remaining nit: Charset.defaultCharset() for stdin decoding.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
… console (fix apache#10230) With redirected streams System.console() is null, the password stayed null and --encrypt-master-password and --encrypt-password printed an empty {}. The password is now read from the first line of the standard input, and the command fails when there is none instead of encrypting nothing.
76af3a4 to
09a406b
Compare
|
Switched the decoding of the redirected input to UTF-8 in 09a406b, so it no longer depends on the locale, and added a test with non-ASCII characters ( |
gnodet-bot
left a comment
There was a problem hiding this comment.
Previous findings are all addressed. LGTM.
- Javadoc ✅ —
@param,@return,@throws IOException, and@throws IllegalStateExceptionall present and accurate. The note thatpromptis silently skipped in the non-interactive path is documented correctly. StandardCharsets.UTF_8✅ —InputStreamReadernow hardcodes UTF-8; the locale-dependentCharset.defaultCharset()issue is gone.- Test coverage ✅ — three tests cover redirected-input read, UTF-8 decode, and empty/blank rejection. Pre-fix validation:
testReadPasswordRejectsMissingPasswordandtestReadPasswordFromRedirectedInputtarget the exactIllegalStateExceptionandBufferedReader.readLine()paths introduced by the fix — both were failing before (old code returnednullsilently instead of throwing).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
… console (fix #10230) (#13589) `mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`. A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed. This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`. `MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests. --- 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) - [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
… console (fix apache#10230) (apache#13589) ## What and why `mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (apache#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`. ## How A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed. This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`. ## Tests `MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests. --- 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) - [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). (cherry picked from commit 73e6521) Ported to Maven 4: only --encrypt-password reads a password here, as --encrypt-master-password already fails with "not supported anymore"; the code is in compat/maven-embedder. The mvn launcher of Maven 4 does not have these options; mvnenc is the tool for it.
… console (fix #10230) (#13589) ## What and why `mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`. ## How A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed. This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`. ## Tests `MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests. --- 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) - [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). (cherry picked from commit 73e6521) Ported to Maven 4: only --encrypt-password reads a password here, as --encrypt-master-password already fails with "not supported anymore"; the code is in compat/maven-embedder. The mvn launcher of Maven 4 does not have these options; mvnenc is the tool for it.
… console (fix #10230) (#13589) ## What and why `mvn --encrypt-master-password` and `mvn --encrypt-password` read the password with `System.console()`. When the streams are redirected there is no console, the password stayed `null`, and the command printed an empty `{}`, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16: `echo myMasterPassword | mvn --encrypt-master-password` prints `{}`. ## How A new `MavenCli.readPassword` reads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails with `No password was provided` instead of encrypting nothing. The standard input is not closed. This is for 3.10.x. Maven 4 does not have these options any more, it has `mvnenc`. ## Tests `MavenCliTest` covers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, because `java.io.Console` is final. I also built the distribution of this branch: `echo myMasterPassword | mvn --encrypt-master-password` prints the encrypted `{...}` value, and with an empty input it fails with the new message. `maven-embedder` and its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests. --- 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) - [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). (cherry picked from commit 73e6521) Ported to Maven 4: only --encrypt-password reads a password here, as --encrypt-master-password already fails with "not supported anymore"; the code is in compat/maven-embedder. The mvn launcher of Maven 4 does not have these options; mvnenc is the tool for it.
What and why
mvn --encrypt-master-passwordandmvn --encrypt-passwordread the password withSystem.console(). When the streams are redirected there is no console, the password stayednull, and the command printed an empty{}, which makes it unusable from another program (#10230, MNG-8398). I could reproduce it on 3.9.16:echo myMasterPassword | mvn --encrypt-master-passwordprints{}.How
A new
MavenCli.readPasswordreads the password from the console and, when there is none, from the first line of the standard input. When no password can be read, or it is empty, the command now fails withNo password was providedinstead of encrypting nothing. The standard input is not closed.This is for 3.10.x. Maven 4 does not have these options any more, it has
mvnenc.Tests
MavenCliTestcovers reading from a redirected input and the missing and empty cases. The console path cannot be mocked, becausejava.io.Consoleis final. I also built the distribution of this branch:echo myMasterPassword | mvn --encrypt-master-passwordprints the encrypted{...}value, and with an empty input it fails with the new message.maven-embedderand its dependencies pass (45 tests) and spotless is clean. I did not run the integration tests.To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following: