From 5dfc4b0df38a7355676f357a50ccdaf3ee332275 Mon Sep 17 00:00:00 2001 From: Matt Royal Date: Tue, 28 Feb 2023 16:46:44 -0800 Subject: [PATCH] Warn about ignored password in auth command (like in login) We ignore the password when authenticating against Kubernetes in both commands. [https://github.com/cloudfoundry/korifi/issues/2195] Co-authored-by: Dave Walter --- command/v7/auth_command.go | 9 ++++++++- command/v7/auth_command_test.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/command/v7/auth_command.go b/command/v7/auth_command.go index b2fd9e12c89..c64d604a072 100644 --- a/command/v7/auth_command.go +++ b/command/v7/auth_command.go @@ -118,11 +118,18 @@ func (cmd AuthCommand) getUsernamePassword() (string, string, error) { if password == "" { if envPassword := cmd.Config.CFPassword(); envPassword != "" { password = envPassword - } else if !cmd.Config.IsCFOnK8s() { + } else { passwordMissing = true } } + if cmd.Config.IsCFOnK8s() { + if !passwordMissing { + cmd.UI.DisplayWarning("Warning: password is ignored when authenticating against Kubernetes.") + } + passwordMissing = false + } + if userMissing || passwordMissing { return "", "", translatableerror.MissingCredentialsError{ MissingUsername: userMissing, diff --git a/command/v7/auth_command_test.go b/command/v7/auth_command_test.go index 7b7d595fc03..c30ac594a48 100644 --- a/command/v7/auth_command_test.go +++ b/command/v7/auth_command_test.go @@ -124,6 +124,24 @@ var _ = Describe("auth Command", func() { }) }) }) + + When("the password is given", func() { + BeforeEach(func() { + cmd.RequiredArgs.Username = "myuser" + cmd.RequiredArgs.Password = "mypassword" + }) + + When("authenticating against korifi", func() { + BeforeEach(func() { + fakeConfig.IsCFOnK8sReturns(true) + }) + + It("succeeds but warns", func() { + Expect(err).NotTo(HaveOccurred()) + Expect(testUI.Err).To(Say("Warning: password is ignored when authenticating against Kubernetes.")) + }) + }) + }) }) When("there is an auth error", func() {