From 8de6465b3159d9ad003571b3f42f9fc89904ebf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Thu, 19 Sep 2024 10:12:57 -0300 Subject: [PATCH] fix panic on native auth --- tsuru/auth/native.go | 9 +++++++++ tsuru/main.go | 1 + 2 files changed, 10 insertions(+) diff --git a/tsuru/auth/native.go b/tsuru/auth/native.go index 8f0aec57..2b57857f 100644 --- a/tsuru/auth/native.go +++ b/tsuru/auth/native.go @@ -52,6 +52,15 @@ func nativeLogin(ctx *cmd.Context) error { return err } defer response.Body.Close() + + if response.StatusCode != http.StatusOK { + body, err := io.ReadAll(response.Body) + if err != nil { + return err + } + return fmt.Errorf("failed to authenticate user: %s, %s", response.Status, string(body)) + } + result, err := io.ReadAll(response.Body) if err != nil { return err diff --git a/tsuru/main.go b/tsuru/main.go index 2463cdd3..6e2f6fa6 100644 --- a/tsuru/main.go +++ b/tsuru/main.go @@ -68,6 +68,7 @@ func buildManagerCustom(name string, stdout, stderr io.Writer) *cmd.Manager { fmt.Fprintln(os.Stderr, "trying to login again") c := &auth.Login{} loginErr := c.Run(&cmd.Context{ + Stdin: os.Stdin, Stderr: stderr, Stdout: stdout, })