Beispiel #1
0
def test_renew_session_token_SUCCESS(mock_datetime, monkeypatch):
    monkeypatch_environment(monkeypatch)

    mock_now = datetime(2001, 1, 1)
    mock_datetime.utcnow.return_value = mock_now

    session = Session(owner='*****@*****.**', renewer='*****@*****.**')
    session.save()
    assert session.expires_at == datetime_to_integer(mock_now) + settings.SESSION_RENEW_PERIOD

    mock_now = datetime(2002, 2, 2)
    mock_datetime.utcnow.return_value = mock_now

    session_token = generate_session_token(session)
    response, context = renew_session_token('*****@*****.**', session_token)
    assert isinstance(response, RenewSessionTokenResponse)
    session = Session.get(session.id)
    assert session.expires_at == datetime_to_integer(mock_now) + settings.SESSION_RENEW_PERIOD
Beispiel #2
0
 def calculate_expiry_time(self, expires_in):
     # Calculate expiry date+time in milliseconds
     now = datetime.utcnow()
     return datetime_to_integer(now + timedelta(seconds=expires_in))
Beispiel #3
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     if self.creation_time is None:
         self.creation_time = datetime_to_integer(datetime.utcnow())
Beispiel #4
0
 def is_expired(self):
     now = datetime.utcnow()
     return datetime_to_integer(now) >= self.expires_at
Beispiel #5
0
 def extend_lifetime(self):
     now = datetime_to_integer(datetime.utcnow())
     self.expires_at = now + min(settings.SESSION_RENEW_PERIOD,
                                 settings.SESSION_MAXIMUM_LIFETIME)