Unverified Commit 11f69efc authored by catsby's avatar catsby
Browse files

make RootToken an interface method

parent 59a2afe4
Branches unavailable
No related merge requests found
Showing with 19 additions and 31 deletions
+19 -31
......@@ -38,7 +38,6 @@ import (
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/sdk/testing/stepwise"
"github.com/hashicorp/vault/vault"
"github.com/y0ssar1an/q"
"golang.org/x/net/http2"
docker "github.com/docker/docker/client"
......@@ -67,7 +66,6 @@ type DockerCluster struct {
CAKeyPEM []byte
CACertPEMFile string
ID string
RootToken string
TempDir string
ClusterName string
RootCAs *x509.CertPool
......@@ -76,6 +74,8 @@ type DockerCluster struct {
CleanupFunc func()
SetupFunc func()
ClusterNodes []*DockerClusterNode
rootToken string
}
// Teardown stops all the containers.
......@@ -115,6 +115,11 @@ func (dc *DockerCluster) MountPath() string {
return dc.DriverOptions.MountPath
}
// RootToken returns the root token of the cluster, if set
func (dc *DockerCluster) RootToken() string {
return dc.rootToken
}
func (dc *DockerCluster) Name() string {
// TODO return UUID cluster name
return dc.PluginName
......@@ -234,11 +239,10 @@ func (rc *DockerCluster) Initialize(ctx context.Context) error {
}
rc.RecoveryKeys = append(rc.RecoveryKeys, raw)
}
rc.RootToken = resp.RootToken
q.Q("===> docker vault root token:", resp.RootToken)
rc.rootToken = resp.RootToken
// Write root token and barrier keys
err = ioutil.WriteFile(filepath.Join(rc.TempDir, "root_token"), []byte(rc.RootToken), 0755)
err = ioutil.WriteFile(filepath.Join(rc.TempDir, "root_token"), []byte(rc.rootToken), 0755)
if err != nil {
return err
}
......@@ -302,7 +306,7 @@ func (rc *DockerCluster) Initialize(ctx context.Context) error {
if i == 0 && !unsealed {
return fmt.Errorf("could not unseal node %d", i)
}
client.SetToken(rc.RootToken)
client.SetToken(rc.rootToken)
err = TestWaitHealthMatches(ctx, node.Client, func(health *api.HealthResponse) error {
if health.Sealed {
......@@ -580,7 +584,7 @@ func (n *DockerClusterNode) CreateAPIClient() (*api.Client, error) {
if err != nil {
return nil, err
}
apiClient.SetToken(n.Cluster.RootToken)
apiClient.SetToken(n.Cluster.RootToken())
return apiClient, nil
}
......
......@@ -112,7 +112,6 @@ type PreFlightFunc func(*logical.Request) error
// backend's HandleRequest method. Please see stepwise.Test and stepwise.Step
// for more information.
func Test(tt TestT, c TestCase) {
// q.Q("==> here in legacy testing.Test")
// We only run acceptance tests if an env var is set because they're
// slow and generally require some outside configuration.
if c.AcceptanceTest && os.Getenv(TestEnvVar) == "" {
......
......@@ -88,6 +88,10 @@ type StepDriver interface {
// BarrierKeys returns the keys used to seal/unseal the cluster. Used for
// debugging. TODO verify we should provide this
//BarrierKeys() [][]byte
// RootToken returns the root token of the cluster, used for administrative
// tasks
RootToken() string
}
// PluginType defines the types of plugins supported
......@@ -199,16 +203,6 @@ type Case struct {
// output.
func Run(tt TestT, c Case) {
tt.Helper()
q.Q("---------")
q.Q("Stepwise starting...")
q.Q("---------")
defer func() {
q.Q("---------")
q.Q("end")
q.Q("---------")
q.Q("")
}()
// We only run acceptance tests if an env var is set because they're
// slow and generally require some outside configuration.
if os.Getenv(TestEnvVar) == "" {
......@@ -226,7 +220,6 @@ func Run(tt TestT, c Case) {
// Run the PreCheck if we have it
if c.PreCheck != nil {
q.Q("--> running precheck")
c.PreCheck()
}
......@@ -236,12 +229,9 @@ func Run(tt TestT, c Case) {
var checkErr error
if c.Teardown != nil {
defer func(testError error) {
q.Q("## teardown error check err:", testError)
if testError != nil {
q.Q("## test check err is not nil, skipping tearing down")
return
}
q.Q("## test check err is nil, tearing down...")
err := c.Teardown()
if err != nil {
tt.Error("failed to tear down:", err)
......@@ -281,10 +271,10 @@ func Run(tt TestT, c Case) {
if err != nil {
tt.Fatal(err)
}
q.Q("===> docker vault root token:", c.Driver.RootToken())
// track all responses to revoke any secrets
var responses []*api.Secret
q.Q("mount path:", c.Driver.MountPath())
for i, step := range c.Steps {
// range is zero based, so add 1 for a human friendly output of steps.
// "index" here is only used for logging / output, and not to reference the
......@@ -304,17 +294,13 @@ func Run(tt TestT, c Case) {
// var lr *logical.Response
switch step.Operation {
case WriteOperation, UpdateOperation:
q.Q("===> Write/Update operation")
resp, err = client.Logical().Write(path, step.Data)
case ReadOperation:
q.Q("===> Read operation")
// resp, err = client.Logical().ReadWithData(path, step.Data)
resp, err = client.Logical().Read(path)
case ListOperation:
q.Q("===> List operation")
resp, err = client.Logical().List(path)
case DeleteOperation:
q.Q("===> Delete operation")
resp, err = client.Logical().Delete(path)
default:
panic("bad operation")
......@@ -322,7 +308,7 @@ func Run(tt TestT, c Case) {
if resp != nil {
responses = append(responses, resp)
}
// q.Q("test resp,err:", resp, err)
// if !s.Unauthenticated {
// // req.ClientToken = client.Token()
// // req.SetTokenEntry(&logical.TokenEntry{
......@@ -361,7 +347,6 @@ func Run(tt TestT, c Case) {
// // or not. Set the err to nil. If the error is a logical.ErrorResponse,
// // it will be handled later.
// if s.ErrorOk {
// q.Q("===> error ok, setting to nil")
// err = nil
// } else {
// // // If the error is not expected, fail right away.
......@@ -454,9 +439,9 @@ func Run(tt TestT, c Case) {
}
// failsafe - revoke by mount path
q.Q("==<> failsafe")
// TODO: should track all things mounted and revoke all paths to be sure?
// Maybe list mounts and try to revoke everything?
if err := client.Sys().RevokePrefix(c.Driver.MountPath()); err != nil {
q.Q("==<> error in failsafe:", err)
revokeErr := fmt.Errorf("[WARN] error revoking by prefix at tend of test: %w", err)
tt.Error(revokeErr)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment