2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-04-25 19:39:04 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2016-04-25 19:39:04 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-10-18 18:46:00 +00:00
|
|
|
// TestDefaultSeal_Config exercises Shamir SetBarrierConfig and BarrierConfig.
|
|
|
|
// Note that this is a little questionable, because we're doing an init and
|
|
|
|
// unseal, then changing the barrier config using an internal function instead
|
|
|
|
// of an API. In other words if your change break this test, it might be more
|
|
|
|
// the test's fault than your changes.
|
2016-04-25 19:39:04 +00:00
|
|
|
func TestDefaultSeal_Config(t *testing.T) {
|
2019-10-18 18:46:00 +00:00
|
|
|
bc := &SealConfig{
|
|
|
|
SecretShares: 4,
|
|
|
|
SecretThreshold: 2,
|
|
|
|
}
|
2016-04-25 19:39:04 +00:00
|
|
|
core, _, _ := TestCoreUnsealed(t)
|
|
|
|
|
2019-06-20 19:14:58 +00:00
|
|
|
defSeal := NewDefaultSeal(nil)
|
2016-04-25 19:39:04 +00:00
|
|
|
defSeal.SetCore(core)
|
2018-01-19 06:44:44 +00:00
|
|
|
err := defSeal.SetBarrierConfig(context.Background(), bc)
|
2016-04-25 19:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
newBc, err := defSeal.BarrierConfig(context.Background())
|
2016-04-25 19:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(*bc, *newBc) {
|
|
|
|
t.Fatal("config mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, test without the benefit of the cached value in the seal
|
2019-06-20 19:14:58 +00:00
|
|
|
defSeal = NewDefaultSeal(nil)
|
2016-04-25 19:39:04 +00:00
|
|
|
defSeal.SetCore(core)
|
2018-01-19 06:44:44 +00:00
|
|
|
newBc, err = defSeal.BarrierConfig(context.Background())
|
2016-04-25 19:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(*bc, *newBc) {
|
|
|
|
t.Fatal("config mismatch")
|
|
|
|
}
|
|
|
|
}
|