Add signature response for valid license keys
This commit is contained in:
@@ -72,6 +72,9 @@ class LicenseServerClient:
|
||||
def is_valid(self, license_key: str) -> requests.Response:
|
||||
return self.request("get", "/is_valid", params={"license_key": license_key}, auth=False)
|
||||
|
||||
def public_key(self) -> requests.Response:
|
||||
return self.request("get", "/public-key", auth=False)
|
||||
|
||||
def disable_license(self, license_key: str, *, auth: bool = True) -> requests.Response:
|
||||
return self.request("post", f"/license/{license_key}/disable", auth=auth)
|
||||
|
||||
@@ -133,6 +136,19 @@ def test_license_endpoint_requires_authentication(client: LicenseServerClient) -
|
||||
assert history_export.status_code == 401
|
||||
|
||||
|
||||
def _assert_validity_payload(response: requests.Response, expected_valid: bool, *, license_key: str) -> None:
|
||||
assert response.status_code == 200
|
||||
payload = response.json()
|
||||
assert isinstance(payload, dict)
|
||||
assert payload.get("valid") is expected_valid
|
||||
|
||||
if expected_valid and "signature" in payload:
|
||||
assert "license" in payload
|
||||
license_payload = payload["license"]
|
||||
assert license_payload.get("license_key") == license_key
|
||||
assert "expiration_timestamp" in license_payload
|
||||
|
||||
|
||||
def test_license_lifecycle_and_exports(client: LicenseServerClient) -> None:
|
||||
info_text = "QA test license"
|
||||
create_response = client.create_license(info=info_text)
|
||||
@@ -145,17 +161,13 @@ def test_license_lifecycle_and_exports(client: LicenseServerClient) -> None:
|
||||
assert len(parts) == 5
|
||||
assert all(len(part) == 5 for part in parts)
|
||||
|
||||
validity_response = client.is_valid(license_key)
|
||||
assert validity_response.status_code == 200
|
||||
assert validity_response.json() is True
|
||||
_assert_validity_payload(client.is_valid(license_key), True, license_key=license_key)
|
||||
|
||||
disable_response = client.disable_license(license_key)
|
||||
assert disable_response.status_code == 200
|
||||
assert disable_response.json()["is_active"] is False
|
||||
|
||||
after_disable = client.is_valid(license_key)
|
||||
assert after_disable.status_code == 200
|
||||
assert after_disable.json() is False
|
||||
_assert_validity_payload(client.is_valid(license_key), False, license_key=license_key)
|
||||
|
||||
enable_response = client.enable_license(license_key)
|
||||
assert enable_response.status_code == 200
|
||||
@@ -186,3 +198,16 @@ def test_license_lifecycle_and_exports(client: LicenseServerClient) -> None:
|
||||
history_rows = list(csv.DictReader(history_response.text.splitlines()))
|
||||
assert history_rows, "Expected history entries for created license key."
|
||||
assert any(license_key in row["action"] for row in history_rows), "History does not reference the license key."
|
||||
|
||||
|
||||
def test_public_key_endpoint(client: LicenseServerClient) -> None:
|
||||
response = client.public_key()
|
||||
|
||||
if response.status_code == 404:
|
||||
detail = response.json().get("detail")
|
||||
assert detail == "License key signing is disabled."
|
||||
return
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.text.strip()
|
||||
assert "public_key" in body
|
||||
|
||||
Reference in New Issue
Block a user