Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Parse ui_auth.session_timeout as a duration (instead of treating it as ms) #9426

Merged
merged 13 commits into from
Feb 18, 2021
Merged
1 change: 1 addition & 0 deletions changelog.d/9426.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Calling the 'parse_duration' function so that configs can be specified in terms of number of seconds/hours/etc/.
clokep marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,9 @@ ui_auth:
# seconds.
#
#session_timeout: 15000
# Now ui_auth also allow standard duration formats such as "15s" to allow
# for credential validation to last for 15 seconds.
# session_timeout: "15s"


# Configuration for sending emails from Synapse.
Expand Down
7 changes: 6 additions & 1 deletion synapse/config/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def read_config(self, config, **kwargs):

# User-interactive authentication
ui_auth = config.get("ui_auth") or {}
self.ui_auth_session_timeout = ui_auth.get("session_timeout", 0)
self.ui_auth_session_timeout = self.parse_duration(
ui_auth.get("session_timeout", 0)
)

def generate_config_section(self, config_dir_path, server_name, **kwargs):
return """\
Expand Down Expand Up @@ -106,4 +108,7 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# seconds.
#
#session_timeout: 15000
# Now ui_auth also allow standard duration formats such as "15s" to allow
# for credential validation to last for 15 seconds.
# session_timeout: "15s"
clokep marked this conversation as resolved.
Show resolved Hide resolved
"""
2 changes: 1 addition & 1 deletion tests/rest/client/v2_alpha/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_cannot_change_uri(self):
},
)

@unittest.override_config({"ui_auth": {"session_timeout": 5 * 1000}})
@unittest.override_config({"ui_auth": {"session_timeout": "5s"}})
def test_can_reuse_session(self):
"""
The session can be reused if configured.
Expand Down