Example #1
0
    def test_invalidate(self, monkeypatch):
        session_ids = iter(["123456", "7890"])
        monkeypatch.setattr(crypto, "random_token", lambda: next(session_ids))
        session = Session({"foo": "bar"}, "original id", False)

        assert session == {"foo": "bar"}
        assert session.sid == "original id"
        assert not session.new
        assert not session.invalidated

        session.invalidate()

        assert session == {}
        assert session.sid == "123456"
        assert session.new
        assert session.invalidated == {"original id"}

        session.invalidate()

        assert session == {}
        assert session.sid == "7890"
        assert session.new
        assert session.invalidated == {"original id", "123456"}
Example #2
0
 def test_methods_call_changed(self, data, method, args):
     session = Session(data)
     session.changed = pretend.call_recorder(lambda: None)
     getattr(session, method)(*args)
     assert session.changed.calls == [pretend.call()]
Example #3
0
 def test_should_save(self):
     session = Session()
     assert not session.should_save()
     session.changed()
     assert session.should_save()
Example #4
0
 def test_invalidate_empty(self):
     session = Session({"foo": "bar"})
     session.invalidate()
     assert session == {}
     assert session.invalidated == set()
Example #5
0
 def test_changed_marks_as_changed(self):
     session = Session()
     assert not session._changed
     session.changed()
     assert session._changed
Example #6
0
    def test_get_totp_secret(self, monkeypatch):
        session = Session()
        session[session._totp_secret_key] = b"foobar"

        assert session.get_totp_secret() == b"foobar"
Example #7
0
 def test_delete(self):
     session = Session({}, "123456", False)
     assert not session.deleted
     session.delete()
     assert session.deleted
Example #8
0
 def test_reauth_needed_no_value(self):
     session = Session()
     assert session.needs_reauthentication(666)
Example #9
0
    def test_get_webauthn_challenge(self):
        session = Session()
        session[session._webauthn_challenge_key] = "not_a_real_challenge"

        assert session.get_webauthn_challenge() == "not_a_real_challenge"
Example #10
0
 def test_reauth_unneeded(self):
     session = Session()
     session.record_auth_timestamp()
     assert not session.needs_reauthentication(666)
Example #11
0
 def test_reauth_needed(self):
     session = Session()
     session[session._reauth_timestamp_key] = 0
     assert session.needs_reauthentication(666)
Example #12
0
 def test_reauth_record(self, pyramid_request):
     session = Session()
     assert not session.should_save()
     session.record_auth_timestamp()
     assert session.should_save()
Example #13
0
 def get(self, sid):
     return Session({}, sid, False)
Example #14
0
 def new(self):
     return Session({}, "123456", True)
Example #15
0
 def test_generate_flash_key(self, queue, expected):
     session = Session()
     assert session._get_flash_queue_key(queue) == expected
Example #16
0
    def test_clear_webauthn_challenge(self):
        session = Session()
        session[session._webauthn_challenge_key] = "not_a_real_challenge"

        session.clear_webauthn_challenge()
        assert not session[session._webauthn_challenge_key]
Example #17
0
    def test_get_csrf_token_empty(self):
        session = Session()
        session.new_csrf_token = pretend.call_recorder(lambda: "123456")

        assert session.get_csrf_token() == "123456"
        assert session.new_csrf_token.calls == [pretend.call()]
Example #18
0
 def test_password_outdated(self, stored, current, expected):
     session = Session()
     session.record_password_timestamp(stored)
     assert session.password_outdated(current) == expected
Example #19
0
    def test_clear_totp_secret(self):
        session = Session()
        session[session._totp_secret_key] = b"foobar"

        session.clear_totp_secret()
        assert not session[session._totp_secret_key]
Example #20
0
 def test_cycle(self):
     session = Session({}, "123456", False)
     assert not session.cycled
     session.cycle()
     assert session.cycled