-
Notifications
You must be signed in to change notification settings - Fork 548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add acceptance tests for the password policy framework implementation #2113
Merged
fairclothjm
merged 4 commits into
VAULT-20749/mux-provider
from
VAULT-20750/password-policy-acc-tests
Dec 19, 2023
+125
−279
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package providertest | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-provider-vault/vault" | ||
) | ||
|
||
// ProtoV5ProviderFactories is a static map containing only the main provider instance | ||
var ( | ||
ProtoV5ProviderFactories map[string]func() (tfprotov5.ProviderServer, error) = protoV5ProviderFactoriesInit(context.Background(), "vault") | ||
) | ||
|
||
// testAccProtoV5ProviderFactories will return a map of provider servers | ||
// suitable for use as a resource.TestStep.ProtoV5ProviderFactories. | ||
// | ||
// When multiplexing providers, the schema and configuration handling must | ||
// exactly match between all underlying providers of the mux server. Mismatched | ||
// schemas will result in a runtime error. | ||
// see: https://developer.hashicorp.com/terraform/plugin/framework/migrating/mux | ||
// | ||
// Any tests that use this function will serve as a smoketest to verify the | ||
// provider schemas match 1-1 so that we may catch runtime errors. | ||
func protoV5ProviderFactoriesInit(ctx context.Context, providerNames ...string) map[string]func() (tfprotov5.ProviderServer, error) { | ||
factories := make(map[string]func() (tfprotov5.ProviderServer, error), len(providerNames)) | ||
|
||
for _, name := range providerNames { | ||
factories[name] = func() (tfprotov5.ProviderServer, error) { | ||
providerServerFactory, _, err := vault.ProtoV5ProviderServerFactory(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return providerServerFactory(), nil | ||
} | ||
} | ||
|
||
return factories | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Vault Auth Methods | ||
|
||
This package contains Vault [auth method API](https://developer.hashicorp.com/vault/api-docs/auth) resources and datasources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Vault Secrets Engine | ||
|
||
This package contains Vault [secrets engine API](https://developer.hashicorp.com/vault/api-docs/secret) resources and datasources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Vault System Backend | ||
|
||
This package contains Vault [system backend API](https://developer.hashicorp.com/vault/api-docs/system) resources and datasources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package sys_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-vault/internal/providertest" | ||
"github.com/hashicorp/terraform-provider-vault/testutil" | ||
) | ||
|
||
func TestAccPasswordPolicy(t *testing.T) { | ||
policyName := acctest.RandomWithPrefix("test-policy") | ||
resourceName := "vault_password_policy.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testutil.TestAccPreCheck(t) }, | ||
ProtoV5ProviderFactories: providertest.ProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccPasswordPolicyConfig(policyName, "length = 20\nrule \"charset\" {\n charset = \"abcde\"\n}\n"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", policyName), | ||
resource.TestCheckResourceAttrSet(resourceName, "policy"), | ||
), | ||
}, | ||
{ | ||
Config: testAccPasswordPolicyConfig(policyName, "length = 20\nrule \"charset\" {\n charset = \"abcde\"\n}\nrule \"charset\" {\n charset = \"1234567890\"\nmin-chars = 1\n}\n"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", policyName), | ||
resource.TestCheckResourceAttrSet(resourceName, "policy"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccPasswordPolicyConfig(policyName string, policy string) string { | ||
return fmt.Sprintf(` | ||
resource "vault_password_policy" "test" { | ||
name = "%s" | ||
policy = <<EOT | ||
%s | ||
EOT | ||
}`, policyName, policy) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context here.