2024-01-29 11:51:40 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package boundary
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
|
|
|
"github.com/hashicorp/boundary/api/authmethods"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-29 13:56:25 -08:00
|
|
|
// CreateNewAuthMethodApi creates a new password auth method using the Go api.
|
2024-01-29 11:51:40 -08:00
|
|
|
// Returns the id of the new auth method
|
|
|
|
|
func CreateNewAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
|
|
|
|
|
aClient := authmethods.NewClient(client)
|
|
|
|
|
newAMResult, err := aClient.Create(ctx, "password", scopeId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
authMethodId := newAMResult.Item.Id
|
|
|
|
|
t.Logf("Created Auth Method: %s", authMethodId)
|
|
|
|
|
return authMethodId
|
|
|
|
|
}
|
2024-01-29 13:56:25 -08:00
|
|
|
|
|
|
|
|
// CreateNewOidcAuthMethodApi creates a new oidc auth method using the Go api.
|
|
|
|
|
// Returns the id of the new auth method
|
|
|
|
|
func CreateNewOidcAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
|
|
|
|
|
aClient := authmethods.NewClient(client)
|
|
|
|
|
newAMResult, err := aClient.Create(ctx, "oidc", scopeId,
|
|
|
|
|
authmethods.WithOidcAuthMethodApiUrlPrefix("https://some_url_prefix"),
|
|
|
|
|
authmethods.WithOidcAuthMethodClientId("some_client_id"),
|
|
|
|
|
authmethods.WithOidcAuthMethodClientSecret("some_client_secret"),
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
authMethodId := newAMResult.Item.Id
|
|
|
|
|
t.Logf("Created Auth Method: %s", authMethodId)
|
|
|
|
|
return authMethodId
|
|
|
|
|
}
|