diff --git a/atst/app.py b/atst/app.py index 04aed44d..1499671c 100644 --- a/atst/app.py +++ b/atst/app.py @@ -186,6 +186,7 @@ def map_config(config): # with a Beat job once a day) "CELERY_RESULT_EXPIRES": 0, "CELERY_RESULT_EXTENDED": True, + "OFFICE_365_DOMAIN": "onmicrosoft.com", "CONTRACT_START_DATE": datetime.strptime( config.get("default", "CONTRACT_START_DATE"), "%Y-%m-%d" ).date(), diff --git a/atst/domain/csp/cloud/azure_cloud_provider.py b/atst/domain/csp/cloud/azure_cloud_provider.py index 7c976b8d..b85bed09 100644 --- a/atst/domain/csp/cloud/azure_cloud_provider.py +++ b/atst/domain/csp/cloud/azure_cloud_provider.py @@ -327,9 +327,7 @@ class AzureCloudProvider(CloudProviderInterface): if result.status_code == 200: result_dict = result.json() tenant_id = result_dict.get("tenantId") - tenant_admin_username = ( - f"{payload.user_id}@{payload.domain_name}.onmicrosoft.com" - ) + tenant_admin_username = f"{payload.user_id}@{payload.domain_name}.{self.config.get('OFFICE_365_DOMAIN')}" self.update_tenant_creds( tenant_id, KeyVaultCredentials( diff --git a/atst/domain/csp/cloud/models.py b/atst/domain/csp/cloud/models.py index 859158a0..27f2c9c7 100644 --- a/atst/domain/csp/cloud/models.py +++ b/atst/domain/csp/cloud/models.py @@ -4,6 +4,7 @@ from typing import Dict, List, Optional from uuid import uuid4 import re +from flask import current_app as app from pydantic import BaseModel, validator, root_validator from atst.utils import snake_to_camel @@ -526,7 +527,7 @@ class UserMixin(BaseModel): @property def user_principal_name(self): - return f"{self.mail_nickname}@{self.tenant_host_name}.onmicrosoft.com" + return f"{self.mail_nickname}@{self.tenant_host_name}.{app.config.get('OFFICE_365_DOMAIN')}" @property def mail_nickname(self): diff --git a/atst/jobs.py b/atst/jobs.py index 0094a6dd..77a8c2f6 100644 --- a/atst/jobs.py +++ b/atst/jobs.py @@ -190,7 +190,7 @@ def send_PPOC_email(portfolio_dict): "email.portfolio_ready.body", { "password_reset_address": app.config.get("AZURE_LOGIN_URL"), - "username": f"{user_id}@{domain_name}.onmicrosoft.com", + "username": f"{user_id}@{domain_name}.{app.config.get('OFFICE_365_DOMAIN')}", }, ), ) diff --git a/tests/domain/cloud/test_models.py b/tests/domain/cloud/test_models.py index e9951c9d..68bcd351 100644 --- a/tests/domain/cloud/test_models.py +++ b/tests/domain/cloud/test_models.py @@ -134,9 +134,12 @@ def test_UserCSPPayload_mail_nickname(): assert payload.mail_nickname == f"han.solo" -def test_UserCSPPayload_user_principal_name(): +def test_UserCSPPayload_user_principal_name(app): payload = UserCSPPayload(**user_payload) - assert payload.user_principal_name == f"han.solo@rebelalliance.onmicrosoft.com" + assert ( + payload.user_principal_name + == f"han.solo@rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}" + ) def test_UserCSPPayload_password(): @@ -167,11 +170,11 @@ class TestBillingOwnerCSPPayload: payload = BillingOwnerCSPPayload(**self.user_payload) assert payload.password - def test_user_principal_name(self): + def test_user_principal_name(self, app): payload = BillingOwnerCSPPayload(**self.user_payload) assert ( payload.user_principal_name - == f"billing_admin@rebelalliance.onmicrosoft.com" + == f"billing_admin@rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}" ) def test_email(self): diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 3edfd769..9df83264 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -135,11 +135,11 @@ def test_create_application_job_is_idempotent(csp): csp.create_application.assert_not_called() -def test_create_user_job(session, csp): +def test_create_user_job(session, csp, app): portfolio = PortfolioFactory.create( csp_data={ "tenant_id": str(uuid4()), - "domain_name": "rebelalliance.onmicrosoft.com", + "domain_name": f"rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}", } ) application = ApplicationFactory.create(portfolio=portfolio, cloud_id="321") @@ -328,7 +328,7 @@ def test_send_ppoc_email(monkeypatch, app): "email.portfolio_ready.body", { "password_reset_address": app.config.get("AZURE_LOGIN_URL"), - "username": f"{user_id}@{domain_name}.onmicrosoft.com", + "username": f"{user_id}@{domain_name}.{app.config.get('OFFICE_365_DOMAIN')}", }, ), )