arturobernalg opened a new pull request, #13589:
URL: https://github.com/apache/maven/pull/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).
   


-- 
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]

Reply via email to