Fix #392 by giving a more specific error
This commit is contained in:
parent
e9ef6cc255
commit
323b49f03d
|
@ -52,7 +52,7 @@ func (c *Core) enableCredential(entry *MountEntry) error {
|
||||||
case strings.HasPrefix(ent.Path, entry.Path):
|
case strings.HasPrefix(ent.Path, entry.Path):
|
||||||
fallthrough
|
fallthrough
|
||||||
case strings.HasPrefix(entry.Path, ent.Path):
|
case strings.HasPrefix(entry.Path, ent.Path):
|
||||||
return fmt.Errorf("path already in use")
|
return logical.CodedError(409, "path 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) {
|
func TestCore_EnableCredential_Token(t *testing.T) {
|
||||||
c, _, _ := TestCoreUnsealed(t)
|
c, _, _ := TestCoreUnsealed(t)
|
||||||
me := &MountEntry{
|
me := &MountEntry{
|
||||||
|
|
Loading…
Reference in New Issue