Ghost/ghost/core/test/unit/server/models
Simon Backx 789e2c96c0
🐛 Fixed SingleUseTokens being cleared on boot (#15999)
fixes https://github.com/TryGhost/Team/issues/1996

**Issue**
Our Magic links are valid for 24 hours. After first usage, the token
lives for a further 10 minutes, so that in the case of email servers or
clients that "visit" links, the token can still be used.

The implementation of the 10 minute window uses setTimeout, meaning if
the process is interrupted, the 10 minute window is ignored completely,
and the token will continue to live for the remainder of it's 24 hour
validity period. To prevent that, the tokens are cleared on boot at the
moment.

**Solution**

To remove the boot clearing logic, we need to make sure the tokens are
only valid for 10 minutes after first use even during restarts.

This commit adds 3 new fields to the SingleUseToken model:
- updated_at: for storing the last time the token was changed/used). Not
really used atm.
- first_used_at: for storing the first time the token was used
- used_count: for storing the number of times the token has been used

Using these fields:
- A token can only be used 3 times
- A token is only valid for 10 minutes after first use, even if the
server restarts in between
- A token is only valid for 24 hours after creation (not changed)

We now also delete expired tokens in a separate job instead of on boot /
in a timeout.
2023-01-04 09:49:39 +01:00
..
base Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
api-key.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
comment.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
custom-theme-setting.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
email-spam-complaint-event.test.js Added email_spam_complaint_events table and model 2022-11-29 18:13:12 +07:00
integration.test.js Added core type integrations to API serializer 2022-08-12 14:18:44 +01:00
invite.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
member-click-event.test.js Added post_id filter and total to activity feed API (#15650) 2022-10-18 15:52:04 +02:00
member-created-event.test.js Added ENUM validation for member/subscription created events (#15312) 2022-08-25 15:39:37 +02:00
member-feedback.test.js Added members_feedback table (#15581) 2022-10-11 13:21:31 +02:00
member-paid-subscription-event.test.js Added post_id filter and total to activity feed API (#15650) 2022-10-18 15:52:04 +02:00
member-subscribe-event.test.js Added ENUM validation for member/subscription created events (#15312) 2022-08-25 15:39:37 +02:00
member.test.js Handled storing complimentary subscription expiry 2022-08-19 18:20:52 +05:30
newsletter.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
permission.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
post.test.js Added post sentiment (#15592) 2022-10-11 17:52:14 +02:00
session.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
settings.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
single-use-token.test.js 🐛 Fixed SingleUseTokens being cleared on boot (#15999) 2023-01-04 09:49:39 +01:00
stripe-customer-subscription.test.js Enabled free trials via tiers and offers 2022-08-24 19:24:31 +05:30
subscription-created-event.test.js Added ENUM validation for member/subscription created events (#15312) 2022-08-25 15:39:37 +02:00
suppression.test.js Added suppressions table and model 2022-11-29 18:12:24 +07:00
tag.test.js Converted Ghost repo into a monorepo 2022-07-20 16:41:05 +02:00
user.test.js Handled fetching staff users for email alerts 2022-08-25 18:01:52 +05:30