-
Notifications
You must be signed in to change notification settings - Fork 303
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 #856 from minrk/slug-value
fix some safe slug patterns
- Loading branch information
Showing
4 changed files
with
42 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,11 @@ | |
("endswith-", "endswith---165f1166"), | ||
("[email protected]", "user-email-com---0925f997"), | ||
("user-_@_emailß.com", "user-email-com---7e3a7efd"), | ||
("has.dot", "has-dot---03e27fdf"), | ||
("z9", "z9"), | ||
("9z9", "x-9z9---224de202"), | ||
("-start", "start---f587e2dc"), | ||
("üser", "ser---73506260"), | ||
("username--servername", "username-servername---d957f1de"), | ||
("start---f587e2dc", "start-f587e2dc---cc5bb9c9"), | ||
pytest.param("x" * 63, "x" * 63, id="x63"), | ||
|
@@ -51,6 +55,13 @@ def test_safe_slug_max_length(max_length, length, expected): | |
[ | ||
("", ""), | ||
("x", "x"), | ||
("a-b", "a-b"), | ||
("9a", "9a"), | ||
("9.", "x-9---99a1b84b"), | ||
("AbC", "AbC"), | ||
("AbC.", "abc---dbe8c5d1"), | ||
("ab.c", "ab.c"), | ||
("[email protected]", "a-b-c---d648b243"), | ||
("-x", "x---a4209624"), | ||
("x-", "x---c8b60efc"), | ||
pytest.param("x" * 63, "x" * 63, id="x63"), | ||
|
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
|
||
|
||
class MockUser(Mock): | ||
name = 'fake' | ||
name = '[email protected]' | ||
server = Server() | ||
|
||
def __init__(self, **kwargs): | ||
|
@@ -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( | ||
|
@@ -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", | ||
|
@@ -1488,7 +1488,7 @@ async def test_spawner_env(): | |
assert env["STATIC"] == "static" | ||
assert env["EXPANDED"] == f"{slug} (expanded)" | ||
assert env["ESCAPED"] == "{username}" | ||
assert env["CALLABLE"] == "mock_name (callable)" | ||
assert env["CALLABLE"] == "mock@name (callable)" | ||
|
||
|
||
async def test_jupyterhub_supplied_env(): | ||
|
@@ -1503,7 +1503,7 @@ async def test_jupyterhub_supplied_env(): | |
env = pod_manifest.spec.containers[0].env | ||
|
||
# Set via .environment, must be expanded | ||
assert V1EnvVar("HELLO", "It's mock_name") in env | ||
assert V1EnvVar("HELLO", "It's mock@name") in env | ||
# Set by JupyterHub itself, must not be expanded | ||
assert V1EnvVar("JUPYTERHUB_COOKIE_OPTIONS", json.dumps(cookie_options)) in env | ||
|
||
|
@@ -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}"} | ||
|
@@ -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", | ||
|