mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
Fix up PGP tests from earlier code fixes
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/vault"
|
"github.com/hashicorp/vault/vault"
|
||||||
@@ -58,7 +59,7 @@ func getPubKeyFiles(t *testing.T) (string, []string, error) {
|
|||||||
func parseDecryptAndTestUnsealKeys(t *testing.T,
|
func parseDecryptAndTestUnsealKeys(t *testing.T,
|
||||||
input, rootToken string,
|
input, rootToken string,
|
||||||
fingerprints bool,
|
fingerprints bool,
|
||||||
backupKeys map[string]string,
|
backupKeys map[string][]string,
|
||||||
core *vault.Core) {
|
core *vault.Core) {
|
||||||
decoder := base64.StdEncoding
|
decoder := base64.StdEncoding
|
||||||
priv1Bytes, err := decoder.DecodeString(privKey1)
|
priv1Bytes, err := decoder.DecodeString(privKey1)
|
||||||
@@ -112,9 +113,10 @@ func parseDecryptAndTestUnsealKeys(t *testing.T,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if backupKeys != nil && len(matchedFingerprints) != 0 {
|
if backupKeys != nil && len(matchedFingerprints) != 0 {
|
||||||
testMap := map[string]string{}
|
testMap := map[string][]string{}
|
||||||
for i, v := range matchedFingerprints {
|
for i, v := range matchedFingerprints {
|
||||||
testMap[v] = encodedKeys[i]
|
testMap[v] = append(testMap[v], encodedKeys[i])
|
||||||
|
sort.Strings(testMap[v])
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(testMap, backupKeys) {
|
if !reflect.DeepEqual(testMap, backupKeys) {
|
||||||
t.Fatalf("test map and backup map do not match, test map is\n%#v\nbackup map is\n%#v", testMap, backupKeys)
|
t.Fatalf("test map and backup map do not match, test map is\n%#v\nbackup map is\n%#v", testMap, backupKeys)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package command
|
|||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -223,7 +224,7 @@ func TestRekey_init_pgp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type backupStruct struct {
|
type backupStruct struct {
|
||||||
Keys map[string]string
|
Keys map[string][]string
|
||||||
}
|
}
|
||||||
backupVals := &backupStruct{}
|
backupVals := &backupStruct{}
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ func TestRekey_init_pgp(t *testing.T) {
|
|||||||
t.Fatalf("nonce mismatch between rekey and backed-up keys")
|
t.Fatalf("nonce mismatch between rekey and backed-up keys")
|
||||||
}
|
}
|
||||||
|
|
||||||
backupVals.Keys = resp.Data["keys"].(map[string]string)
|
backupVals.Keys = resp.Data["keys"].(map[string][]string)
|
||||||
|
|
||||||
// Now delete and try again; the values should be inaccessible
|
// Now delete and try again; the values should be inaccessible
|
||||||
req = logical.TestRequest(t, logical.DeleteOperation, "rekey/backup")
|
req = logical.TestRequest(t, logical.DeleteOperation, "rekey/backup")
|
||||||
@@ -262,5 +263,10 @@ func TestRekey_init_pgp(t *testing.T) {
|
|||||||
t.Fatalf("keys found when they should have been deleted")
|
t.Fatalf("keys found when they should have been deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort, because it'll be tested with DeepEqual later
|
||||||
|
for k, _ := range backupVals.Keys {
|
||||||
|
sort.Strings(backupVals.Keys[k])
|
||||||
|
}
|
||||||
|
|
||||||
parseDecryptAndTestUnsealKeys(t, ui.OutputWriter.String(), token, true, backupVals.Keys, core)
|
parseDecryptAndTestUnsealKeys(t, ui.OutputWriter.String(), token, true, backupVals.Keys, core)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user