From 5d795e6104b183748d43884f40b9c62869263991 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 20 Oct 2022 13:02:42 -0400 Subject: [PATCH] refact(e2e): Add support for authenticating as any user --- testing/internal/e2e/boundary/boundary.go | 18 ++++++++++++++---- .../e2e/credential/vault/vault_test.go | 2 +- .../e2e/host/aws/dynamichostcatalog_test.go | 2 +- .../host/static/connect_authz_token_test.go | 2 +- .../e2e/host/static/connect_ssh_test.go | 2 +- .../internal/e2e/host/static/connect_test.go | 2 +- .../e2e/host/static/session_cancel_test.go | 2 +- .../static/static_credential_store_test.go | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/testing/internal/e2e/boundary/boundary.go b/testing/internal/e2e/boundary/boundary.go index 313e4a57d..0afa643cd 100644 --- a/testing/internal/e2e/boundary/boundary.go +++ b/testing/internal/e2e/boundary/boundary.go @@ -4,6 +4,7 @@ package boundary import ( "context" "fmt" + "os" "testing" "github.com/hashicorp/boundary/api" @@ -59,16 +60,25 @@ func NewApiClient() (*api.Client, error) { return client, err } -// AuthenticateCli uses the cli to authenticate the specified Boundary instance. -func AuthenticateCli(t testing.TB) { +// AuthenticateAdminCli uses the cli to authenticate the specified Boundary instance as an admin +func AuthenticateAdminCli(t testing.TB) { c, err := loadConfig() require.NoError(t, err) + AuthenticateCli(t, c.AdminLoginName, c.AdminLoginPassword) +} + +// AuthenticateCli uses the cli to authenticate the specified Boundary instance +func AuthenticateCli(t testing.TB, loginName string, password string) { + c, err := loadConfig() + require.NoError(t, err) + + os.Setenv("E2E_TEST_BOUNDARY_PASSWORD", password) output := e2e.RunCommand(context.Background(), "boundary", "authenticate", "password", "-addr", c.Address, "-auth-method-id", c.AuthMethodId, - "-login-name", c.AdminLoginName, - "-password", "env://E2E_PASSWORD_ADMIN_PASSWORD", + "-login-name", loginName, + "-password", "env://E2E_TEST_BOUNDARY_PASSWORD", ) require.NoError(t, output.Err, string(output.Stderr)) } diff --git a/testing/internal/e2e/credential/vault/vault_test.go b/testing/internal/e2e/credential/vault/vault_test.go index 34774581e..5731f8352 100644 --- a/testing/internal/e2e/credential/vault/vault_test.go +++ b/testing/internal/e2e/credential/vault/vault_test.go @@ -52,7 +52,7 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId) diff --git a/testing/internal/e2e/host/aws/dynamichostcatalog_test.go b/testing/internal/e2e/host/aws/dynamichostcatalog_test.go index 9cf4ea694..372f15c7c 100644 --- a/testing/internal/e2e/host/aws/dynamichostcatalog_test.go +++ b/testing/internal/e2e/host/aws/dynamichostcatalog_test.go @@ -50,7 +50,7 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) diff --git a/testing/internal/e2e/host/static/connect_authz_token_test.go b/testing/internal/e2e/host/static/connect_authz_token_test.go index 3b91e264d..b9b97995e 100644 --- a/testing/internal/e2e/host/static/connect_authz_token_test.go +++ b/testing/internal/e2e/host/static/connect_authz_token_test.go @@ -23,7 +23,7 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId) diff --git a/testing/internal/e2e/host/static/connect_ssh_test.go b/testing/internal/e2e/host/static/connect_ssh_test.go index d74a6cd57..fbac406c4 100644 --- a/testing/internal/e2e/host/static/connect_ssh_test.go +++ b/testing/internal/e2e/host/static/connect_ssh_test.go @@ -23,7 +23,7 @@ func TestConnectTargetWithSshCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId) diff --git a/testing/internal/e2e/host/static/connect_test.go b/testing/internal/e2e/host/static/connect_test.go index 62c7c1e42..ef9a3e600 100644 --- a/testing/internal/e2e/host/static/connect_test.go +++ b/testing/internal/e2e/host/static/connect_test.go @@ -18,7 +18,7 @@ func TestConnectTargetCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId) diff --git a/testing/internal/e2e/host/static/session_cancel_test.go b/testing/internal/e2e/host/static/session_cancel_test.go index 249d45718..618cf93c8 100644 --- a/testing/internal/e2e/host/static/session_cancel_test.go +++ b/testing/internal/e2e/host/static/session_cancel_test.go @@ -21,7 +21,7 @@ func TestSessionCancelCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId) diff --git a/testing/internal/e2e/host/static/static_credential_store_test.go b/testing/internal/e2e/host/static/static_credential_store_test.go index c00e9d3fe..233ed4315 100644 --- a/testing/internal/e2e/host/static/static_credential_store_test.go +++ b/testing/internal/e2e/host/static/static_credential_store_test.go @@ -21,7 +21,7 @@ func TestStaticCredentialStoreCli(t *testing.T) { c, err := loadConfig() require.NoError(t, err) - boundary.AuthenticateCli(t) + boundary.AuthenticateAdminCli(t) newOrgId := boundary.CreateNewOrgCli(t) newProjectId := boundary.CreateNewProjectCli(t, newOrgId) newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, newProjectId)