-
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 #124 from averevki/mtls-identity-tests
Add a basic mTLS identity tests
- Loading branch information
Showing
8 changed files
with
138 additions
and
13 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
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
Empty file.
44 changes: 44 additions & 0 deletions
44
testsuite/tests/kuadrant/authorino/operator/tls/mtls/test_mtls_identity.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,44 @@ | ||
"""mTLS authentication tests""" | ||
import pytest | ||
from httpx import ReadError, ConnectError | ||
|
||
from testsuite.objects import Rule | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def authorization(authorization, blame, selector_params, cert_attributes): | ||
"""Create AuthConfig with mtls identity and pattern matching rule""" | ||
authorization.remove_all_identities() | ||
|
||
authorization.add_mtls_identity(blame("mtls"), *selector_params) | ||
rule = Rule("auth.identity.Organization", "incl", cert_attributes["O"]) | ||
authorization.add_auth_rule(blame("redhat"), rule) | ||
return authorization | ||
|
||
|
||
def test_mtls_success(envoy_authority, valid_cert, envoy): | ||
"""Test successful mtls authentication""" | ||
with envoy.client(verify=envoy_authority, cert=valid_cert) as client: | ||
response = client.get("/get") | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.parametrize("cert_authority, certificate, err, err_match", [ | ||
pytest.param("envoy_authority", "invalid_cert", ReadError, "unknown ca", id="Invalid certificate"), | ||
pytest.param("invalid_authority", "valid_cert", ConnectError, "certificate verify failed", id="Unknown authority"), | ||
]) | ||
def test_mtls_fail(request, cert_authority, certificate, err, err_match: str, envoy): | ||
"""Test mtls verification with invalid certificate or unknown signed authority""" | ||
ca = request.getfixturevalue(cert_authority) | ||
cert = request.getfixturevalue(certificate) | ||
|
||
with pytest.raises(err, match=err_match): | ||
with envoy.client(verify=ca, cert=cert) as client: | ||
client.get("/get") | ||
|
||
|
||
def test_mtls_unmatched_attributes(envoy_authority, custom_cert, envoy): | ||
"""Test certificate that signed by the trusted CA, though their attributes are unmatched""" | ||
with envoy.client(verify=envoy_authority, cert=custom_cert) as client: | ||
response = client.get("/get") | ||
assert response.status_code == 403 |
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