Projet

Général

Profil

0001-tokens-limit-expiration-to-1-year-61222.patch

Frédéric Péters, 31 janvier 2022 14:18

Télécharger (1,39 ko)

Voir les différences:

Subject: [PATCH] tokens: limit expiration to 1 year (#61222)

 wcs/qommon/tokens.py | 5 +++++
 1 file changed, 5 insertions(+)
wcs/qommon/tokens.py
26 26

  
27 27
class Token(StorableObject):
28 28
    _names = 'tokens'
29
    MAX_DELAY = 365
29 30

  
30 31
    type = None
31 32
    expiration = None
......
37 38
            self.set_expiration_delay(expiration_delay)
38 39

  
39 40
    def set_expiration_delay(self, expiration_delay):
41
        expiration_delay = min(expiration_delay, self.MAX_DELAY * 86400)  # max 1 year.
40 42
        self.expiration = now() + datetime.timedelta(seconds=expiration_delay)
41 43

  
42 44
    @classmethod
......
60 62

  
61 63
    def migrate(self):
62 64
        if isinstance(self.expiration, (float, int)):
65
            self.expiration = min(
66
                self.expiration, (now() + datetime.timedelta(days=self.MAX_DELAY)).timestamp()
67
            )
63 68
            self.expiration = make_aware(datetime.datetime.fromtimestamp(self.expiration), is_dst=True)
64 69
        self.expiration_check()
65 70

  
66
-