Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Vault
Commits
11f69efc
Unverified
Commit
11f69efc
authored
5 years ago
by
catsby
Browse files
Options
Download
Email Patches
Plain Diff
make RootToken an interface method
parent
59a2afe4
Branches unavailable
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sdk/testing/stepwise/drivers/docker/docker.go
+11
-7
sdk/testing/stepwise/drivers/docker/docker.go
sdk/testing/stepwise/legacy.go
+0
-1
sdk/testing/stepwise/legacy.go
sdk/testing/stepwise/testing.go
+8
-23
sdk/testing/stepwise/testing.go
with
19 additions
and
31 deletions
+19
-31
sdk/testing/stepwise/drivers/docker/docker.go
+
11
-
7
View file @
11f69efc
...
...
@@ -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
.
R
ootToken
),
0755
)
err
=
ioutil
.
WriteFile
(
filepath
.
Join
(
rc
.
TempDir
,
"root_token"
),
[]
byte
(
rc
.
r
ootToken
),
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
.
R
ootToken
)
client
.
SetToken
(
rc
.
r
ootToken
)
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
}
...
...
This diff is collapsed.
Click to expand it.
sdk/testing/stepwise/legacy.go
+
0
-
1
View file @
11f69efc
...
...
@@ -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
)
==
""
{
...
...
This diff is collapsed.
Click to expand it.
sdk/testing/stepwise/testing.go
+
8
-
23
View file @
11f69efc
...
...
@@ -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
)
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help