Skip to content

Commit 5702b04

Browse files
tboergerChris Milson-Tokunaga
authored andcommitted
feat: add all supported alogithms for rsa-enc keystore (#1092)
* feat: add all supported alogithms for rsa-enc keystore Signed-off-by: Thomas Boerger <[email protected]> * feat: add all supported alogithms for java keystore Signed-off-by: Thomas Boerger <[email protected]> --------- Signed-off-by: Thomas Boerger <[email protected]>
1 parent 1a5b035 commit 5702b04

4 files changed

+33
-17
lines changed

provider/resource_keycloak_realm_keystore_java_keystore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package provider
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
89
"github.com/keycloak/terraform-provider-keycloak/keycloak"
910
)
1011

1112
var (
12-
keycloakRealmKeystoreJavaKeystoreAlgorithm = []string{"RS256", "RS384", "RS512", "PS256", "PS384", "PS512"}
13+
keycloakRealmKeystoreJavaKeystoreAlgorithm = []string{"AES", "EdDSA", "ES256", "ES384", "ES512", "HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "RSA1_5", "RSA-OAEP", "RSA-OAEP-256", "ECDH-ES", "ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW"}
1314
)
1415

1516
func resourceKeycloakRealmKeystoreJavaKeystore() *schema.Resource {

provider/resource_keycloak_realm_keystore_java_kyestore_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package provider
22

33
import (
44
"fmt"
5+
"regexp"
6+
"strconv"
7+
"testing"
8+
59
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
610
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
711
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
812
"github.com/keycloak/terraform-provider-keycloak/keycloak"
9-
"regexp"
10-
"strconv"
11-
"testing"
1213
)
1314

1415
func TestAccKeycloakRealmKeystoreJava_basic(t *testing.T) {
@@ -74,7 +75,7 @@ func TestAccKeycloakRealmKeystoreJava_algorithmValidation(t *testing.T) {
7475

7576
skipIfEnvSet(t, "CI") // temporary while I figure out how to put java keystore file to keycloak container in CI
7677

77-
algorithm := randomStringInSlice(keycloakRealmKeystoreRsaAlgorithm)
78+
algorithm := randomStringInSlice(keycloakRealmKeystoreJavaKeystoreAlgorithm)
7879

7980
resource.Test(t, resource.TestCase{
8081
ProviderFactories: testAccProviderFactories,

provider/resource_keycloak_realm_keystore_rsa.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package provider
22

33
import (
44
"context"
5+
56
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
89
"github.com/keycloak/terraform-provider-keycloak/keycloak"
910
)
1011

1112
var (
12-
keycloakRealmKeystoreRsaAlgorithm = []string{"RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "RSA-OAEP"}
13+
keycloakRealmKeystoreRsaAlgorithm = []string{"RS256", "RS384", "RS512", "PS256", "PS384", "PS512"}
14+
keycloakRealmKeystoreRsaEncAlgorithm = []string{"RSA1_5", "RSA-OAEP", "RSA-OAEP-256"}
1315
)
1416

1517
func resourceKeycloakRealmKeystoreRsa() *schema.Resource {
@@ -53,7 +55,7 @@ func resourceKeycloakRealmKeystoreRsa() *schema.Resource {
5355
"algorithm": {
5456
Type: schema.TypeString,
5557
Optional: true,
56-
ValidateFunc: validation.StringInSlice(keycloakRealmKeystoreRsaAlgorithm, false),
58+
ValidateFunc: validation.StringInSlice(append(keycloakRealmKeystoreRsaAlgorithm, keycloakRealmKeystoreRsaEncAlgorithm...), false),
5759
Default: "RS256",
5860
Description: "Intended algorithm for the key",
5961
},

provider/resource_keycloak_realm_keystore_rsa_test.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2223
func TestAccKeycloakRealmKeystoreRsa_basic(t *testing.T) {
@@ -78,7 +79,8 @@ func TestAccKeycloakRealmKeystoreRsa_createAfterManualDestroy(t *testing.T) {
7879
func 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
218230
resource "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(`
234245
data "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

Comments
 (0)