mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
b842b825ab
The API schema is not checked for changes until after a TTL is expired. A one-hour TTL was hardcoded which makes development tedious because the only way to force a schema update is to remember to remove files between invocations. This adds a new environment variable, schema_ttl, to configure the TTL returned by the server to schema() calls. This can be set low to ensure a frequent refresh during development. If the client is in compat mode, that is if client is working against a server that doesn't support the schema() command, then use the client's schema_ttl instead so that the user still has control. Re-check validity before writing the cache. This saves us both a disk write and the possibility of updating the expiration with a ttl of 0. This can happen if the fingerprint is still valid (not expired, no language change) the schema check is skipped so we have no server-provided ttl. https://pagure.io/freeipa/issue/8492 Signed-off-by: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Stanislav Levin <slev@altlinux.org> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
#
|
|
# Copyright (C) 2021 FreeIPA Contributors see COPYING for license
|
|
#
|
|
import pytest
|
|
import time
|
|
|
|
from ipaclient.remote_plugins import ServerInfo
|
|
|
|
|
|
class TestServerInfo(ServerInfo):
|
|
"""Simplified ServerInfo class with hardcoded values"""
|
|
def __init__(self, fingerprint='deadbeef', hostname='ipa.example.test',
|
|
force_check=False, language='en_US',
|
|
version='2.0', expiration=None):
|
|
self._force_check = force_check
|
|
self._language = language
|
|
self._now = time.time()
|
|
self._dict = {
|
|
'fingerprint': fingerprint,
|
|
'expiration': expiration or time.time() + 3600,
|
|
'language': language,
|
|
'version': version,
|
|
}
|
|
|
|
def _read(self):
|
|
"""Running on test controller, this is a no-op"""
|
|
|
|
def _write(self):
|
|
"""Running on test controller, this is a no-op"""
|
|
|
|
|
|
@pytest.mark.tier0
|
|
class TestIPAServerInfo:
|
|
"""Test that ServerInfo detects changes in remote configuration"""
|
|
|
|
def test_valid(self):
|
|
server_info = TestServerInfo()
|
|
assert server_info.is_valid() is True
|
|
|
|
def test_force_check(self):
|
|
server_info = TestServerInfo(force_check=True)
|
|
assert server_info.is_valid() is False
|
|
|
|
def test_language_change(self):
|
|
server_info = TestServerInfo()
|
|
assert server_info.is_valid() is True
|
|
server_info._language = 'fr_FR'
|
|
assert server_info.is_valid() is False
|
|
server_info._language = 'en_US'
|
|
|
|
def test_expired(self):
|
|
server_info = TestServerInfo(expiration=time.time() + 2)
|
|
assert server_info.is_valid() is True
|
|
|
|
# skip past the expiration time
|
|
server_info._now = time.time() + 5
|
|
assert server_info.is_valid() is False
|
|
|
|
# set a new expiration time in the future
|
|
server_info.update_validity(10)
|
|
assert server_info.is_valid() is True
|
|
|
|
# move to the future beyond expiration
|
|
server_info._now = time.time() + 15
|
|
assert server_info.is_valid() is False
|
|
|
|
def test_update_validity(self):
|
|
server_info = TestServerInfo(expiration=time.time() + 1)
|
|
|
|
# Expiration and time are one second off so the cache is ok
|
|
assert server_info.is_valid() is True
|
|
|
|
# Simulate time passing by
|
|
server_info._now = time.time() + 2
|
|
|
|
# the validity should be updated because it is now expired
|
|
server_info.update_validity(3600)
|
|
|
|
# the cache is now valid for another hour
|
|
assert server_info.is_valid() is True
|