Skip to content

Commit

Permalink
Warn about ignored password in auth command (like in login)
Browse files Browse the repository at this point in the history
We ignore the password when authenticating against Kubernetes in both
commands.

[cloudfoundry/korifi#2195]

Co-authored-by: Dave Walter <walterda@vmware.com>
  • Loading branch information
2 people authored and a-b committed Mar 25, 2023
1 parent 6439266 commit 5dfc4b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion command/v7/auth_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions command/v7/auth_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5dfc4b0

Please sign in to comment.