From a55bb9c4ea33b58f3b866519c0885c5b6d2837e7 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 6 Sep 2022 12:01:32 -0700 Subject: [PATCH] Improve templating tests Add a test of the /etc/passwd template and adjust the /etc/group template to closer reflect what we'll be doing in Phalanx. --- tests/resourcemgr_test.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/resourcemgr_test.py b/tests/resourcemgr_test.py index 12655a3..3d1f4c9 100644 --- a/tests/resourcemgr_test.py +++ b/tests/resourcemgr_test.py @@ -33,10 +33,12 @@ name: group namespace: "{{ user_namespace }}" data: + user: | + {{user}}:x:{{uid}}:{{gid if gid else uid}}::/home/{{ user }}:/bin/bash group: | - {{user}}:x:{{gid if gid else uid}}:{% for group in groups %}\ -{% if "id" in group %} - {{ group.name }}:x:{{ group.id }}:{{ user }}{% endif %}{% endfor %} + {%- for group in groups %}{% if "id" in group %} + {{ group.name }}:x:{{ group.id }}:\ +{{ user if group.id != gid else ""}}{% endif %}{% endfor %} - apiVersion: v1 kind: ConfigMap metadata: @@ -156,6 +158,7 @@ async def test_create_kubernetes_resources( "gid": 1551, "groups": [ {"name": "foo", "id": 1235}, + {"name": "primary", "id": 1551}, {"name": "bar", "id": 4567}, {"name": "baz"}, ], @@ -242,11 +245,12 @@ async def test_create_kubernetes_resources( "labels": spawner.extra_labels, }, "data": { + "user": "someuser:x:1234:1551::/home/someuser:/bin/bash\n", "group": ( - "someuser:x:1551:\n" "foo:x:1235:someuser\n" + "primary:x:1551:\n" "bar:x:4567:someuser\n" - ) + ), }, }, { @@ -263,7 +267,7 @@ async def test_create_kubernetes_resources( "FIREFLY_ROUTE": "/portal/app", "HUB_ROUTE": "/nb/hub/", "EXTERNAL_GID": "1551", - "EXTERNAL_GROUPS": "foo:1235,bar:4567", + "EXTERNAL_GROUPS": "foo:1235,primary:1551,bar:4567", "EXTERNAL_UID": "1234", "ACCESS_TOKEN": "user-token", "IMAGE_DIGEST": "sha256:123456789abcdef",