Move policy test to keysutil package
This commit is contained in:
parent
6d1e1a3ba5
commit
c14a6c8666
|
@ -1,31 +1,30 @@
|
||||||
package transit
|
package keysutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/helper/keysutil"
|
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
keysArchive []keysutil.KeyEntry
|
keysArchive []KeyEntry
|
||||||
)
|
)
|
||||||
|
|
||||||
func resetKeysArchive() {
|
func resetKeysArchive() {
|
||||||
keysArchive = []keysutil.KeyEntry{keysutil.KeyEntry{}}
|
keysArchive = []KeyEntry{KeyEntry{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_KeyUpgrade(t *testing.T) {
|
func Test_KeyUpgrade(t *testing.T) {
|
||||||
testKeyUpgradeCommon(t, keysutil.NewLockManager(false))
|
testKeyUpgradeCommon(t, NewLockManager(false))
|
||||||
testKeyUpgradeCommon(t, keysutil.NewLockManager(true))
|
testKeyUpgradeCommon(t, NewLockManager(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testKeyUpgradeCommon(t *testing.T, lm *keysutil.LockManager) {
|
func testKeyUpgradeCommon(t *testing.T, lm *LockManager) {
|
||||||
storage := &logical.InmemStorage{}
|
storage := &logical.InmemStorage{}
|
||||||
p, lock, upserted, err := lm.GetPolicyUpsert(keysutil.PolicyRequest{
|
p, lock, upserted, err := lm.GetPolicyUpsert(PolicyRequest{
|
||||||
Storage: storage,
|
Storage: storage,
|
||||||
KeyType: keysutil.KeyType_AES256_GCM96,
|
KeyType: KeyType_AES256_GCM96,
|
||||||
Name: "test",
|
Name: "test",
|
||||||
})
|
})
|
||||||
if lock != nil {
|
if lock != nil {
|
||||||
|
@ -59,11 +58,11 @@ func testKeyUpgradeCommon(t *testing.T, lm *keysutil.LockManager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_ArchivingUpgrade(t *testing.T) {
|
func Test_ArchivingUpgrade(t *testing.T) {
|
||||||
testArchivingUpgradeCommon(t, keysutil.NewLockManager(false))
|
testArchivingUpgradeCommon(t, NewLockManager(false))
|
||||||
testArchivingUpgradeCommon(t, keysutil.NewLockManager(true))
|
testArchivingUpgradeCommon(t, NewLockManager(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testArchivingUpgradeCommon(t *testing.T, lm *keysutil.LockManager) {
|
func testArchivingUpgradeCommon(t *testing.T, lm *LockManager) {
|
||||||
resetKeysArchive()
|
resetKeysArchive()
|
||||||
|
|
||||||
// First, we generate a policy and rotate it a number of times. Each time
|
// First, we generate a policy and rotate it a number of times. Each time
|
||||||
|
@ -72,9 +71,9 @@ func testArchivingUpgradeCommon(t *testing.T, lm *keysutil.LockManager) {
|
||||||
// zero and latest, respectively
|
// zero and latest, respectively
|
||||||
|
|
||||||
storage := &logical.InmemStorage{}
|
storage := &logical.InmemStorage{}
|
||||||
p, lock, _, err := lm.GetPolicyUpsert(keysutil.PolicyRequest{
|
p, lock, _, err := lm.GetPolicyUpsert(PolicyRequest{
|
||||||
Storage: storage,
|
Storage: storage,
|
||||||
KeyType: keysutil.KeyType_AES256_GCM96,
|
KeyType: KeyType_AES256_GCM96,
|
||||||
Name: "test",
|
Name: "test",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -192,11 +191,11 @@ func testArchivingUpgradeCommon(t *testing.T, lm *keysutil.LockManager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Archiving(t *testing.T) {
|
func Test_Archiving(t *testing.T) {
|
||||||
testArchivingCommon(t, keysutil.NewLockManager(false))
|
testArchivingCommon(t, NewLockManager(false))
|
||||||
testArchivingCommon(t, keysutil.NewLockManager(true))
|
testArchivingCommon(t, NewLockManager(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testArchivingCommon(t *testing.T, lm *keysutil.LockManager) {
|
func testArchivingCommon(t *testing.T, lm *LockManager) {
|
||||||
resetKeysArchive()
|
resetKeysArchive()
|
||||||
|
|
||||||
// First, we generate a policy and rotate it a number of times. Each time // we'll ensure that we have the expected number of keys in the archive and
|
// First, we generate a policy and rotate it a number of times. Each time // we'll ensure that we have the expected number of keys in the archive and
|
||||||
|
@ -204,9 +203,9 @@ func testArchivingCommon(t *testing.T, lm *keysutil.LockManager) {
|
||||||
// zero and latest, respectively
|
// zero and latest, respectively
|
||||||
|
|
||||||
storage := &logical.InmemStorage{}
|
storage := &logical.InmemStorage{}
|
||||||
p, lock, _, err := lm.GetPolicyUpsert(keysutil.PolicyRequest{
|
p, lock, _, err := lm.GetPolicyUpsert(PolicyRequest{
|
||||||
Storage: storage,
|
Storage: storage,
|
||||||
KeyType: keysutil.KeyType_AES256_GCM96,
|
KeyType: KeyType_AES256_GCM96,
|
||||||
Name: "test",
|
Name: "test",
|
||||||
})
|
})
|
||||||
if lock != nil {
|
if lock != nil {
|
||||||
|
@ -272,7 +271,7 @@ func testArchivingCommon(t *testing.T, lm *keysutil.LockManager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkKeys(t *testing.T,
|
func checkKeys(t *testing.T,
|
||||||
p *keysutil.Policy,
|
p *Policy,
|
||||||
storage logical.Storage,
|
storage logical.Storage,
|
||||||
action string,
|
action string,
|
||||||
archiveVer, latestVer, keysSize int) {
|
archiveVer, latestVer, keysSize int) {
|
Loading…
Reference in New Issue