Skip to content

Commit

Permalink
rsa_public_key of jwt consumer is nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoneto-senior committed Sep 15, 2023
1 parent 489c079 commit e73f90e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions kong/resource_kong_consumer_jwt_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}

Expand Down
34 changes: 15 additions & 19 deletions kong/resource_kong_consumer_jwt_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kong
import (
"context"
"fmt"
"regexp"
"testing"

"github.com/kong/go-kong/kong"
Expand Down Expand Up @@ -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,
},
},
})
Expand Down Expand Up @@ -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}"
}
`

0 comments on commit e73f90e

Please sign in to comment.