Skip to content

Commit

Permalink
more exercise of unsafe names in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Oct 2, 2024
1 parent 385782a commit 229ae3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __init__(self, *args, **kwargs):
# runs during test execution only
if 'user' not in kwargs:
user = MockObject()
user.name = 'mock_name'
user.name = 'mock@name'
user.id = 'mock_id'
user.url = 'mock_url'
self.user = user
Expand Down
10 changes: 5 additions & 5 deletions tests/test_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


class MockUser(Mock):
name = 'fake'
name = '[email protected]'
server = Server()

def __init__(self, **kwargs):
Expand Down Expand Up @@ -272,7 +272,7 @@ async def test_spawn_start_in_different_namespace(
async def test_spawn_enable_user_namespaces():
user = MockUser()
spawner = KubeSpawner(user=user, _mock=True, enable_user_namespaces=True)
assert spawner.namespace.endswith(f"-{user.escaped_name}")
assert spawner.namespace.endswith(f"-{safe_slug(user.name)}")


async def test_spawn_start_enable_user_namespaces(
Expand All @@ -289,7 +289,7 @@ async def test_spawn_start_enable_user_namespaces(

spawner = KubeSpawner(
hub=hub,
user=MockUser(name="start"),
user=MockUser(name="start@test"),
config=config,
api_token="abc123",
oauth_client_id="unused",
Expand Down Expand Up @@ -1625,7 +1625,7 @@ async def test_pod_connect_ip(kube_ns, kube_client, config, hub_pod, hub):
async def test_get_pvc_manifest():
c = Config()

username = "mock_name"
username = "mock@name"
slug = safe_slug(username)
c.KubeSpawner.pvc_name_template = "user-{username}"
c.KubeSpawner.storage_extra_labels = {"user": "{username}"}
Expand All @@ -1640,7 +1640,7 @@ async def test_get_pvc_manifest():
assert manifest.metadata.name == f"user-{slug}"
assert manifest.metadata.labels == {
"user": slug,
"hub.jupyter.org/username": username,
"hub.jupyter.org/username": slug,
"app.kubernetes.io/name": "jupyterhub",
"app.kubernetes.io/managed-by": "kubespawner",
"app.kubernetes.io/component": "singleuser-server",
Expand Down

0 comments on commit 229ae3c

Please sign in to comment.