Move 'onmicrosoft.com' to an app constant
This commit is contained in:
parent
8f52443b5d
commit
9b25a4b907
@ -186,6 +186,7 @@ def map_config(config):
|
|||||||
# with a Beat job once a day)
|
# with a Beat job once a day)
|
||||||
"CELERY_RESULT_EXPIRES": 0,
|
"CELERY_RESULT_EXPIRES": 0,
|
||||||
"CELERY_RESULT_EXTENDED": True,
|
"CELERY_RESULT_EXTENDED": True,
|
||||||
|
"OFFICE_365_DOMAIN": "onmicrosoft.com",
|
||||||
"CONTRACT_START_DATE": datetime.strptime(
|
"CONTRACT_START_DATE": datetime.strptime(
|
||||||
config.get("default", "CONTRACT_START_DATE"), "%Y-%m-%d"
|
config.get("default", "CONTRACT_START_DATE"), "%Y-%m-%d"
|
||||||
).date(),
|
).date(),
|
||||||
|
@ -327,9 +327,7 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
result_dict = result.json()
|
result_dict = result.json()
|
||||||
tenant_id = result_dict.get("tenantId")
|
tenant_id = result_dict.get("tenantId")
|
||||||
tenant_admin_username = (
|
tenant_admin_username = f"{payload.user_id}@{payload.domain_name}.{self.config.get('OFFICE_365_DOMAIN')}"
|
||||||
f"{payload.user_id}@{payload.domain_name}.onmicrosoft.com"
|
|
||||||
)
|
|
||||||
self.update_tenant_creds(
|
self.update_tenant_creds(
|
||||||
tenant_id,
|
tenant_id,
|
||||||
KeyVaultCredentials(
|
KeyVaultCredentials(
|
||||||
|
@ -4,6 +4,7 @@ from typing import Dict, List, Optional
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from flask import current_app as app
|
||||||
from pydantic import BaseModel, validator, root_validator
|
from pydantic import BaseModel, validator, root_validator
|
||||||
|
|
||||||
from atst.utils import snake_to_camel
|
from atst.utils import snake_to_camel
|
||||||
@ -526,7 +527,7 @@ class UserMixin(BaseModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def user_principal_name(self):
|
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
|
@property
|
||||||
def mail_nickname(self):
|
def mail_nickname(self):
|
||||||
|
@ -190,7 +190,7 @@ def send_PPOC_email(portfolio_dict):
|
|||||||
"email.portfolio_ready.body",
|
"email.portfolio_ready.body",
|
||||||
{
|
{
|
||||||
"password_reset_address": app.config.get("AZURE_LOGIN_URL"),
|
"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')}",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -134,9 +134,12 @@ def test_UserCSPPayload_mail_nickname():
|
|||||||
assert payload.mail_nickname == f"han.solo"
|
assert payload.mail_nickname == f"han.solo"
|
||||||
|
|
||||||
|
|
||||||
def test_UserCSPPayload_user_principal_name():
|
def test_UserCSPPayload_user_principal_name(app):
|
||||||
payload = UserCSPPayload(**user_payload)
|
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():
|
def test_UserCSPPayload_password():
|
||||||
@ -167,11 +170,11 @@ class TestBillingOwnerCSPPayload:
|
|||||||
payload = BillingOwnerCSPPayload(**self.user_payload)
|
payload = BillingOwnerCSPPayload(**self.user_payload)
|
||||||
assert payload.password
|
assert payload.password
|
||||||
|
|
||||||
def test_user_principal_name(self):
|
def test_user_principal_name(self, app):
|
||||||
payload = BillingOwnerCSPPayload(**self.user_payload)
|
payload = BillingOwnerCSPPayload(**self.user_payload)
|
||||||
assert (
|
assert (
|
||||||
payload.user_principal_name
|
payload.user_principal_name
|
||||||
== f"billing_admin@rebelalliance.onmicrosoft.com"
|
== f"billing_admin@rebelalliance.{app.config.get('OFFICE_365_DOMAIN')}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_email(self):
|
def test_email(self):
|
||||||
|
@ -135,11 +135,11 @@ def test_create_application_job_is_idempotent(csp):
|
|||||||
csp.create_application.assert_not_called()
|
csp.create_application.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_create_user_job(session, csp):
|
def test_create_user_job(session, csp, app):
|
||||||
portfolio = PortfolioFactory.create(
|
portfolio = PortfolioFactory.create(
|
||||||
csp_data={
|
csp_data={
|
||||||
"tenant_id": str(uuid4()),
|
"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")
|
application = ApplicationFactory.create(portfolio=portfolio, cloud_id="321")
|
||||||
@ -328,7 +328,7 @@ def test_send_ppoc_email(monkeypatch, app):
|
|||||||
"email.portfolio_ready.body",
|
"email.portfolio_ready.body",
|
||||||
{
|
{
|
||||||
"password_reset_address": app.config.get("AZURE_LOGIN_URL"),
|
"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')}",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user