-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from jsmolar/reconciliation
Add tests for API key Secret reconciliation
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
testsuite/tests/kuadrant/authorino/identity/api_key/test_reconciliation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Tests Secret reconciliation for API key identity verification & authentication""" | ||
import pytest | ||
|
||
from testsuite.httpx.auth import HeaderApiKeyAuth | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def api_key(create_api_key, module_label): | ||
"""Creates API key Secret""" | ||
api_key = "api_key_value" | ||
return create_api_key("api-key", module_label, api_key) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def auth(api_key): | ||
"""Valid API Key Auth""" | ||
return HeaderApiKeyAuth(api_key) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, module_label): | ||
"""Creates AuthConfig with API key identity""" | ||
authorization.add_api_key_identity("api_key", match_label=module_label) | ||
return authorization | ||
|
||
|
||
def test_create_new_api_key(client, create_api_key, module_label): | ||
"""Test reconciliation when API key Secret is freshly created with valid label""" | ||
api_key = create_api_key("api-key", module_label, "new_api_key") | ||
auth = HeaderApiKeyAuth(api_key) | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_delete_api_key(client, auth, api_key): | ||
"""Test reconciliation when API key Secret is deleted""" | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
api_key.delete() | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 401 | ||
|
||
|
||
def test_update_api_key(client, auth, api_key): | ||
"""Test reconciliation when API key Secret is updated""" | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
api_key.update_api_key("update_api_key") | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 401 | ||
|
||
auth = HeaderApiKeyAuth(api_key) | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 |