Skip to content

Commit

Permalink
add tests for jwt-provider config entry
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodingenthusiast committed Jul 13, 2023
1 parent 3dcf543 commit 2c1571b
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
run: make test
- name: Run OSS acceptance tests
run: |
curl -LO https://releases.hashicorp.com/consul/1.15.2/consul_1.15.2_linux_amd64.zip
sudo unzip consul_1.15.2_linux_amd64.zip consul -d /usr/local/bin
curl -LO https://releases.hashicorp.com/consul/1.16.0/consul_1.16.0_linux_amd64.zip
sudo unzip consul_1.16.0_linux_amd64.zip consul -d /usr/local/bin
SKIP_REMOTE_DATACENTER_TESTS=1 make testacc TESTARGS="-count=1"
- name: Run go vet
run: make vet
75 changes: 75 additions & 0 deletions consul/resource_consul_config_entry_ce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,46 @@ func TestAccConsulConfigEntryCE_Mesh(t *testing.T) {
})
}

func TestAccConsulConfigEntryCE_JWTProvider_Remote(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipTestOnConsulEnterpriseEdition(t) },
Providers: providers,
Steps: []resource.TestStep{
{
Config: TestAccConsulConfigEntryCE_jwtRemote,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "id", "jwt-provider-okta"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "name", "okta"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "kind", "jwt-provider"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "config_json", "{\"ClockSkewSeconds\":30,\"Forwarding\":{\"HeaderName\":\"test-token\"},\"Issuer\":\"test-issuer\",\"JSONWebKeySet\":{\"Remote\":{\"FetchAsynchronously\":true,\"URI\":\"https://127.0.0.1:9091\"}}}"),
),
},
},
})
}

func TestAccConsulConfigEntryCE_JWTProvider_Local(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipTestOnConsulEnterpriseEdition(t) },
Providers: providers,
Steps: []resource.TestStep{
{
Config: TestAccConsulConfigEntryCE_jwtLocal,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "id", "jwt-provider-auth0"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "name", "auth0"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "kind", "jwt-provider"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "config_json", "{\"ClockSkewSeconds\":30,\"Forwarding\":{\"HeaderName\":\"test-token\"},\"Issuer\":\"auth0-issuer\",\"JSONWebKeySet\":{\"Local\":{\"JWKS\":\"eyJrZXlzIjogW3sKICAiY3J2IjogIlAtMjU2IiwKICAia2V5X29wcyI6IFsKICAgICJ2ZXJpZnkiCiAgXSwKICAia3R5IjogIkVDIiwKICAieCI6ICJXYzl1WnVQYUI3S2gyRk1jOXd0SmpSZThYRDR5VDJBWU5BQWtyWWJWanV3IiwKICAieSI6ICI2OGhSVEppSk5Pd3RyaDRFb1BYZVZuUnVIN2hpU0RKX2xtYmJqZkRmV3EwIiwKICAiYWxnIjogIkVTMjU2IiwKICAidXNlIjogInNpZyIsCiAgImtpZCI6ICJhYzFlOGY5MGVkZGY2MWM0MjljNjFjYTA1YjRmMmUwNyIKfV19\"}}}"),
),
},
},
})
}

const testAccConsulConfigEntryCE_ServiceDefaults = `
resource "consul_config_entry" "foo" {
name = "foo"
Expand Down Expand Up @@ -701,3 +741,38 @@ resource "consul_config_entry" "mesh" {
})
}
`
const TestAccConsulConfigEntryCE_jwtRemote = `
resource "consul_config_entry" "jwt_provider" {
name = "okta"
kind = "jwt-provider"
config_json = jsonencode({
Issuer = "test-issuer"
JSONWebKeySet = {
Remote = {
URI = "https://127.0.0.1:9091"
FetchAsynchronously = true
}
}
Forwarding = {
HeaderName = "test-token"
}
})
}
`

const TestAccConsulConfigEntryCE_jwtLocal = `
resource "consul_config_entry" "jwt_provider" {
name = "auth0"
kind = "jwt-provider"
config_json = jsonencode({
Issuer = "auth0-issuer"
JSONWebKeySet = {
Local = {
JWKS = "eyJrZXlzIjogW3sKICAiY3J2IjogIlAtMjU2IiwKICAia2V5X29wcyI6IFsKICAgICJ2ZXJpZnkiCiAgXSwKICAia3R5IjogIkVDIiwKICAieCI6ICJXYzl1WnVQYUI3S2gyRk1jOXd0SmpSZThYRDR5VDJBWU5BQWtyWWJWanV3IiwKICAieSI6ICI2OGhSVEppSk5Pd3RyaDRFb1BYZVZuUnVIN2hpU0RKX2xtYmJqZkRmV3EwIiwKICAiYWxnIjogIkVTMjU2IiwKICAidXNlIjogInNpZyIsCiAgImtpZCI6ICJhYzFlOGY5MGVkZGY2MWM0MjljNjFjYTA1YjRmMmUwNyIKfV19"
}
}
})
}
`
76 changes: 76 additions & 0 deletions consul/resource_consul_config_entry_ee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,46 @@ func TestAccConsulConfigEntryEE_Mesh(t *testing.T) {
})
}

func TestAccConsulConfigEntryEE_JWTProvider_Remote(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipTestOnConsulEnterpriseEdition(t) },
Providers: providers,
Steps: []resource.TestStep{
{
Config: TestAccConsulConfigEntryEE_jwtRemote,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "id", "jwt-provider-okta"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "name", "okta"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "kind", "jwt-provider"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "config_json", "{\"ClockSkewSeconds\":30,\"Forwarding\":{\"HeaderName\":\"test-token\"},\"Issuer\":\"test-issuer\",\"JSONWebKeySet\":{\"Remote\":{\"FetchAsynchronously\":true,\"URI\":\"https://127.0.0.1:9091\"}}}"),
),
},
},
})
}

func TestAccConsulConfigEntryEE_JWTProvider_Local(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipTestOnConsulEnterpriseEdition(t) },
Providers: providers,
Steps: []resource.TestStep{
{
Config: TestAccConsulConfigEntryEE_jwtLocal,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "id", "jwt-provider-auth0"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "name", "auth0"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "kind", "jwt-provider"),
resource.TestCheckResourceAttr("consul_config_entry.jwt_provider", "config_json", "{\"ClockSkewSeconds\":30,\"Forwarding\":{\"HeaderName\":\"test-token\"},\"Issuer\":\"auth0-issuer\",\"JSONWebKeySet\":{\"Local\":{\"JWKS\":\"eyJrZXlzIjogW3sKICAiY3J2IjogIlAtMjU2IiwKICAia2V5X29wcyI6IFsKICAgICJ2ZXJpZnkiCiAgXSwKICAia3R5IjogIkVDIiwKICAieCI6ICJXYzl1WnVQYUI3S2gyRk1jOXd0SmpSZThYRDR5VDJBWU5BQWtyWWJWanV3IiwKICAieSI6ICI2OGhSVEppSk5Pd3RyaDRFb1BYZVZuUnVIN2hpU0RKX2xtYmJqZkRmV3EwIiwKICAiYWxnIjogIkVTMjU2IiwKICAidXNlIjogInNpZyIsCiAgImtpZCI6ICJhYzFlOGY5MGVkZGY2MWM0MjljNjFjYTA1YjRmMmUwNyIKfV19\"}}}"),
),
},
},
})
}

const testAccConsulConfigEntryEE_ServiceDefaults = `
resource "consul_config_entry" "foo" {
name = "foo"
Expand Down Expand Up @@ -828,3 +868,39 @@ resource "consul_config_entry" "mesh" {
})
}
`

const TestAccConsulConfigEntryEE_jwtRemote = `
resource "consul_config_entry" "jwt_provider" {
name = "okta"
kind = "jwt-provider"
config_json = jsonencode({
Issuer = "test-issuer"
JSONWebKeySet = {
Remote = {
URI = "https://127.0.0.1:9091"
FetchAsynchronously = true
}
}
Forwarding = {
HeaderName = "test-token"
}
})
}
`

const TestAccConsulConfigEntryEE_jwtLocal = `
resource "consul_config_entry" "jwt_provider" {
name = "auth0"
kind = "jwt-provider"
config_json = jsonencode({
Issuer = "auth0-issuer"
JSONWebKeySet = {
Local = {
JWKS = "eyJrZXlzIjogW3sKICAiY3J2IjogIlAtMjU2IiwKICAia2V5X29wcyI6IFsKICAgICJ2ZXJpZnkiCiAgXSwKICAia3R5IjogIkVDIiwKICAieCI6ICJXYzl1WnVQYUI3S2gyRk1jOXd0SmpSZThYRDR5VDJBWU5BQWtyWWJWanV3IiwKICAieSI6ICI2OGhSVEppSk5Pd3RyaDRFb1BYZVZuUnVIN2hpU0RKX2xtYmJqZkRmV3EwIiwKICAiYWxnIjogIkVTMjU2IiwKICAidXNlIjogInNpZyIsCiAgImtpZCI6ICJhYzFlOGY5MGVkZGY2MWM0MjljNjFjYTA1YjRmMmUwNyIKfV19"
}
}
})
}
`

0 comments on commit 2c1571b

Please sign in to comment.