Merge pull request #525 from ctennis/fix392
Fix #392 by giving a more specific error
This commit is contained in:
commit
b812e29c83
|
@ -52,7 +52,7 @@ func (c *Core) enableCredential(entry *MountEntry) error {
|
|||
case strings.HasPrefix(ent.Path, entry.Path):
|
||||
fallthrough
|
||||
case strings.HasPrefix(entry.Path, ent.Path):
|
||||
return fmt.Errorf("path already in use")
|
||||
return logical.CodedError(409, "path is already in use")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,33 @@ func TestCore_EnableCredential(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCore_EnableCredential_twice_409(t *testing.T) {
|
||||
c, _, _ := TestCoreUnsealed(t)
|
||||
c.credentialBackends["noop"] = func(*logical.BackendConfig) (logical.Backend, error) {
|
||||
return &NoopBackend{}, nil
|
||||
}
|
||||
|
||||
me := &MountEntry{
|
||||
Path: "foo",
|
||||
Type: "noop",
|
||||
}
|
||||
err := c.enableCredential(me)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// 2nd should be a 409 error
|
||||
err2 := c.enableCredential(me)
|
||||
switch err2.(type) {
|
||||
case logical.HTTPCodedError:
|
||||
if err2.(logical.HTTPCodedError).Code() != 409 {
|
||||
t.Fatalf("invalid code given")
|
||||
}
|
||||
default:
|
||||
t.Fatalf("expected a different error type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCore_EnableCredential_Token(t *testing.T) {
|
||||
c, _, _ := TestCoreUnsealed(t)
|
||||
me := &MountEntry{
|
||||
|
|
Loading…
Reference in New Issue