From 86a763b9054b725092a6b2b8f515a815bd8186bc Mon Sep 17 00:00:00 2001 From: Noah Fontes Date: Sun, 10 Apr 2022 01:53:17 -0700 Subject: [PATCH] Refactor WireMock mappings/files, reset before tests --- Makefile | 2 ++ docker-compose.yml | 9 +++++---- dockerfiles/wiremock/Dockerfile | 5 ----- .../cd_auth0managed.json | 19 +++++++++++++++++++ .../__files/custom_domain_verified.json | 16 ---------------- ...stom_domain_with_pending_verification.json | 16 ---------------- .../delete_custom_domain_204.json | 2 +- ...ustom_domain_pending_verification_200.json | 18 ++++++++++++++++++ .../get_custom_domain_ready_200.json | 18 ++++++++++++++++++ .../post_custom_domain_201.json | 5 ++++- .../post_custom_domain_verify_200.json | 19 +++++++++++++++++++ .../get_custom_domain_pending_200.json | 16 ---------------- .../mappings/get_custom_domain_ready_200.json | 15 --------------- .../post_custom_domain_verify_200.json | 13 ------------- 14 files changed, 86 insertions(+), 87 deletions(-) delete mode 100644 dockerfiles/wiremock/Dockerfile create mode 100644 dockerfiles/wiremock/__files/custom_domain_verification/cd_auth0managed.json delete mode 100644 dockerfiles/wiremock/__files/custom_domain_verified.json delete mode 100644 dockerfiles/wiremock/__files/custom_domain_with_pending_verification.json rename dockerfiles/wiremock/mappings/{ => custom_domain_verification/with_auth0_managed_certs}/delete_custom_domain_204.json (60%) create mode 100644 dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_pending_verification_200.json create mode 100644 dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_ready_200.json rename dockerfiles/wiremock/mappings/{ => custom_domain_verification/with_auth0_managed_certs}/post_custom_domain_201.json (70%) create mode 100644 dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_verify_200.json delete mode 100644 dockerfiles/wiremock/mappings/get_custom_domain_pending_200.json delete mode 100644 dockerfiles/wiremock/mappings/get_custom_domain_ready_200.json delete mode 100644 dockerfiles/wiremock/mappings/post_custom_domain_verify_200.json diff --git a/Makefile b/Makefile index fd2bf1126..fbfda2997 100644 --- a/Makefile +++ b/Makefile @@ -104,6 +104,7 @@ test-unit: ## Run unit tests test-acc: dev-up ## Run acceptance tests ${call print, "Running acceptance tests"} + @docker-compose exec -- auth0 curl -4 -sS -o /dev/null -X POST http://localhost:8080/__admin/scenarios/reset @TF_ACC=1 go test ${GO_PACKAGES} -v $(TESTARGS) -timeout 120m -coverprofile="${GO_TEST_COVERAGE_FILE}" test-sweep: ## Clean up test tenant @@ -118,6 +119,7 @@ test-sweep: ## Clean up test tenant dev-up: ## Bootstrap the development containers ${call print, "Starting development containers"} @docker-compose up -d + @docker-compose exec -- auth0 curl -4 --retry-connrefused --retry 15 --retry-delay 2 -sS -o /dev/null -X POST http://localhost:8080/__admin/mappings/reset dev-down: ## Bring down the development containers ${call print, "Bringing the development containers down"} diff --git a/docker-compose.yml b/docker-compose.yml index 92cebecc1..6fb5212cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,10 +2,11 @@ version: "3.8" services: auth0: - build: - context: . - dockerfile: dockerfiles/wiremock/Dockerfile - command: --port 8080 --verbose + image: wiremock/wiremock:2.30.0 + volumes: + - ./dockerfiles/wiremock/__files:/home/wiremock/__files + - ./dockerfiles/wiremock/mappings:/home/wiremock/mappings + command: --port 8080 --verbose --global-response-templating expose: - "8080" ports: diff --git a/dockerfiles/wiremock/Dockerfile b/dockerfiles/wiremock/Dockerfile deleted file mode 100644 index 7836df2c9..000000000 --- a/dockerfiles/wiremock/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM wiremock/wiremock:2.30.0 - - -COPY ./dockerfiles/wiremock/__files /home/wiremock/__files -COPY ./dockerfiles/wiremock/mappings /home/wiremock/mappings diff --git a/dockerfiles/wiremock/__files/custom_domain_verification/cd_auth0managed.json b/dockerfiles/wiremock/__files/custom_domain_verification/cd_auth0managed.json new file mode 100644 index 000000000..126feebe8 --- /dev/null +++ b/dockerfiles/wiremock/__files/custom_domain_verification/cd_auth0managed.json @@ -0,0 +1,19 @@ +{ + "custom_domain_id": "cd_auth0managed", + "domain": "terraform-provider.auth0.com", + "primary": true, + "status": "{{parameters.status}}", + "type": "auth0_managed_certs", +{{#eq parameters.status "ready"}} + "origin_domain_name": "terraform-provider-cd-auth0managed.edge.tenants.eu.auth0.com", +{{/eq}} + "verification": { + "methods": [ + { + "name": "cname", + "record": "terraform-provider-cd-auth0managed.edge.tenants.eu.auth0.com" + } + ] + }, + "tls_policy": "recommended" +} diff --git a/dockerfiles/wiremock/__files/custom_domain_verified.json b/dockerfiles/wiremock/__files/custom_domain_verified.json deleted file mode 100644 index bf836a728..000000000 --- a/dockerfiles/wiremock/__files/custom_domain_verified.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "custom_domain_id": "cd_fakecustomdomain", - "domain": "terraform-provider.auth0.com", - "primary": true, - "status": "ready", - "type": "auth0_managed_certs", - "verification": { - "methods": [ - { - "name": "cname", - "record": "terraform-provider-cd-fakecustomdomain.edge.tenants.eu.auth0.com" - } - ] - }, - "tls_policy": "recommended" -} diff --git a/dockerfiles/wiremock/__files/custom_domain_with_pending_verification.json b/dockerfiles/wiremock/__files/custom_domain_with_pending_verification.json deleted file mode 100644 index fec67a9cb..000000000 --- a/dockerfiles/wiremock/__files/custom_domain_with_pending_verification.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "custom_domain_id": "cd_fakecustomdomain", - "domain": "terraform-provider.auth0.com", - "primary": true, - "status": "pending_verification", - "type": "auth0_managed_certs", - "verification": { - "methods": [ - { - "name": "cname", - "record": "terraform-provider-cd-fakecustomdomain.edge.tenants.eu.auth0.com" - } - ] - }, - "tls_policy": "recommended" -} diff --git a/dockerfiles/wiremock/mappings/delete_custom_domain_204.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/delete_custom_domain_204.json similarity index 60% rename from dockerfiles/wiremock/mappings/delete_custom_domain_204.json rename to dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/delete_custom_domain_204.json index 9ecc14879..cffedbe8e 100644 --- a/dockerfiles/wiremock/mappings/delete_custom_domain_204.json +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/delete_custom_domain_204.json @@ -1,7 +1,7 @@ { "request": { "method": "DELETE", - "url": "/api/v2/custom-domains/cd_fakecustomdomain" + "url": "/api/v2/custom-domains/cd_auth0managed" }, "response": { "status": 204 diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_pending_verification_200.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_pending_verification_200.json new file mode 100644 index 000000000..b613a77c6 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_pending_verification_200.json @@ -0,0 +1,18 @@ +{ + "scenarioName": "Custom domain verification with Auth0-managed certificates", + "requiredScenarioState": "Started", + "request": { + "method": "GET", + "url": "/api/v2/custom-domains/cd_auth0managed" + }, + "response": { + "status": 200, + "bodyFileName": "custom_domain_verification/cd_auth0managed.json", + "headers": { + "Content-Type": "application/json" + }, + "transformerParameters": { + "status": "pending_verification" + } + } +} diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_ready_200.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_ready_200.json new file mode 100644 index 000000000..857fa9892 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/get_custom_domain_ready_200.json @@ -0,0 +1,18 @@ +{ + "scenarioName": "Custom domain verification with Auth0-managed certificates", + "requiredScenarioState": "Verified", + "request": { + "method": "GET", + "url": "/api/v2/custom-domains/cd_auth0managed" + }, + "response": { + "status": 200, + "bodyFileName": "custom_domain_verification/cd_auth0managed.json", + "headers": { + "Content-Type": "application/json" + }, + "transformerParameters": { + "status": "ready" + } + } +} diff --git a/dockerfiles/wiremock/mappings/post_custom_domain_201.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_201.json similarity index 70% rename from dockerfiles/wiremock/mappings/post_custom_domain_201.json rename to dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_201.json index 7ce986ce9..451b8ba2f 100644 --- a/dockerfiles/wiremock/mappings/post_custom_domain_201.json +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_201.json @@ -13,9 +13,12 @@ }, "response": { "status": 201, - "bodyFileName": "custom_domain_with_pending_verification.json", + "bodyFileName": "custom_domain_verification/cd_auth0managed.json", "headers": { "Content-Type": "application/json" + }, + "transformerParameters": { + "status": "pending_verification" } } } diff --git a/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_verify_200.json b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_verify_200.json new file mode 100644 index 000000000..a9ca8fcc6 --- /dev/null +++ b/dockerfiles/wiremock/mappings/custom_domain_verification/with_auth0_managed_certs/post_custom_domain_verify_200.json @@ -0,0 +1,19 @@ +{ + "scenarioName": "Custom domain verification with Auth0-managed certificates", + "requiredScenarioState": "Started", + "newScenarioState": "Verified", + "request": { + "method": "POST", + "url": "/api/v2/custom-domains/cd_auth0managed/verify" + }, + "response": { + "status": 201, + "bodyFileName": "custom_domain_verification/cd_auth0managed.json", + "headers": { + "Content-Type": "application/json" + }, + "transformerParameters": { + "status": "ready" + } + } +} diff --git a/dockerfiles/wiremock/mappings/get_custom_domain_pending_200.json b/dockerfiles/wiremock/mappings/get_custom_domain_pending_200.json deleted file mode 100644 index aced07dc2..000000000 --- a/dockerfiles/wiremock/mappings/get_custom_domain_pending_200.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "scenarioName": "Custom Domain Verification", - "requiredScenarioState": "Started", - "newScenarioState": "Verified", - "request": { - "method": "GET", - "url": "/api/v2/custom-domains/cd_fakecustomdomain" - }, - "response": { - "status": 200, - "bodyFileName": "custom_domain_with_pending_verification.json", - "headers": { - "Content-Type": "application/json" - } - } -} diff --git a/dockerfiles/wiremock/mappings/get_custom_domain_ready_200.json b/dockerfiles/wiremock/mappings/get_custom_domain_ready_200.json deleted file mode 100644 index 2496cf23c..000000000 --- a/dockerfiles/wiremock/mappings/get_custom_domain_ready_200.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "scenarioName": "Custom Domain Verification", - "requiredScenarioState": "Verified", - "request": { - "method": "GET", - "url": "/api/v2/custom-domains/cd_fakecustomdomain" - }, - "response": { - "status": 200, - "bodyFileName": "custom_domain_verified.json", - "headers": { - "Content-Type": "application/json" - } - } -} diff --git a/dockerfiles/wiremock/mappings/post_custom_domain_verify_200.json b/dockerfiles/wiremock/mappings/post_custom_domain_verify_200.json deleted file mode 100644 index bf9493b58..000000000 --- a/dockerfiles/wiremock/mappings/post_custom_domain_verify_200.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "request": { - "method": "POST", - "url": "/api/v2/custom-domains/cd_fakecustomdomain/verify" - }, - "response": { - "status": 201, - "bodyFileName": "custom_domain_verified.json", - "headers": { - "Content-Type": "application/json" - } - } -}