|
|
@@ -24,41 +24,48 @@ import (
|
|
|
|
|
|
func TestGetSecretAddress(t *testing.T) {
|
|
|
t.Run("when the key is not addressing a path and uses the default path", func(t *testing.T) {
|
|
|
- path, key, err := getSecretAddress("/", "foo")
|
|
|
- assert.NoError(t, err)
|
|
|
+ path, key := getSecretAddress("/", "foo")
|
|
|
assert.Equal(t, "/", path)
|
|
|
assert.Equal(t, "foo", key)
|
|
|
|
|
|
- path, key, err = getSecretAddress("/foo", "bar")
|
|
|
- assert.NoError(t, err)
|
|
|
+ path, key = getSecretAddress("/foo", "bar")
|
|
|
assert.Equal(t, "/foo", path)
|
|
|
assert.Equal(t, "bar", key)
|
|
|
})
|
|
|
|
|
|
t.Run("when the key is addressing a path", func(t *testing.T) {
|
|
|
- path, key, err := getSecretAddress("/", "/foo/bar")
|
|
|
- assert.NoError(t, err)
|
|
|
+ path, key := getSecretAddress("/", "/foo/bar")
|
|
|
assert.Equal(t, path, "/foo")
|
|
|
assert.Equal(t, key, "bar")
|
|
|
})
|
|
|
|
|
|
t.Run("when the key is addressing a path and ignores the default path", func(t *testing.T) {
|
|
|
- path, key, err := getSecretAddress("/foo", "/bar/baz")
|
|
|
- assert.NoError(t, err)
|
|
|
+ path, key := getSecretAddress("/foo", "/bar/baz")
|
|
|
assert.Equal(t, "/bar", path)
|
|
|
assert.Equal(t, "baz", key)
|
|
|
})
|
|
|
|
|
|
t.Run("works with a nested directory", func(t *testing.T) {
|
|
|
- path, key, err := getSecretAddress("/", "/foo/bar/baz")
|
|
|
- assert.NoError(t, err)
|
|
|
+ path, key := getSecretAddress("/", "/foo/bar/baz")
|
|
|
assert.Equal(t, "/foo/bar", path)
|
|
|
assert.Equal(t, "baz", key, "baz")
|
|
|
})
|
|
|
|
|
|
- t.Run("fails when the key is a folder but does not begin with a slash", func(t *testing.T) {
|
|
|
- _, _, err := getSecretAddress("/", "bar/baz")
|
|
|
- assert.Error(t, err)
|
|
|
- assert.Equal(t, err.Error(), "a secret key referencing a folder must start with a '/' as it is an absolute path, key: bar/baz")
|
|
|
+ t.Run("relative key joins onto the default path", func(t *testing.T) {
|
|
|
+ path, key := getSecretAddress("/secrets/mysql-core", "azure/admin-users")
|
|
|
+ assert.Equal(t, "/secrets/mysql-core/azure", path)
|
|
|
+ assert.Equal(t, "admin-users", key)
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("relative key with default root path", func(t *testing.T) {
|
|
|
+ path, key := getSecretAddress("/", "azure/admin-users")
|
|
|
+ assert.Equal(t, "/azure", path)
|
|
|
+ assert.Equal(t, "admin-users", key)
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("relative key with nested folders", func(t *testing.T) {
|
|
|
+ path, key := getSecretAddress("/scope", "a/b/c/name")
|
|
|
+ assert.Equal(t, "/scope/a/b/c", path)
|
|
|
+ assert.Equal(t, "name", key)
|
|
|
})
|
|
|
}
|