Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double formatting of callables (command, environment, request_headers_override) #437

Merged
merged 2 commits into from
Jan 4, 2024
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
4 changes: 1 addition & 3 deletions jupyter_server_proxy/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,7 @@ def _render_template(self, value):
def _realize_rendered_template(self, attribute):
"""Call any callables, then render any templated values."""
if callable(attribute):
attribute = self._render_template(
call_with_asked_args(attribute, self.process_args)
)
attribute = call_with_asked_args(attribute, self.process_args)
return self._render_template(attribute)

@web.authenticated
Expand Down
8 changes: 8 additions & 0 deletions tests/resources/jupyter_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def cats_only(response, path):
response.code = 403
response.body = b"dogs not allowed"

def my_env():
return {
"MYVAR": "String with escaped {{var}}"
}

c.ServerProxy.servers = {
"python-http": {
Expand All @@ -65,6 +69,10 @@ def cats_only(response, path):
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"mappath": mappathf,
},
"python-http-callable-env": {
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
"environment": my_env,
},
"python-websocket": {
"command": [sys.executable, "./tests/resources/websocket.py", "--port={port}"],
"request_headers_override": {
Expand Down
6 changes: 6 additions & 0 deletions tests/test_proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,9 @@ def test_bad_server_proxy_url(
if status >= 400:
# request should not have been proxied
assert "X-ProxyContextPath" not in r.headers


def test_callable_environment_formatting(a_server_port_and_token: Tuple[int, str]) -> None:
PORT, TOKEN = a_server_port_and_token
r = request_get(PORT, "/python-http-callable-env/test", TOKEN)
assert r.code == 200