@@ -7,16 +7,17 @@ import (
77 "crypto/x509/pkix"
88 "encoding/pem"
99 "fmt"
10- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
11- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12- "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
13- "github.com/keycloak/terraform-provider-keycloak/keycloak"
1410 "log"
1511 "math/big"
1612 "regexp"
1713 "strings"
1814 "testing"
1915 "time"
16+
17+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
18+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
19+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
20+ "github.com/keycloak/terraform-provider-keycloak/keycloak"
2021)
2122
2223func TestAccKeycloakRealmKeystoreRsa_basic (t * testing.T ) {
@@ -78,7 +79,8 @@ func TestAccKeycloakRealmKeystoreRsa_createAfterManualDestroy(t *testing.T) {
7879func TestAccKeycloakRealmKeystoreRsa_algorithmValidation (t * testing.T ) {
7980 t .Parallel ()
8081
81- algorithm := randomStringInSlice (keycloakRealmKeystoreRsaAlgorithm )
82+ rsaAlgorithm := randomStringInSlice (keycloakRealmKeystoreRsaAlgorithm )
83+ rsaEncAlgorithm := randomStringInSlice (keycloakRealmKeystoreRsaEncAlgorithm )
8284 privateKey , certificate := generateKeyAndCert (2048 )
8385
8486 resource .Test (t , resource.TestCase {
@@ -87,12 +89,22 @@ func TestAccKeycloakRealmKeystoreRsa_algorithmValidation(t *testing.T) {
8789 CheckDestroy : testAccCheckRealmKeystoreRsaDestroy (),
8890 Steps : []resource.TestStep {
8991 {
90- Config : testKeycloakRealmKeystoreRsa_basicWithAttrValidation (algorithm , "algorithm" ,
92+ Config : testKeycloakRealmKeystoreRsa_basicWithAttrValidation ("rsa" , rsaAlgorithm , "algorithm" ,
9193 acctest .RandString (10 ), privateKey , certificate ),
9294 ExpectError : regexp .MustCompile ("expected algorithm to be one of .+ got .+" ),
9395 },
9496 {
95- Config : testKeycloakRealmKeystoreRsa_basicWithAttrValidation (algorithm , "algorithm" , algorithm ,
97+ Config : testKeycloakRealmKeystoreRsa_basicWithAttrValidation ("rsa" , rsaAlgorithm , "algorithm" , rsaAlgorithm ,
98+ privateKey , certificate ),
99+ Check : testAccCheckRealmKeystoreRsaExists ("keycloak_realm_keystore_rsa.realm_rsa" ),
100+ },
101+ {
102+ Config : testKeycloakRealmKeystoreRsa_basicWithAttrValidation ("rsa-enc" , rsaEncAlgorithm , "algorithm" ,
103+ acctest .RandString (10 ), privateKey , certificate ),
104+ ExpectError : regexp .MustCompile ("expected algorithm to be one of .+ got .+" ),
105+ },
106+ {
107+ Config : testKeycloakRealmKeystoreRsa_basicWithAttrValidation ("rsa-enc" , rsaEncAlgorithm , "algorithm" , rsaEncAlgorithm ,
96108 privateKey , certificate ),
97109 Check : testAccCheckRealmKeystoreRsaExists ("keycloak_realm_keystore_rsa.realm_rsa" ),
98110 },
@@ -216,7 +228,6 @@ data "keycloak_realm" "realm" {
216228}
217229
218230resource "keycloak_realm_keystore_rsa" "realm_rsa" {
219-
220231 name = "%s"
221232 realm_id = data.keycloak_realm.realm.id
222233
@@ -228,7 +239,7 @@ resource "keycloak_realm_keystore_rsa" "realm_rsa" {
228239 ` , testAccRealmUserFederation .Realm , rsaName , privateKey , certificate )
229240}
230241
231- func testKeycloakRealmKeystoreRsa_basicWithAttrValidation (rsaName , attr , val , privateKey ,
242+ func testKeycloakRealmKeystoreRsa_basicWithAttrValidation (provider , rsaName , attr , val , privateKey ,
232243 certificate string ) string {
233244 return fmt .Sprintf (`
234245data "keycloak_realm" "realm" {
@@ -243,6 +254,7 @@ resource "keycloak_realm_keystore_rsa" "realm_rsa" {
243254
244255 private_key = "%s"
245256 certificate = "%s"
257+ provider_id = "%s"
246258}
247- ` , testAccRealmUserFederation .Realm , rsaName , attr , val , privateKey , certificate )
259+ ` , testAccRealmUserFederation .Realm , rsaName , attr , val , privateKey , certificate , provider )
248260}
0 commit comments