def test_04_cleanup_authcache(self):
        # cleanup everything!
        r = cleanup(100000000)
        # Create some entries:
        AuthCache("grandpa",
                  self.realm,
                  self.resolver,
                  _hash_password(self.password),
                  first_auth=datetime.datetime.utcnow() -
                  datetime.timedelta(days=10),
                  last_auth=datetime.datetime.utcnow() -
                  datetime.timedelta(days=2)).save()
        AuthCache("grandpa",
                  self.realm,
                  self.resolver,
                  _hash_password(self.password),
                  first_auth=datetime.datetime.utcnow() -
                  datetime.timedelta(minutes=10),
                  last_auth=datetime.datetime.utcnow() -
                  datetime.timedelta(minutes=2)).save()

        # Now we delete entries, that are older than 20 minutes. Only the 2 days old
        # should be deleted. Not the 2 minutes old.
        r = cleanup(10)
        self.assertEqual(1, r)
Exemplo n.º 2
0
    def test_04_cleanup_authcache(self):
        # cleanup everything!
        r = cleanup(100000000)
        # Create some entries:
        AuthCache("grandpa", self.realm, self.resolver, _hash_password(self.password),
                  first_auth=datetime.datetime.utcnow() - datetime.timedelta(
                      days=10),
                  last_auth=datetime.datetime.utcnow() - datetime.timedelta(
                      days=2)).save()
        AuthCache("grandpa", self.realm, self.resolver, _hash_password(self.password),
                  first_auth=datetime.datetime.utcnow() - datetime.timedelta(
                      minutes=10),
                  last_auth=datetime.datetime.utcnow() - datetime.timedelta(
                      minutes=2)).save()

        # Now we delete entries, that are older than 20 minutes. Only the 2 days old
        # should be deleted. Not the 2 minutes old.
        r = cleanup(10)
        self.assertEqual(1, r)
Exemplo n.º 3
0
    def test_05_old_hashes(self):
        from privacyidea.lib.crypto import hash
        # Test that old hashes do not break the code
        r = cleanup(100000000)
        # Add an entry with an old password hash
        AuthCache("grandpa", self.realm, self.resolver, hash("old password", seed=""),
                  first_auth=datetime.datetime.utcnow() - datetime.timedelta(
                      minutes=10),
                  last_auth=datetime.datetime.utcnow() - datetime.timedelta(
                      minutes=2)).save()

        r = verify_in_cache("grandpa", self.realm, self.resolver, "old password")
        self.assertFalse(r)