secret/kv: Sort keys during list operation (#4845)

This commit is contained in:
Brian Kassouf 2018-06-27 11:48:59 -07:00 committed by GitHub
parent c2f8c0f4cd
commit 6607b425be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import (
"errors"
"math/big"
paths "path"
"sort"
"strings"
"github.com/hashicorp/golang-lru"
@ -205,6 +206,7 @@ func (s *encryptedKeyStorage) List(ctx context.Context, prefix string) ([]string
decryptedKeys[i] = plaintext
}
sort.Strings(decryptedKeys)
return decryptedKeys, nil
}

View file

@ -203,7 +203,7 @@ func TestEncryptedKeysStorage_List(t *testing.T) {
t.Fatal(err)
}
if len(keys) != 2 || !strutil.StrListContains(keys, "foo1/") || !strutil.StrListContains(keys, "foo") {
if len(keys) != 2 || keys[1] != "foo1/" || keys[0] != "foo" {
t.Fatalf("bad keys: %#v", keys)
}
@ -211,7 +211,7 @@ func TestEncryptedKeysStorage_List(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(keys) != 2 || !strutil.StrListContains(keys, "test") || !strutil.StrListContains(keys, "test/") {
if len(keys) != 2 || keys[0] != "test" || keys[1] != "test/" {
t.Fatalf("bad keys: %#v", keys)
}