Skip to content

Commit

Permalink
Merge pull request #437 from diocas/main
Browse files Browse the repository at this point in the history
Fix double formatting of callables (`command`, `environment`, `request_headers_override`)
  • Loading branch information
consideRatio authored Jan 4, 2024
2 parents 8a4d62b + 40a37b3 commit 98eff01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 98eff01

Please sign in to comment.