-
Notifications
You must be signed in to change notification settings - Fork 17
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 #63 from jsmolar/api_key_auth
Add cluster-wide API key identity tests
- Loading branch information
Showing
5 changed files
with
75 additions
and
11 deletions.
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
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
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
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
60 changes: 60 additions & 0 deletions
60
testsuite/tests/kuadrant/authorino/operator/clusterwide/test_all_namespace_api_key.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,60 @@ | ||
""" | ||
Tests for API key identity for AuthConfig configured with all_namespaces=true for cluster-wide | ||
API key secret placement. | ||
""" | ||
import pytest | ||
|
||
from testsuite.httpx.auth import HeaderApiKeyAuth | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def api_key(create_api_key, module_label, openshift2): | ||
"""Creates API key Secret""" | ||
api_key = "cluster_wide_api_key" | ||
create_api_key("wide-api-key", module_label, api_key, openshift2) | ||
return api_key | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def auth(api_key): | ||
"""Valid API Key Auth""" | ||
return HeaderApiKeyAuth(api_key) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def invalid_label_selector(): | ||
"""Label for API key secret that is different from the one specified in AuthConfig""" | ||
return "invalid_api_label" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def invalid_api_key(create_api_key, invalid_label_selector, openshift2): | ||
"""Creates API key Secret with label that does not match any of the labelSelectors defined by AuthConfig""" | ||
api_key = "invalid_api_key" | ||
create_api_key("invalid-api-key", invalid_label_selector, api_key, openshift2) | ||
return api_key | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def invalid_auth(invalid_api_key): | ||
"""Invalid key Auth""" | ||
return HeaderApiKeyAuth(invalid_api_key) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, module_label): | ||
"""Creates AuthConfig with API key identity""" | ||
authorization.add_api_key_identity("api_key", all_namespaces=True, match_label=module_label) | ||
return authorization | ||
|
||
|
||
def test_correct_auth(client, auth): | ||
"""Tests request with correct API key""" | ||
response = client.get("/get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_invalid_api_key(client, invalid_auth): | ||
"""Tests request with wrong API key""" | ||
response = client.get("/get", auth=invalid_auth) | ||
assert response.status_code == 401 |