Skip to content

Commit

Permalink
test(opensearch): fix weak password error (#1395)
Browse files Browse the repository at this point in the history
(cherry picked from commit c464bfd)
  • Loading branch information
Serpentiel committed Oct 25, 2023
1 parent a285887 commit 20281d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (
acc "github.com/aiven/terraform-provider-aiven/internal/acctest"
)

// openSearchSecurityPluginTestPassword is the password used for the OpenSearch Security Plugin Config tests.
const openSearchSecurityPluginTestPassword = "ThisIsATest123^=^"

// TestAccAivenOpenSearchSecurityPluginConfig_basic tests the basic functionality of the OpenSearch Security Plugin
// Config resource.
func TestAccAivenOpenSearchSecurityPluginConfig_basic(t *testing.T) {
Expand Down Expand Up @@ -53,14 +50,14 @@ resource "aiven_opensearch_security_plugin_config" "foo" {
admin_password = "%s"
depends_on = [aiven_opensearch.bar, aiven_opensearch_user.foo]
}`, os.Getenv("AIVEN_PROJECT_NAME"), rName, openSearchSecurityPluginTestPassword),
}`, os.Getenv("AIVEN_PROJECT_NAME"), rName, openSearchTestPassword),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "project", os.Getenv("AIVEN_PROJECT_NAME")),
resource.TestCheckResourceAttr(
resourceName, "service_name", fmt.Sprintf("test-acc-sr-os-sec-plugin-%s", rName),
),
resource.TestCheckResourceAttr(
resourceName, "admin_password", openSearchSecurityPluginTestPassword,
resourceName, "admin_password", openSearchTestPassword,
),
resource.TestCheckResourceAttr(resourceName, "available", "true"),
resource.TestCheckResourceAttr(resourceName, "enabled", "true"),
Expand Down Expand Up @@ -88,14 +85,14 @@ resource "aiven_opensearch_security_plugin_config" "foo" {
admin_password = "%s"
depends_on = [aiven_opensearch.bar]
}`, os.Getenv("AIVEN_PROJECT_NAME"), rName, openSearchSecurityPluginTestPassword),
}`, os.Getenv("AIVEN_PROJECT_NAME"), rName, openSearchTestPassword),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "project", os.Getenv("AIVEN_PROJECT_NAME")),
resource.TestCheckResourceAttr(
resourceName, "service_name", fmt.Sprintf("test-acc-sr-os-sec-plugin-%s", rName),
),
resource.TestCheckResourceAttr(
resourceName, "admin_password", openSearchSecurityPluginTestPassword,
resourceName, "admin_password", openSearchTestPassword,
),
resource.TestCheckResourceAttr(resourceName, "available", "true"),
resource.TestCheckResourceAttr(resourceName, "enabled", "true"),
Expand Down Expand Up @@ -129,7 +126,7 @@ resource "aiven_opensearch_security_plugin_config" "foo" {
admin_password = "%s"
depends_on = [aiven_opensearch.bar, aiven_opensearch_user.foo]
}`, os.Getenv("AIVEN_PROJECT_NAME"), rName, openSearchSecurityPluginTestPassword),
}`, os.Getenv("AIVEN_PROJECT_NAME"), rName, openSearchTestPassword),
ExpectError: regexp.MustCompile("when the OpenSearch Security Plugin is enabled"),
},
},
Expand Down
15 changes: 9 additions & 6 deletions internal/sdkprovider/service/opensearch/opensearch_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/aiven/terraform-provider-aiven/internal/schemautil"
)

// openSearchTestPassword is the password used for the OpenSearch tests.
const openSearchTestPassword = "ThisIsATest123^=^"

func TestAccAivenOpenSearchUser_basic(t *testing.T) {
resourceName := "aiven_opensearch_user.foo"
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
Expand All @@ -31,7 +34,7 @@ func TestAccAivenOpenSearchUser_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "service_name", fmt.Sprintf("test-acc-sr-%s", rName)),
resource.TestCheckResourceAttr(resourceName, "project", os.Getenv("AIVEN_PROJECT_NAME")),
resource.TestCheckResourceAttr(resourceName, "username", fmt.Sprintf("user-%s", rName)),
resource.TestCheckResourceAttr(resourceName, "password", "Test$1234"),
resource.TestCheckResourceAttr(resourceName, "password", openSearchTestPassword),
),
},
},
Expand Down Expand Up @@ -72,28 +75,28 @@ func testAccCheckAivenOpenSearchUserResourceDestroy(s *terraform.State) error {
func testAccOpenSearchUserResource(name string) string {
return fmt.Sprintf(`
data "aiven_project" "foo" {
project = "%s"
project = "%[1]s"
}
resource "aiven_opensearch" "bar" {
project = data.aiven_project.foo.project
cloud_name = "google-europe-west1"
plan = "startup-4"
service_name = "test-acc-sr-%s"
service_name = "test-acc-sr-%[2]s"
maintenance_window_dow = "monday"
maintenance_window_time = "10:00:00"
}
resource "aiven_opensearch_user" "foo" {
service_name = aiven_opensearch.bar.service_name
project = data.aiven_project.foo.project
username = "user-%s"
password = "Test$1234"
username = "user-%[2]s"
password = "%[3]s"
}
data "aiven_opensearch_user" "user" {
service_name = aiven_opensearch_user.foo.service_name
project = aiven_opensearch_user.foo.project
username = aiven_opensearch_user.foo.username
}`, os.Getenv("AIVEN_PROJECT_NAME"), name, name)
}`, os.Getenv("AIVEN_PROJECT_NAME"), name, openSearchTestPassword)
}

0 comments on commit 20281d2

Please sign in to comment.