api: auth: fix nil deref

By pulling in the fixes from c/common.  Add regression tests to make
sure it's not happening another time.  The error messages are not
ideal and should probably be optimized in the `/auth` endpoints directly
but it's already an improvement over a nil deref.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2023-04-11 09:56:29 +02:00
parent 0a588e7f31
commit b4cfc727be
6 changed files with 22 additions and 6 deletions

View File

@@ -242,14 +242,19 @@ func replaceURLByHostPort(repository string) (string, error) {
// using the -u and -p flags. If the username prompt is left empty, the
// displayed userFromAuthFile will be used instead.
func getUserAndPass(opts *LoginOptions, password, userFromAuthFile string) (user, pass string, err error) {
reader := bufio.NewReader(opts.Stdin)
username := opts.Username
if username == "" {
if opts.Stdin == nil {
return "", "", fmt.Errorf("cannot prompt for username without stdin")
}
if userFromAuthFile != "" {
fmt.Fprintf(opts.Stdout, "Username (%s): ", userFromAuthFile)
} else {
fmt.Fprint(opts.Stdout, "Username: ")
}
reader := bufio.NewReader(opts.Stdin)
username, err = reader.ReadString('\n')
if err != nil {
return "", "", fmt.Errorf("reading username: %w", err)

View File

@@ -1,4 +1,4 @@
package version
// Version is the version of the build.
const Version = "0.52.0"
const Version = "0.53.0-dev"