Skip to content

Commit

Permalink
Added Azure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
terricain committed May 16, 2023
1 parent e3f4fac commit 114f629
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
41 changes: 38 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
branches:
- master
- "*"
tags:
- "*"

Expand All @@ -13,17 +13,52 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- name: Install setuptools and
run: |
python -m pip install --upgrade setuptools wheel
python -m pip install -r requirements-dev.txt
- name: Test
run: pytest tests/

azure_test:
name: Azure Test
runs-on: ubuntu-latest
environment:
name: dev.azure
# Not using OIDC Auth
# permissions:
# id-token: write
# contents: read
steps:
# Not using CLI Auth
# - name: 'Az CLI Login via OIDC'
# uses: azure/login@v1
# with:
# client-id: ${{ secrets.AZURE_CLIENT_ID }}
# tenant-id: ${{ secrets.AZURE_TENANT_ID }}
# subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install setuptools and
run: |
python -m pip install --upgrade setuptools wheel
python -m pip install -r requirements-dev.txt
- name: Test
run: pytest azure_tests/
env:
EMAIL: ${{ vars.EMAIL }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}


publish:
name: Publish
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
Expand Down
23 changes: 13 additions & 10 deletions tests/integration_test.py → azure_tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from azure.mgmt.dns import DnsManagementClient
from azure.identity import ClientSecretCredential
from azure.identity import ClientSecretCredential, AzureCliCredential

if TYPE_CHECKING:
import pathlib
Expand All @@ -14,8 +14,8 @@
EMAIL = os.getenv('EMAIL', 'NOT_AN_EMAIL')

azure_creds = pytest.mark.skipif(
any(env not in os.environ for env in ['AZURE_SP_ID', 'AZURE_SP_SECRET', 'AZURE_TENANT_ID', 'EMAIL']),
reason="Missing 'AZURE_SP_ID', 'AZURE_SP_SECRET', 'AZURE_TENANT_ID' environment variables"
any(env not in os.environ for env in ['AZURE_CLIENT_ID', 'AZURE_TENANT_ID', 'EMAIL']),
reason="Missing 'AZURE_CLIENT_ID', 'AZURE_TENANT_ID' environment variables"
)

SUBSCRIPTION_ID = '90907259-f568-40c9-be09-768317e458ae'
Expand All @@ -36,12 +36,15 @@ def get_cert_names(count: int = 1) -> List[str]:

@pytest.fixture(scope='session')
def azure_dns_client() -> DnsManagementClient:
creds = ClientSecretCredential(
client_id=os.environ['AZURE_SP_ID'],
client_secret=os.environ['AZURE_SP_SECRET'],
tenant_id=os.environ['AZURE_TENANT_ID'],
authority='https://login.microsoftonline.com/'
)
if 'AZURE_CLIENT_SECRET' in os.environ:
creds = ClientSecretCredential(
client_id=os.environ['AZURE_CLIENT_ID'],
client_secret=os.environ['AZURE_CLIENT_SECRET'],
tenant_id=os.environ['AZURE_TENANT_ID'],
authority='https://login.microsoftonline.com/'
)
else:
creds = AzureCliCredential(tenant_id=os.environ['AZURE_TENANT_ID'])
return DnsManagementClient(creds, SUBSCRIPTION_ID, None, 'https://management.azure.com/', credential_scopes=['https://management.azure.com//.default'])


Expand Down Expand Up @@ -80,7 +83,7 @@ def create_config(tmpdir: 'pathlib.Path', zones: List[str]) -> str:
"""
config = {
'dns_azure_sp_client_id': os.environ['AZURE_SP_ID'],
'dns_azure_sp_client_secret': os.environ['AZURE_SP_SECRET'],
'dns_azure_sp_client_secret': os.environ['AZURE_CLIENT_SECRET'],
'dns_azure_tenant_id': os.environ['AZURE_TENANT_ID'],
'dns_azure_environment': AZURE_ENV,
}
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Security',
'Topic :: System :: Installation/Setup',
Expand Down

0 comments on commit 114f629

Please sign in to comment.