* fix: Allow users to set OIDC maxAge value to 0 to require immediate reauth (#364) * fix: Allow users to set OIDC maxAge value to 0 to require immediate reauth Previously, setting 0 as a value for maxAge in an OIDC resource block would not update Boundary, as it was getting treated as a nil value in the provider. This fix addresses that issue, ensuring that both setting the value to 0 will require immediate reauthorisation, as well as removing the maxAge paramater defaulting the reauth time length to the TTL of the chose OIDC provider * Update doc strings, fix imports, and run go generate * add changes to CHANGELOG * spelling: host_set_plugin exmaple to example * Update target.md (#349) Update docs for Target resource removing `scope_id` from `boundary_host` resources to prevent error ``` ╷ │ Error: Unsupported argument │ │ on main.tf line 79, in resource "boundary_host" "foo": │ 79: scope_id = boundary_scope.project.id │ │ An argument named "scope_id" is not expected here. ``` * feature: add worker_filter option to Boundary Credential Store Vault (#375) * feature: add worker_filter option to Boundary Credential Store Vault * Update changelog * chore: update deps * small fixes for cherry-picks * downgrade hclog --------- Co-authored-by: mocofound <aharness@hashicorp.com> Co-authored-by: Steven Zamborsky <97125550+stevenzamborsky@users.noreply.github.com> Co-authored-by: Louis Ruch <louisruch@gmail.com>
134 lines
4.0 KiB
Go
134 lines
4.0 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package provider
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
"github.com/hashicorp/boundary/api/authmethods"
|
|
"github.com/hashicorp/boundary/testing/controller"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
|
|
)
|
|
|
|
const (
|
|
fooBaseAuthMethodDesc = "test auth method"
|
|
fooBaseAuthMethodDescUpdate = "test auth method update"
|
|
)
|
|
|
|
// TODO(malnick) - remove these tests after deprecating use of password params in
|
|
// favor of attributes map
|
|
var (
|
|
fooBaseAuthMethod = fmt.Sprintf(`
|
|
resource "boundary_auth_method" "foo" {
|
|
name = "test"
|
|
description = "%s"
|
|
type = "password"
|
|
scope_id = boundary_scope.org1.id
|
|
depends_on = [boundary_role.org1_admin]
|
|
}`, fooBaseAuthMethodDesc)
|
|
|
|
fooBaseAuthMethodUpdate = fmt.Sprintf(`
|
|
resource "boundary_auth_method" "foo" {
|
|
name = "test"
|
|
description = "%s"
|
|
type = "password"
|
|
scope_id = boundary_scope.org1.id
|
|
depends_on = [boundary_role.org1_admin]
|
|
}`, fooBaseAuthMethodDescUpdate)
|
|
)
|
|
|
|
func TestAccBaseAuthMethodPassword(t *testing.T) {
|
|
tc := controller.NewTestController(t, tcConfig...)
|
|
defer tc.Shutdown()
|
|
url := tc.ApiAddrs()[0]
|
|
|
|
var provider *schema.Provider
|
|
resource.Test(t, resource.TestCase{
|
|
ProviderFactories: providerFactories(&provider),
|
|
CheckDestroy: testAccCheckAuthMethodResourceDestroy(t, provider, passwordAuthMethodType),
|
|
Steps: []resource.TestStep{
|
|
{
|
|
// create
|
|
Config: testConfig(url, fooOrg, fooBaseAuthMethod),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("boundary_auth_method.foo", "description", fooBaseAuthMethodDesc),
|
|
resource.TestCheckResourceAttr("boundary_auth_method.foo", "name", "test"),
|
|
resource.TestCheckResourceAttr("boundary_auth_method.foo", "type", "password"),
|
|
testAccCheckBaseAuthMethodResourceExists(provider, "boundary_auth_method.foo"),
|
|
),
|
|
},
|
|
importStep("boundary_auth_method.foo"),
|
|
|
|
{
|
|
// update
|
|
Config: testConfig(url, fooOrg, fooBaseAuthMethodUpdate),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("boundary_auth_method.foo", "description", fooBaseAuthMethodDescUpdate),
|
|
resource.TestCheckResourceAttr("boundary_auth_method.foo", "name", "test"),
|
|
resource.TestCheckResourceAttr("boundary_auth_method.foo", "type", "password"),
|
|
testAccCheckBaseAuthMethodResourceExists(provider, "boundary_auth_method.foo"),
|
|
),
|
|
},
|
|
importStep("boundary_auth_method.foo"),
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckBaseAuthMethodResourceExists(testProvider *schema.Provider, name string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[name]
|
|
if !ok {
|
|
return fmt.Errorf("Not found: %s", name)
|
|
}
|
|
|
|
id := rs.Primary.ID
|
|
if id == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
md := testProvider.Meta().(*metaData)
|
|
|
|
amClient := authmethods.NewClient(md.client)
|
|
|
|
if _, err := amClient.Read(context.Background(), id); err != nil {
|
|
return fmt.Errorf("Got an error when reading auth method %q: %w", id, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckBaseAuthMethodResourceDestroy(t *testing.T, testProvider *schema.Provider) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
if testProvider.Meta() == nil {
|
|
t.Fatal("got nil provider metadata")
|
|
}
|
|
md := testProvider.Meta().(*metaData)
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
switch rs.Type {
|
|
case "boundary_auth_method":
|
|
id := rs.Primary.ID
|
|
|
|
amClient := authmethods.NewClient(md.client)
|
|
|
|
_, err := amClient.Read(context.Background(), id)
|
|
if apiErr := api.AsServerError(err); apiErr == nil || apiErr.Response().StatusCode() != http.StatusNotFound {
|
|
return fmt.Errorf("didn't get a 404 when reading destroyed auth method %q: %v", id, err)
|
|
}
|
|
|
|
default:
|
|
continue
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|