Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
  • Loading branch information
Lawouach committed Mar 26, 2024
1 parent 0830e16 commit ab802aa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 162 deletions.
43 changes: 0 additions & 43 deletions chaosazure/common/cloud.py

This file was deleted.

23 changes: 3 additions & 20 deletions chaosazure/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import os

from chaoslib.types import Configuration, Secrets
from msrestazure import azure_cloud

from chaosazure.common import cloud

logger = logging.getLogger("chaostoolkit")

Expand Down Expand Up @@ -85,33 +82,19 @@ def load_secrets(experiment_secrets: Secrets):
"tenant_id", os.getenv("AZURE_TENANT_ID")
),
# load cloud object
"cloud": cloud.get_or_raise(
experiment_secrets.get("azure_cloud", os.getenv("AZURE_CLOUD"))
"cloud": experiment_secrets.get(
"azure_cloud", os.getenv("AZURE_CLOUD", "AZURE_PUBLIC_CLOUD")
),
"access_token": experiment_secrets.get(
"access_token", os.getenv("AZURE_ACCESS_TOKEN")
),
}

# 2: lookup for credentials in azure auth file
az_auth_file = _load_azure_auth_file()
if az_auth_file:
rm_endpoint = az_auth_file.get("resourceManagerEndpointUrl")
return {
"client_id": az_auth_file.get("clientId"),
"client_secret": az_auth_file.get("clientSecret"),
"tenant_id": az_auth_file.get("tenantId"),
# load cloud object
"cloud": azure_cloud.get_cloud_from_metadata_endpoint(rm_endpoint),
# access token is not supported for credential files
"access_token": None,
}

return {
"client_id": os.getenv("AZURE_CLIENT_ID"),
"client_secret": os.getenv("AZURE_CLIENT_SECRET"),
"tenant_id": os.getenv("AZURE_TENANT_ID"),
"cloud": cloud.get_or_raise(os.getenv("AZURE_CLOUD")),
"cloud": os.getenv("AZURE_CLOUD", "AZURE_PUBLIC_CLOUD"),
"access_token": os.getenv("AZURE_ACCESS_TOKEN"),
}

Expand Down
68 changes: 0 additions & 68 deletions tests/common/test_cloud.py

This file was deleted.

29 changes: 5 additions & 24 deletions tests/common/test_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from chaosazure import get_management_url_from_authority
from chaosazure.common import config

settings_dir = os.path.join(os.path.dirname(__file__), "fixtures")
Expand All @@ -21,8 +22,8 @@ def test_load_secrets_from_experiment_dict():
assert secrets.get("client_secret") == "AZURE_CLIENT_SECRET"
assert secrets.get("tenant_id") == "AZURE_TENANT_ID"
assert (
secrets.get("cloud").endpoints.resource_manager
== "https://management.azure.com/"
get_management_url_from_authority(secrets)
== "https://management.azure.com"
)


Expand All @@ -36,28 +37,8 @@ def test_load_token_from_experiment_dict():
# assert
assert secrets.get("access_token") == "ACCESS_TOKEN"
assert (
secrets.get("cloud").endpoints.resource_manager
== "https://management.azure.com/"
)


def test_load_secrets_from_credential_file(monkeypatch):
# arrange
experiment_secrets = None
monkeypatch.setenv(
"AZURE_AUTH_LOCATION", os.path.join(settings_dir, "credentials.json")
)

# act
secrets = config.load_secrets(experiment_secrets)

# assert
assert secrets.get("client_id") == "AZURE_CLIENT_ID"
assert secrets.get("client_secret") == "AZURE_CLIENT_SECRET"
assert secrets.get("tenant_id") == "AZURE_TENANT_ID"
assert (
secrets.get("cloud").endpoints.resource_manager
== "https://management.azure.com/"
get_management_url_from_authority(secrets)
== "https://management.azure.com"
)


Expand Down
11 changes: 4 additions & 7 deletions tests/data/secrets_provider.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
from chaosazure.common import cloud


def provide_secrets_via_service_principal():
return {"client_id": "***", "client_secret": "***", "tenant_id": "***"}


def provide_secrets_china():
result = provide_secrets_via_service_principal()
result["azure_cloud"] = cloud.AZURE_CHINA_CLOUD
result["azure_cloud"] = "AZURE_CHINA_CLOUD"
return result


def provide_secrets_germany():
result = provide_secrets_via_service_principal()
result["azure_cloud"] = cloud.AZURE_GERMAN_CLOUD
result["azure_cloud"] = "AZURE_GERMAN_CLOUD"
return result


Expand All @@ -25,13 +22,13 @@ def provide_secrets_germany_small_letters():

def provide_secrets_us_gov():
result = provide_secrets_via_service_principal()
result["azure_cloud"] = cloud.AZURE_US_GOV_CLOUD
result["azure_cloud"] = "AZURE_US_GOV_CLOUD"
return result


def provide_secrets_public():
result = provide_secrets_via_service_principal()
result["azure_cloud"] = cloud.AZURE_PUBLIC_CLOUD
result["azure_cloud"] = "AZURE_PUBLIC_CLOUD"
return result


Expand Down

0 comments on commit ab802aa

Please sign in to comment.