Files
wehub-resource-sync 7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

105 lines
3.8 KiB
Python

"""Tests for CredentialStoreBase TTL boundary conditions and remove parameter.
Complements test_credential_store_base.py and test_credential_store_extended.py
by testing precise TTL boundaries using mocked time.time().
"""
import time as time_module
from unittest.mock import patch
from local_deep_research.database.credential_store_base import (
CredentialStoreBase,
)
class ConcreteStore(CredentialStoreBase):
"""Minimal concrete subclass for testing base class logic."""
def store(self, key, username, password):
self._store_credentials(
key, {"username": username, "password": password}
)
def retrieve(self, key, remove=False):
return self._retrieve_credentials(key, remove=remove)
# ---------------------------------------------------------------------------
# _retrieve_credentials boundary conditions
# ---------------------------------------------------------------------------
class TestRetrieveCredentialsBoundary:
"""TTL boundary tests using mocked time."""
def test_not_expired_at_exact_boundary(self):
"""time.time() == expires_at → NOT expired (uses > not >=)."""
store = ConcreteStore(ttl_seconds=100)
with patch.object(time_module, "time", return_value=1000.0):
store.store("k", "user", "pass")
# expires_at = 1000.0 + 100 = 1100.0
with patch.object(time_module, "time", return_value=1100.0):
result = store.retrieve("k")
assert result == ("user", "pass")
def test_expired_just_past_boundary(self):
"""time.time() = expires_at + epsilon → expired."""
store = ConcreteStore(ttl_seconds=100)
with patch.object(time_module, "time", return_value=1000.0):
store.store("k", "user", "pass")
with patch.object(time_module, "time", return_value=1100.001):
result = store.retrieve("k")
assert result is None
def test_expired_entry_deleted_from_store(self):
"""Expired retrieval deletes the entry."""
store = ConcreteStore(ttl_seconds=10)
with patch.object(time_module, "time", return_value=1000.0):
store.store("k", "user", "pass")
with patch.object(time_module, "time", return_value=1011.0):
store.retrieve("k") # triggers deletion
assert "k" not in store._store
# ---------------------------------------------------------------------------
# _cleanup_expired
# ---------------------------------------------------------------------------
class TestCleanupExpired:
"""Tests for _cleanup_expired logic with mocked time."""
def test_some_expired(self):
store = ConcreteStore(ttl_seconds=100)
with patch.object(time_module, "time", return_value=1000.0):
store.store("old", "u1", "p1")
# Insert "new" directly, bypassing _store_credentials' implicit cleanup
with patch.object(time_module, "time", return_value=2000.0):
store._store["new"] = {
"username": "u2",
"password": "p2",
"expires_at": time_module.time() + store.ttl, # 2100
}
store._cleanup_expired()
assert "old" not in store._store
assert "new" in store._store
def test_all_expired(self):
store = ConcreteStore(ttl_seconds=10)
with patch.object(time_module, "time", return_value=1000.0):
store.store("a", "u1", "p1")
store.store("b", "u2", "p2")
with patch.object(time_module, "time", return_value=2000.0):
store._cleanup_expired()
assert len(store._store) == 0
def test_empty_store_no_error(self):
store = ConcreteStore(ttl_seconds=3600)
store._cleanup_expired() # should not raise
assert len(store._store) == 0