Skip to content

Commit

Permalink
Merge pull request #9 from mxmehl/live-tests
Browse files Browse the repository at this point in the history
Add functional tests against test API
  • Loading branch information
mxmehl authored Mar 13, 2024
2 parents 035697b + 81f941a commit e7c1a02
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/actions/poetrybuild/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ inputs:
description: "Value for 'python-version'"
required: false
type: string
poetry_args:
default: ""
description: "Additional arguments for the poetry install step'"
required: false
type: string
runs:
using: "composite"
steps:
Expand All @@ -19,5 +24,5 @@ runs:
- name: Install dependencies
run: |
pip install poetry
poetry install --no-interaction
poetry install --no-interaction ${{ inputs.poetry_args }}
shell: bash
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- uses: ./.github/actions/poetrybuild
with:
python: ${{ matrix.python-version }}
poetry_args: --only main
- name: Execute inwx-dns-recordmaster
run: poetry run inwx-dnsrm --help

Expand All @@ -56,6 +57,32 @@ jobs:
inwx-dnsrm --version
inwx-dnsrm --help
# Run functional tests against the INWX test instance
live-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/poetrybuild
with:
poetry_args: --only main

- name: Create app configuration
run: |
mkdir -p /home/runner/.config/inwx-dns-recordmaster
cp tests/config.toml /home/runner/.config/inwx-dns-recordmaster/config.toml
# Replace secrets in app config
sed -i "s|__INWX_OTE_USER__|${{ secrets.INWX_OTE_USER }}|" /home/runner/.config/inwx-dns-recordmaster/config.toml
sed -i "s|__INWX_OTE_PASS__|${{ secrets.INWX_OTE_PASS }}|" /home/runner/.config/inwx-dns-recordmaster/config.toml
- name: Run with first records configuration
run: poetry run inwx-dnsrm -c tests/records/

- name: Run with second records configuration
run: |
cp tests/records/test-mehl.mx.yaml.changes tests/records/test-mehl.mx.yaml
poetry run inwx-dnsrm -c tests/records/
# Formatting
pylint:
runs-on: ubuntu-22.04
steps:
Expand All @@ -82,6 +109,7 @@ jobs:
- name: Test typing with mypy
run: poetry run mypy

# REUSE
reuse:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions recordmaster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# to create a sub-account with restricted access. You may also ask the INWX
# support to limit access to this account to certain IP addresses.
shared_secret = ""
# Whether to use the INWX test instance at https://www.ote.inwx.de. Default: false
test_instance = false
"""


Expand Down
13 changes: 9 additions & 4 deletions recordmaster/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@

def api_login(api_response_file: str, debug: bool) -> ApiClient:
"""Login to INWX API"""
# Do not login when using the remote API response file
if not api_response_file:
api_client = ApiClient(
api_url=ApiClient.API_LIVE_URL, api_type=ApiType.JSON_RPC, debug_mode=debug
# Set API URL depending on app config
login_data = get_app_config("inwx_account")
api_url = (
ApiClient.API_OTE_URL
if login_data.get("test_instance", False)
else ApiClient.API_LIVE_URL
)
api_client = ApiClient(api_url=api_url, api_type=ApiType.JSON_RPC, debug_mode=debug)

# Get login data from app config
login_data = get_app_config("inwx_account")
login_data = {
"username": login_data.get("username"),
"password": login_data.get("password"),
Expand All @@ -37,6 +40,8 @@ def api_login(api_response_file: str, debug: bool) -> ApiClient:
login_result = api_client.login(**login_data)
if login_result["code"] != 1000: # type: ignore
raise RuntimeError(f"API Login error: {login_result}")

# Do not login when using the remote API response file
else:
api_client = ApiClient(debug_mode=debug)

Expand Down
22 changes: 22 additions & 0 deletions tests/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2024 Max Mehl <https://mehl.mx>
#
# SPDX-License-Identifier: CC0-1.0

# App configuration for INWX DNS Recordmaster.
# This is not the place for domain records, these can be anywhere and used with the -c flag

# Login data for the INWX API. Can also be a sub-account
[inwx_account]
# Username and password are both required
username = "__INWX_OTE_USER__"
password = "__INWX_OTE_PASS__"

# In case your account is 2FA-protected, you can add the TOTP shared secret here
# The program will automatically create a TOTP token for you.
# Note that this may reduce the account's security drastically. It may be better
# to create a sub-account with restricted access. You may also ask the INWX
# support to limit access to this account to certain IP addresses.
shared_secret = ""

# Whether to use the INWX test instance at https://www.ote.inwx.de. Default: false
test_instance = true
17 changes: 17 additions & 0 deletions tests/records/test-mehl.mx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2024 Max Mehl <https://mehl.mx>
#
# SPDX-License-Identifier: CC0-1.0

test-mehl.mx:
.:
- type: A
content: "10.1.33.7"
- type: NS
content: ns.ote.inwx.de
ttl: 86400
- type: NS
content: ns2.ote.inwx.de
ttl: 86400
mail:
- type: CNAME
content: mehl.mx
17 changes: 17 additions & 0 deletions tests/records/test-mehl.mx.yaml.changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2024 Max Mehl <https://mehl.mx>
#
# SPDX-License-Identifier: CC0-1.0

test-mehl.mx:
.:
- type: A
content: "127.0.0.1"
- type: NS
content: ns.ote.inwx.de
ttl: 86400
- type: NS
content: ns2.ote.inwx.de
ttl: 86400
cloud:
- type: MX
content: example.com

0 comments on commit e7c1a02

Please sign in to comment.