test(e2e): Refactor vault setup method (#3724)
* refact(e2e): Pass in boundary-controller-policy to method This allows any boundary-enterprise specific test packages to point to their own testdata directory * test(e2e): Fix assertion statement * refact(e2e): Move method call for clarity
This commit is contained in:
1 parent
e3e848d847
commit
94dd9e84fe
8 files changed
+21
-19
No files matched your search
@@ -45,7 +45,7 @@ func TestCliVaultCredentialStore(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", boundaryPolicyName),
|
||||
@@ -209,7 +209,7 @@ func TestApiVaultCredentialStore(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("secrets", "enable", "-path="+c.VaultSecretPath, "kv-v2"),
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestCliTcpTargetVaultConnectTarget(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", boundaryPolicyName),
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ func TestCliTcpTargetVaultGenericConnectTargetWithAuthzToken(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", boundaryPolicyName),
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ func TestCliTcpTargetVaultGenericConnectTargetWithSsh(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", boundaryPolicyName),
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestCliTcpTargetVaultGenericConnectTarget(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", boundaryPolicyName),
|
||||
|
||||
@@ -42,17 +42,9 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
|
||||
newTargetId := boundary.CreateNewTargetCli(
|
||||
t,
|
||||
ctx,
|
||||
newProjectId,
|
||||
c.TargetPort,
|
||||
target.WithAddress("openssh-server"),
|
||||
target.WithEgressWorkerFilter(fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagEgress)),
|
||||
)
|
||||
|
||||
// Configure vault
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", boundaryPolicyName),
|
||||
@@ -123,6 +115,16 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
|
||||
newCredentialLibraryId := newCredentialLibraryResult.Item.Id
|
||||
t.Logf("Created Credential Library: %s", newCredentialLibraryId)
|
||||
|
||||
// Create a target
|
||||
newTargetId := boundary.CreateNewTargetCli(
|
||||
t,
|
||||
ctx,
|
||||
newProjectId,
|
||||
c.TargetPort,
|
||||
target.WithAddress("openssh-server"),
|
||||
target.WithEgressWorkerFilter(fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagEgress)),
|
||||
)
|
||||
|
||||
// Add brokered credentials to target
|
||||
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialLibraryId)
|
||||
|
||||
@@ -166,7 +168,7 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
|
||||
),
|
||||
)
|
||||
require.Error(t, output.Err)
|
||||
require.Equal(t, output.ExitCode, 255)
|
||||
require.Equal(t, 255, output.ExitCode)
|
||||
t.Log("Successfully failed to connect to target with wrong worker filter")
|
||||
|
||||
// Try creating targets with an ingress worker filter. This should result in
|
||||
|
||||
@@ -235,7 +235,7 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
|
||||
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialsId)
|
||||
|
||||
// Create vault credentials
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t)
|
||||
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("secrets", "enable", "-path="+c.VaultSecretPath, "kv-v2"),
|
||||
)
|
||||
|
||||
@@ -25,9 +25,9 @@ type CreateTokenResponse struct {
|
||||
|
||||
// Setup verifies if appropriate credentials are set and adds the boundary controller
|
||||
// policy to vault. Returns the vault address.
|
||||
func Setup(t testing.TB) (boundaryPolicyName string, kvPolicyFilePath string) {
|
||||
func Setup(t testing.TB, boundaryControllerFilePath string) (boundaryPolicyName string, kvPolicyFilePath string) {
|
||||
// Set up boundary policy
|
||||
boundaryPolicyFilePath, err := filepath.Abs("testdata/boundary-controller-policy.hcl")
|
||||
boundaryPolicyFilePath, err := filepath.Abs(boundaryControllerFilePath)
|
||||
require.NoError(t, err)
|
||||
boundaryPolicyName = WritePolicy(t, context.Background(), boundaryPolicyFilePath)
|
||||
|
||||
|
||||
Reference in new issue
Block a user