diff --git a/env.d/development/france.dist b/env.d/development/france.dist index 16fccc6..842bcc5 100644 --- a/env.d/development/france.dist +++ b/env.d/development/france.dist @@ -1 +1,2 @@ -ORGANIZATION_PLUGINS=plugins.organizations.NameFromSiretOrganizationPlugin,plugins.organizations.CommuneCreation \ No newline at end of file +ORGANIZATION_PLUGINS=plugins.organizations.NameFromSiretOrganizationPlugin,plugins.organizations.CommuneCreation +DNS_PROVISIONING_TARGET_ZONE=test.collectivite.fr \ No newline at end of file diff --git a/src/backend/people/settings.py b/src/backend/people/settings.py index 5682ea0..8d77a2f 100755 --- a/src/backend/people/settings.py +++ b/src/backend/people/settings.py @@ -545,6 +545,11 @@ class Base(Configuration): environ_name="MAIL_CHECK_DOMAIN_INTERVAL", environ_prefix=None, ) + DNS_PROVISIONING_TARGET_ZONE = values.Value( + default=None, + environ_name="DNS_PROVISIONING_TARGET_ZONE", + environ_prefix=None, + ) DNS_PROVISIONING_API_URL = values.Value( default="https://api.scaleway.com", environ_name="DNS_PROVISIONING_API_URL", diff --git a/src/backend/plugins/organizations.py b/src/backend/plugins/organizations.py index 05303f1..39d6a65 100644 --- a/src/backend/plugins/organizations.py +++ b/src/backend/plugins/organizations.py @@ -181,7 +181,7 @@ class CommuneCreation(BaseOrganizationPlugin): def zone_name(self, name: str) -> str: """Derive the zone name from the commune name""" normalized = self.normalize_name(name) - return f"{normalized}.collectivite.fr" + return f"{normalized}.{settings.DNS_PROVISIONING_TARGET_ZONE}" def complete_commune_creation(self, name: str) -> ApiCall: """Specify the tasks to be completed after a commune is created.""" @@ -193,7 +193,7 @@ class CommuneCreation(BaseOrganizationPlugin): create_zone.url = "/domain/v2beta1/dns-zones" create_zone.params = { "project_id": settings.DNS_PROVISIONING_RESOURCE_ID, - "domain": "collectivite.fr", + "domain": settings.DNS_PROVISIONING_TARGET_ZONE, "subdomain": inputs["name"], } create_zone.headers = { diff --git a/src/backend/plugins/tests/organizations/test_commune_creation.py b/src/backend/plugins/tests/organizations/test_commune_creation.py index d272448..6e0bcba 100644 --- a/src/backend/plugins/tests/organizations/test_commune_creation.py +++ b/src/backend/plugins/tests/organizations/test_commune_creation.py @@ -1,6 +1,7 @@ """Tests for the CommuneCreation plugin.""" from django.conf import settings +from django.test.utils import override_settings import pytest import responses @@ -60,6 +61,7 @@ def test_api_call_execution(): task.execute() +@override_settings(DNS_PROVISIONING_TARGET_ZONE="collectivite.fr") def test_tasks_on_commune_creation_include_zone_creation(): """Test the first task in commune creation: creating the DNS sub-zone""" plugin = CommuneCreation() @@ -78,6 +80,7 @@ def test_tasks_on_commune_creation_include_zone_creation(): assert tasks[0].headers["X-Auth-Token"] == settings.DNS_PROVISIONING_API_CREDENTIALS +@override_settings(DNS_PROVISIONING_TARGET_ZONE="collectivite.fr") def test_tasks_on_commune_creation_include_dimail_domain_creation(): """Test the second task in commune creation: creating the domain in Dimail""" plugin = CommuneCreation() @@ -100,6 +103,7 @@ def test_tasks_on_commune_creation_include_dimail_domain_creation(): ) +@override_settings(DNS_PROVISIONING_TARGET_ZONE="collectivite.fr") def test_tasks_on_commune_creation_include_fetching_spec(): """Test the third task in commune creation: asking Dimail for the spec""" plugin = CommuneCreation() @@ -116,6 +120,7 @@ def test_tasks_on_commune_creation_include_fetching_spec(): ) +@override_settings(DNS_PROVISIONING_TARGET_ZONE="collectivite.fr") def test_tasks_on_commune_creation_include_dns_records(): """Test the next several tasks in commune creation: creating records""" plugin = CommuneCreation() @@ -171,6 +176,7 @@ def test_tasks_on_commune_creation_include_dns_records(): ) +@override_settings(DNS_PROVISIONING_TARGET_ZONE="collectivite.fr") def test_tasks_on_grant_access(): """Test the final tasks after making user admin of an org""" plugin = CommuneCreation() @@ -218,6 +224,7 @@ def test_normalize_name(): ) +@override_settings(DNS_PROVISIONING_TARGET_ZONE="collectivite.fr") def test_zone_name(): """Test transforming a commune name to a sub-zone of collectivite.fr""" plugin = CommuneCreation() diff --git a/src/frontend/apps/e2e/__tests__/app-desk/domain-provisioning.spec.ts b/src/frontend/apps/e2e/__tests__/app-desk/domain-provisioning.spec.ts index 01f9766..06cb109 100644 --- a/src/frontend/apps/e2e/__tests__/app-desk/domain-provisioning.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-desk/domain-provisioning.spec.ts @@ -23,7 +23,7 @@ test.describe('When a commune, domain is created on first login via ProConnect', await expect( page.getByLabel('Mail domains panel', { exact: true }), ).toBeVisible(); - await expect(page.getByText('merlaut.collectivite.fr')).toHaveCount(1); + await expect(page.getByText('merlaut.test.collectivite.fr')).toHaveCount(1); await expect(page.getByText('No domains exist.')).toHaveCount(0); }); });