Skip to content

Commit

Permalink
Add tests for custom domains with self-managed certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
impl committed Apr 11, 2022
1 parent fab416d commit 5f471a6
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 4 deletions.
81 changes: 77 additions & 4 deletions auth0/resource_auth0_custom_domain_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func TestAccCustomDomainVerification(t *testing.T) {
func TestAccCustomDomainVerificationWithAuth0ManagedCerts(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"auth0": func() (*schema.Provider, error) {
Expand All @@ -16,18 +16,39 @@ func TestAccCustomDomainVerification(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: testAccCustomDomainVerification,
Config: testAccCustomDomainVerificationWithAuth0ManagedCerts,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "domain", "terraform-provider.auth0.com"),
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "type", "auth0_managed_certs"),
resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id"),
// The status attribute is set to "pending_verification"
// here because Terraform has settled its state before
// attempting the custom domain verification. We need to
// refresh the state to move it along.
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "pending_verification"),
resource.TestCheckResourceAttrPair(
"auth0_custom_domain.my_custom_domain", "id",
"auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id",
),
resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name"),
),
},
{
Config: testAccCustomDomainVerificationWithAuth0ManagedCerts,
Check: resource.ComposeTestCheckFunc(
// By applying an identical plan, we can reconcile the
// status attribute.
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "ready"),
resource.TestCheckResourceAttrPair(
"auth0_custom_domain.my_custom_domain", "origin_domain_name",
"auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name",
),
),
},
},
})
}

const testAccCustomDomainVerification = `
const testAccCustomDomainVerificationWithAuth0ManagedCerts = `
resource "auth0_custom_domain" "my_custom_domain" {
domain = "terraform-provider.auth0.com"
type = "auth0_managed_certs"
Expand All @@ -38,3 +59,55 @@ resource "auth0_custom_domain_verification" "my_custom_domain_verification" {
timeouts { create = "15m" }
}
`

func TestAccCustomDomainVerificationWithSelfManagedCerts(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"auth0": func() (*schema.Provider, error) {
return providerWithMockedAPI(), nil
},
},
Steps: []resource.TestStep{
{
Config: testAccCustomDomainVerificationWithSelfManagedCerts,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "domain", "terraform-provider.auth0.com"),
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "type", "self_managed_certs"),
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "pending_verification"),
resource.TestCheckResourceAttrPair(
"auth0_custom_domain.my_custom_domain", "id",
"auth0_custom_domain_verification.my_custom_domain_verification", "custom_domain_id",
),
resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name"),
resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "cname_api_key"),
),
},
{
Config: testAccCustomDomainVerificationWithSelfManagedCerts,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_custom_domain.my_custom_domain", "status", "ready"),
resource.TestCheckResourceAttrPair(
"auth0_custom_domain.my_custom_domain", "origin_domain_name",
"auth0_custom_domain_verification.my_custom_domain_verification", "origin_domain_name",
),
// Even though we can no longer read this from the API, it
// should remain set after refresh as we won't clear it out
// in the read operation.
resource.TestCheckResourceAttrSet("auth0_custom_domain_verification.my_custom_domain_verification", "cname_api_key"),
),
},
},
})
}

const testAccCustomDomainVerificationWithSelfManagedCerts = `
resource "auth0_custom_domain" "my_custom_domain" {
domain = "terraform-provider.auth0.com"
type = "self_managed_certs"
}
resource "auth0_custom_domain_verification" "my_custom_domain_verification" {
custom_domain_id = auth0_custom_domain.my_custom_domain.id
timeouts { create = "15m" }
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"custom_domain_id": "cd_selfmanaged",
"domain": "terraform-provider.auth0.com",
"primary": true,
"status": "pending_verification",
"type": "self_managed_certs",
"verification": {
"methods": [
{
"name": "txt",
"record": "a6124756-554d-4a4b-b140-787bdea2e89c",
"domain": "_cf-custom-hostname.terraform-provider.auth0.com"
}
]
},
"tls_policy": "recommended"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"custom_domain_id": "cd_selfmanaged",
"domain": "terraform-provider.auth0.com",
"primary": true,
"status": "ready",
"type": "self_managed_certs",
"origin_domain_name": "terraform-provider-cd-selfmanaged.edge.tenants.eu.auth0.com",
"verification": {
"methods": [
{
"name": "txt",
"record": "a6124756-554d-4a4b-b140-787bdea2e89c",
"domain": "_cf-custom-hostname.terraform-provider.auth0.com"
}
]
},
"tls_policy": "recommended"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"custom_domain_id": "cd_selfmanaged",
"domain": "terraform-provider.auth0.com",
"primary": true,
"status": "ready",
"type": "self_managed_certs",
"origin_domain_name": "terraform-provider-cd-selfmanaged.edge.tenants.eu.auth0.com",
"cname_api_key": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff",
"verification": {
"methods": [
{
"name": "txt",
"record": "a6124756-554d-4a4b-b140-787bdea2e89c",
"domain": "_cf-custom-hostname.terraform-provider.auth0.com"
}
]
},
"tls_policy": "recommended"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"request": {
"method": "DELETE",
"url": "/api/v2/custom-domains/cd_selfmanaged"
},
"response": {
"status": 204
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"scenarioName": "Custom domain verification with self-managed certificates",
"requiredScenarioState": "Started",
"request": {
"method": "GET",
"url": "/api/v2/custom-domains/cd_selfmanaged"
},
"response": {
"status": 200,
"bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json",
"headers": {
"Content-Type": "application/json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"scenarioName": "Custom domain verification with self-managed certificates",
"requiredScenarioState": "Verified",
"request": {
"method": "GET",
"url": "/api/v2/custom-domains/cd_selfmanaged"
},
"response": {
"status": 200,
"bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_ready.json",
"headers": {
"Content-Type": "application/json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"request": {
"method": "POST",
"url": "/api/v2/custom-domains",
"bodyPatterns": [
{
"equalToJson": {
"domain": "terraform-provider.auth0.com",
"type": "self_managed_certs"
}
}
]
},
"response": {
"status": 201,
"bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_pending_verification.json",
"headers": {
"Content-Type": "application/json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"scenarioName": "Custom domain verification with self-managed certificates",
"requiredScenarioState": "Started",
"newScenarioState": "Verified",
"request": {
"method": "POST",
"url": "/api/v2/custom-domains/cd_selfmanaged/verify"
},
"response": {
"status": 201,
"bodyFileName": "custom_domain_verification/with_self_managed_certs/custom_domain_verify.json",
"headers": {
"Content-Type": "application/json"
}
}
}

0 comments on commit 5f471a6

Please sign in to comment.