mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-20 00:13:53 -05:00
Check for invalid token when authing via cli
If a token does not exist, the Read request returns without an error, but the secret returned is `nil`, so we need to check for that. Closes #75
This commit is contained in:
parent
f61e0b120a
commit
e4ffd4ac27
2 changed files with 27 additions and 0 deletions
|
|
@ -151,6 +151,10 @@ func (c *AuthCommand) Run(args []string) int {
|
|||
"Error validating token: %s", err))
|
||||
return 1
|
||||
}
|
||||
if secret == nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error: Invalid token"))
|
||||
return 1
|
||||
}
|
||||
|
||||
// Get the policies we have
|
||||
policiesRaw, ok := secret.Data["policies"]
|
||||
|
|
|
|||
|
|
@ -82,6 +82,29 @@ func TestAuth_token(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAuth_badToken(t *testing.T) {
|
||||
core, _, _ := vault.TestCoreUnsealed(t)
|
||||
ln, addr := http.TestServer(t, core)
|
||||
defer ln.Close()
|
||||
|
||||
testAuthInit(t)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &AuthCommand{
|
||||
Meta: Meta{
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-address", addr,
|
||||
"not-a-valid-token",
|
||||
}
|
||||
if code := c.Run(args); code != 1 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuth_method(t *testing.T) {
|
||||
core, _, token := vault.TestCoreUnsealed(t)
|
||||
ln, addr := http.TestServer(t, core)
|
||||
|
|
|
|||
Loading…
Reference in a new issue