Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
847b9dcd
Commit
847b9dcd
authored
5 years ago
by
Brendan Abolivier
Browse files
Options
Downloads
Patches
Plain Diff
Make max_delta equal to period * 10%
parent
7e1c7cc2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/config/registration.py
+4
-11
4 additions, 11 deletions
synapse/config/registration.py
synapse/storage/_base.py
+3
-4
3 additions, 4 deletions
synapse/storage/_base.py
tests/rest/client/v2_alpha/test_register.py
+1
-17
1 addition, 17 deletions
tests/rest/client/v2_alpha/test_register.py
with
8 additions
and
32 deletions
synapse/config/registration.py
+
4
−
11
View file @
847b9dcd
...
...
@@ -39,9 +39,7 @@ class AccountValidityConfig(Config):
else
:
self
.
renew_email_subject
=
"
Renew your %(app)s account
"
self
.
startup_job_max_delta
=
self
.
parse_duration
(
config
.
get
(
"
startup_job_max_delta
"
,
0
),
)
self
.
startup_job_max_delta
=
self
.
period
*
10.
/
100.
if
self
.
renew_by_email_enabled
and
"
public_baseurl
"
not
in
synapse_config
:
raise
ConfigError
(
"
Can
'
t send renewal emails without
'
public_baseurl
'"
)
...
...
@@ -133,20 +131,15 @@ class RegistrationConfig(Config):
# This means that, if a validity period is set, and Synapse is restarted (it will
# then derive an expiration date from the current validity period), and some time
# after that the validity period changes and Synapse is restarted, the users
'
# expiration dates won
'
t be updated unless their account is manually renewed.
#
# If set, the ``startup_job_max_delta`` optional setting will make the startup job
# described above set a random expiration date between t + period and
# t + period + startup_job_max_delta, t being the date and time at which the job
# sets the expiration date for a given user. This is useful for server admins that
# want to avoid Synapse sending a lot of renewal emails at once.
# expiration dates won
'
t be updated unless their account is manually renewed. This
# date will be randomly selected within a range [now + period ; now + period + d],
# where d is equal to 10% of the validity period.
#
#account_validity:
# enabled: True
# period: 6w
# renew_at: 1w
# renew_email_subject:
"
Renew your %%(app)s account
"
# startup_job_max_delta: 2d
# The user must provide all of the below types of 3PID when registering.
#
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/_base.py
+
3
−
4
View file @
847b9dcd
...
...
@@ -329,14 +329,13 @@ class SQLBaseStore(object):
user_id (str): User ID to set an expiration date for.
use_delta (bool): If set to False, the expiration date for the user will be
now + validity period. If set to True, this expiration date will be a
random value in the [now + period; now + period + max_delta] range,
max_delta being the configured value for the size of the range, unless
delta is 0, in which case it sets it to now + period.
random value in the [now + period; now + period + d] range, d being a
delta equal to 10% of the validity period.
"""
now_ms
=
self
.
_clock
.
time_msec
()
expiration_ts
=
now_ms
+
self
.
_account_validity
.
period
if
use_delta
and
self
.
_account_validity
.
startup_job_max_delta
:
if
use_delta
:
expiration_ts
=
self
.
rand
.
randrange
(
expiration_ts
,
expiration_ts
+
self
.
_account_validity
.
startup_job_max_delta
,
...
...
This diff is collapsed.
Click to expand it.
tests/rest/client/v2_alpha/test_register.py
+
1
−
17
View file @
847b9dcd
...
...
@@ -436,7 +436,7 @@ class AccountValidityBackgroundJobTestCase(unittest.HomeserverTestCase):
def
make_homeserver
(
self
,
reactor
,
clock
):
self
.
validity_period
=
10
self
.
max_delta
=
10
self
.
max_delta
=
self
.
validity_period
*
10.
/
100.
config
=
self
.
default_config
()
...
...
@@ -453,22 +453,6 @@ class AccountValidityBackgroundJobTestCase(unittest.HomeserverTestCase):
return
self
.
hs
def
test_background_job
(
self
):
"""
Tests whether the account validity startup background job does the right thing,
which is sticking an expiration date to every account that doesn
'
t already have
one.
"""
user_id
=
self
.
register_user
(
"
kermit
"
,
"
user
"
)
self
.
hs
.
config
.
account_validity
.
startup_job_max_delta
=
0
now_ms
=
self
.
hs
.
clock
.
time_msec
()
self
.
get_success
(
self
.
store
.
_set_expiration_date_when_missing
())
res
=
self
.
get_success
(
self
.
store
.
get_expiration_ts_for_user
(
user_id
))
self
.
assertEqual
(
res
,
now_ms
+
self
.
validity_period
)
def
test_background_job_with_max_delta
(
self
):
"""
Tests the same thing as test_background_job, except that it sets the
startup_job_max_delta parameter and checks that the expiration date is within the
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment