Skip to content

Commit

Permalink
Merge pull request #7881 from ckan/allow-none-as-session-timeout
Browse files Browse the repository at this point in the history
fix: Allow `None` for `beaker.session.timeout`
  • Loading branch information
amercader committed Nov 2, 2023
2 parents a8eb4d7 + e021af3 commit 665ca43
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/7881.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Empty string in `beaker.session.timeout` produces an error instead of never-expiring session
2 changes: 1 addition & 1 deletion ckan/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def ipython(namespace: Mapping[str, Any], banner: str) -> None:
from traitlets.config.loader import Config

c = Config()
c.TerminalInteractiveShell.banner2 = banner # type: ignore
c.TerminalInteractiveShell.banner2 = banner

IPython.start_ipython([], user_ns=namespace, config=c)

Expand Down
3 changes: 1 addition & 2 deletions ckan/config/config_declaration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ groups:
browsers are instructed to not send the cookie over anything other than an SSL connection.
- key: beaker.session.timeout
type: int
default: 600
validators: int_validator
description: |
Seconds until the session is considered invalid, after which it will be ignored and invalidated.
This number is based on the time since the session was last accessed, not from when the session was created.
Expand Down
18 changes: 18 additions & 0 deletions ckan/tests/config/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ def get_blueprint(self):
blueprint.add_url_rule(*rule)

return blueprint


@pytest.mark.parametrize("timeout,normalized", [
(None, None),
("", None),
("123", 123),
("1_000_000", 1_000_000),
("-1", -1),
])
def test_beaker_session_timeout(
monkeypatch, ckan_config, make_app, timeout, normalized
):
"""Beaker timeout accepts `None`(never expires) and int(expires in
n-seconds) values.
"""
monkeypatch.setitem(ckan_config, "beaker.session.timeout", timeout)
make_app()

0 comments on commit 665ca43

Please sign in to comment.