Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pygobuildinfo = "0.1.28"

[tool.poetry.group.dev.dependencies]
tox = "3.28.0"
pytest = "9.0.3"
pytest = "9.1.0"
pytest-xdist = "3.8.0"
pytest-benchmark = "5.2.3"
responses = "0.26.1"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ def mock_get_token(url: str) -> Optional[str]:
return {
"id_token": jwt.encode(
{"exp": time.time() + 100, "from_cache": True},
"secret",
"secret10" * 4,
algorithm="HS256",
)
}
elif url == "https://expired.example.com":
return {
"id_token": jwt.encode(
{"exp": time.time() - 100, "from_cache": True},
"secret",
"secret10" * 4,
algorithm="HS256",
)
}
Expand Down
118 changes: 61 additions & 57 deletions tests/test_k8sobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,61 +72,63 @@

@pytest.mark.parametrize(
"k8sdict,expected",
zip(
[None] + _test_objs,
[
{
"kind": "",
"name": "",
"namespace": "",
},
{
"kind": "ServiceAccount",
"name": "test",
"namespace": "test",
},
{
"kind": "ServiceAccount",
"name": "test-sa-2",
"namespace": "test",
},
{
"kind": "Pod",
"name": "test",
"namespace": "test",
},
{
"kind": "Role",
"name": "test-role",
"namespace": "test",
"spec": {
"test": "testing",
list(
zip(
[None] + _test_objs,
[
{
"kind": "",
"name": "",
"namespace": "",
},
},
{
"kind": "Role",
"name": "test-role",
"namespace": "test-2",
"spec": {
"test": "testing2",
{
"kind": "ServiceAccount",
"name": "test",
"namespace": "test",
},
},
{
"kind": "ClusterRole",
"namespace": "",
"name": "test-cr",
},
{
"kind": "ClusterRole",
"namespace": "",
"name": "test-cr-2",
},
{
"name": "",
"namespace": "",
"kind": "",
},
],
{
"kind": "ServiceAccount",
"name": "test-sa-2",
"namespace": "test",
},
{
"kind": "Pod",
"name": "test",
"namespace": "test",
},
{
"kind": "Role",
"name": "test-role",
"namespace": "test",
"spec": {
"test": "testing",
},
},
{
"kind": "Role",
"name": "test-role",
"namespace": "test-2",
"spec": {
"test": "testing2",
},
},
{
"kind": "ClusterRole",
"namespace": "",
"name": "test-cr",
},
{
"kind": "ClusterRole",
"namespace": "",
"name": "test-cr-2",
},
{
"name": "",
"namespace": "",
"kind": "",
},
],
)
),
)
def test_k8sobject_constructor(k8sdict, expected):
Expand Down Expand Up @@ -164,10 +166,12 @@ def test_k8sobject_constructor(k8sdict, expected):

@pytest.mark.parametrize(
"k8sdict,to_cluster_scoped,to_ns_scoped",
zip(
_test_objs,
[False, False, False, False, False, True, True, True],
[False, False, True, True, True, True, True, True],
list(
zip(
_test_objs,
[False, False, False, False, False, True, True, True],
[False, False, True, True, True, True, True, True],
)
),
)
def test_k8sobject_less_than(k8sdict, to_cluster_scoped, to_ns_scoped):
Expand Down
18 changes: 10 additions & 8 deletions tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from commodore import login
from commodore import tokencache

akey = "a" * 32


def mock_open_browser(authorization_endpoint: str, code="foobar"):
def mock(request_uri: str):
Expand Down Expand Up @@ -156,7 +158,7 @@ def test_fetch_token(mock_login, config: Config, tmp_path, fs, cached):
if cached:
expected_token_payload["marker"] = "id-456"

expected_token = jwt.encode(expected_token_payload, "aaaaaa")
expected_token = jwt.encode(expected_token_payload, akey)
if cached:
cache_contents = {config.api_url: {"id_token": expected_token}}

Expand Down Expand Up @@ -199,13 +201,13 @@ def test_refresh_tokens(config: Config, tmp_path, fs, idp_status_code):
}

current_tokens = {
"id_token": jwt.encode(current_id_token, "aaaaaa"),
"refresh_token": jwt.encode(current_refresh_token, "aaaaaa"),
"id_token": jwt.encode(current_id_token, akey),
"refresh_token": jwt.encode(current_refresh_token, akey),
}
new_tokens = {
"access_token": "dummy-access-token-456",
"id_token": jwt.encode(new_id_token, "aaaaaa"),
"refresh_token": jwt.encode(new_refresh_token, "aaaaaa"),
"id_token": jwt.encode(new_id_token, akey),
"refresh_token": jwt.encode(new_refresh_token, akey),
}
cache_contents = {config.api_url: current_tokens}

Expand Down Expand Up @@ -263,14 +265,14 @@ def test_refresh_tokens_not_needed(

id_token = {"marker": "id", "exp": time.time() - 10}
tokens = {
"id_token": jwt.encode(id_token, "aaaaaa"),
"id_token": jwt.encode(id_token, akey),
}
if expired_refresh_token:
tokens["refresh_token"] = jwt.encode(
{"marker": "R", "exp": time.time() - 10}, "aaaaaa"
{"marker": "R", "exp": time.time() - 10}, akey
)
if broken_refresh_token:
rt = jwt.encode({"marker": "R", "exp": time.time() + 600}, "aaaaaa")
rt = jwt.encode({"marker": "R", "exp": time.time() + 600}, akey)
tokens["refresh_token"] = f"X{rt[1:]}"
cache_contents = {config.api_url: tokens}
fs.create_file(
Expand Down
Loading