Skip to content

Commit

Permalink
test(jans-pycloudlib): add testcases for configuration schema updates
Browse files Browse the repository at this point in the history
Signed-off-by: iromli <[email protected]>
  • Loading branch information
iromli committed Jan 8, 2025
1 parent 6bf583b commit f952fe3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions jans-pycloudlib/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,51 @@ def test_random_optional_scopes(value):

with pytest.raises(ValidationError):
ConfigmapSchema().validate_optional_scopes(value)


def test_load_schema_key(tmpdir):
from jans.pycloudlib.schema import load_schema_key

src = tmpdir.join("configuration.key")
src.write("abcd")
assert load_schema_key(str(src)) == "abcd"


def test_maybe_encrypted_schema_file_missing():
from jans.pycloudlib.schema import maybe_encrypted_schema

_, err, _ = maybe_encrypted_schema("/path/to/schema/file", "/path/to/schema/key")
assert "error" in err


def test_maybe_encrypted_schema(tmpdir):
from jans.pycloudlib.schema import maybe_encrypted_schema

src = tmpdir.join("configuration.json")
src.write("zLBGM41dAfA2JuIkVHRKa+/WwVo/8oQAdD0LUT3jGfhqp/euYdDhf+kTiKwfb1Sv28zYL12JlO+3oSl6ZlhiTw==")

src_key = tmpdir.join("configuration.key")
src_key.write("6Jsv61H7fbkeIkRvUpnZ98fu")

out, _, _ = maybe_encrypted_schema(str(src), str(src_key))
assert out == {"_configmap": {"hostname": "example.com"}}


def test_schema_exclude_configmap(tmpdir):
from jans.pycloudlib.schema import load_schema_from_file

src = tmpdir.join("configuration.json")
src.write('{"_configmap": {}, "_secret": {"admin_password": "Test1234#"}}')

out, _, code = load_schema_from_file(str(src), exclude_configmap=True)
assert "_configmap" not in out and code == 0


def test_schema_exclude_secret(tmpdir):
from jans.pycloudlib.schema import load_schema_from_file

src = tmpdir.join("configuration.json")
src.write('{"_configmap": {"city": "Austin", "country_code": "US", "admin_email": "[email protected]", "hostname": "example.com", "orgName": "Example Inc.", "state": "TX"}, "_secret": {}}')

out, _, code = load_schema_from_file(str(src), exclude_secret=True)
assert "_secret" not in out and code == 0

0 comments on commit f952fe3

Please sign in to comment.