From e73f90ef3a0e173595e4e31e5ae02497664506a5 Mon Sep 17 00:00:00 2001 From: "roberto.neto" Date: Fri, 15 Sep 2023 10:16:23 -0300 Subject: [PATCH] rsa_public_key of jwt consumer is nullable --- kong/resource_kong_consumer_jwt_auth.go | 6 ++-- kong/resource_kong_consumer_jwt_auth_test.go | 34 +++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/kong/resource_kong_consumer_jwt_auth.go b/kong/resource_kong_consumer_jwt_auth.go index 909f76d..408ba06 100644 --- a/kong/resource_kong_consumer_jwt_auth.go +++ b/kong/resource_kong_consumer_jwt_auth.go @@ -59,10 +59,10 @@ func resourceKongConsumerJWTAuth() *schema.Resource { func resourceKongConsumerJWTAuthCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { JWTAuthRequest := &kong.JWTAuth{ - Algorithm: kong.String(d.Get("algorithm").(string)), - Key: kong.String(d.Get("key").(string)), + Algorithm: readStringPtrFromResource(d, "algorithm"), + Key: readStringPtrFromResource(d, "key"), RSAPublicKey: readStringPtrFromResource(d, "rsa_public_key"), - Secret: kong.String(d.Get("secret").(string)), + Secret: readStringPtrFromResource(d, "secret"), Tags: readStringArrayPtrFromResource(d, "tags"), } diff --git a/kong/resource_kong_consumer_jwt_auth_test.go b/kong/resource_kong_consumer_jwt_auth_test.go index 9fceea4..f510c21 100644 --- a/kong/resource_kong_consumer_jwt_auth_test.go +++ b/kong/resource_kong_consumer_jwt_auth_test.go @@ -3,6 +3,7 @@ package kong import ( "context" "fmt" + "regexp" "testing" "github.com/kong/go-kong/kong" @@ -43,17 +44,16 @@ func TestAccJWTAuth(t *testing.T) { ), }, { - Config: testCreateJWTAuthConfigRsaPublicKeyNull, + Config: testCreateJWTAuthConfigDefaults, Check: resource.ComposeTestCheckFunc( - testAccCheckJWTAuthExists("kong_consumer_jwt_auth.consumer_jwt_config2"), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "algorithm", "HS256"), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "key", "my_key"), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "secret", "my_secret"), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "rsa_public_key", ""), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "tags.#", "2"), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "tags.0", "foo"), - resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config2", "tags.1", "bar"), + testAccCheckJWTAuthExists("kong_consumer_jwt_auth.consumer_jwt_config_defaults"), + resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config_defaults", "algorithm", "HS256"), + resource.TestMatchResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config_defaults", "key", regexp.MustCompile(".+")), + resource.TestMatchResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config_defaults", "secret", regexp.MustCompile(".+")), + resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config_defaults", "rsa_public_key", ""), + resource.TestCheckResourceAttr("kong_consumer_jwt_auth.consumer_jwt_config_defaults", "tags.#", "0"), ), + ExpectNonEmptyPlan: true, }, }, }) @@ -179,17 +179,13 @@ resource "kong_consumer_jwt_auth" "consumer_jwt_config" { tags = ["foo"] } ` -const testCreateJWTAuthConfigRsaPublicKeyNull = ` -resource "kong_consumer" "my_consumer2" { - username = "User2" - custom_id = "456" +const testCreateJWTAuthConfigDefaults = ` +resource "kong_consumer" "consumer_jwt_defaults" { + username = "consumer_jwt" + custom_id = "666" } -resource "kong_consumer_jwt_auth" "consumer_jwt_config2" { - consumer_id = "${kong_consumer.my_consumer2.id}" - algorithm = "HS256" - key = "my_key" - secret = "my_secret" - tags = ["foo", "bar"] +resource "kong_consumer_jwt_auth" "consumer_jwt_config_defaults" { + consumer_id = "${kong_consumer.consumer_jwt_defaults.id}" } `