From 7dce5396f50f2c9a1975efbd6610f52474628466 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Fri, 8 Dec 2023 14:35:04 -0800 Subject: [PATCH] testing/e2e: add API helper for u/pw credentials --- testing/internal/e2e/boundary/credential.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/testing/internal/e2e/boundary/credential.go b/testing/internal/e2e/boundary/credential.go index 3cd2edfda4..399b2a2d93 100644 --- a/testing/internal/e2e/boundary/credential.go +++ b/testing/internal/e2e/boundary/credential.go @@ -142,3 +142,19 @@ func CreateNewStaticCredentialJsonCli(t testing.TB, ctx context.Context, credent return newCredentialsId } + +// CreateNewStaticCredentialPasswordApi uses the API to create a new password credential in the +// provided static credential store. +// Returns the id of the new credential +func CreateNewStaticCredentialPasswordApi(t testing.TB, ctx context.Context, client *api.Client, credentialStoreId string, user string, password string) string { + c := credentials.NewClient(client) + newCredentialsResult, err := c.Create(ctx, "username_password", credentialStoreId, + credentials.WithUsernamePasswordCredentialUsername(user), + credentials.WithUsernamePasswordCredentialPassword(password), + ) + require.NoError(t, err) + newCredentialsId := newCredentialsResult.Item.Id + t.Logf("Created Username/Password Credentials: %s", newCredentialsId) + + return newCredentialsId +}