Files
wehub-resource-sync 7a0da7932b
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
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

185 lines
6.6 KiB
Python

"""Tests for SessionPasswordStore."""
import time
class TestSessionPasswordStore:
"""Tests for SessionPasswordStore class."""
def test_init_with_default_ttl(self):
"""SessionPasswordStore initializes with default 24-hour TTL."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore()
# TTL should be 24 hours in seconds
assert store.ttl == 24 * 3600
def test_init_with_custom_ttl(self):
"""SessionPasswordStore accepts custom TTL in hours."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=12)
assert store.ttl == 12 * 3600
def test_store_session_password_stores_correctly(self):
"""store_session_password stores password correctly."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("testuser", "session123", "mypassword")
# Verify it was stored
result = store.get_session_password("testuser", "session123")
assert result == "mypassword"
def test_get_session_password_returns_password(self):
"""get_session_password returns the stored password."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("user1", "sess1", "pass123")
result = store.get_session_password("user1", "sess1")
assert result == "pass123"
def test_get_session_password_nonexistent_returns_none(self):
"""get_session_password returns None for nonexistent entries."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
result = store.get_session_password("nonexistent", "nosession")
assert result is None
def test_clear_session_clears_entry(self):
"""clear_session removes the stored password."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("user1", "sess1", "pass123")
# Verify stored
assert store.get_session_password("user1", "sess1") == "pass123"
# Clear
store.clear_session("user1", "sess1")
# Verify cleared
assert store.get_session_password("user1", "sess1") is None
def test_clear_session_nonexistent_entry_no_error(self):
"""clear_session does not raise error for nonexistent entry."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
# Should not raise
store.clear_session("nonexistent", "nosession")
def test_session_key_format_is_username_session_id(self):
"""Session key format is (username, session_id) tuple."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("myuser", "mysession", "pass")
# Check the internal key format
expected_key = ("myuser", "mysession")
assert expected_key in store._store
def test_password_expires_after_ttl(self):
"""Password expires and returns None after TTL."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
# Use a very short TTL (1 second converted from hours)
# But we can manipulate the store directly for testing
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("user1", "sess1", "pass123")
# Manually set expiration to past
key = ("user1", "sess1")
store._store[key]["expires_at"] = time.time() - 1
# Should return None
result = store.get_session_password("user1", "sess1")
assert result is None
def test_store_alias_method(self):
"""store() is an alias for store_session_password()."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store("alias_user", "alias_session", "alias_pass")
result = store.get_session_password("alias_user", "alias_session")
assert result == "alias_pass"
def test_retrieve_alias_method(self):
"""retrieve() is an alias for get_session_password()."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("user1", "sess1", "pass123")
result = store.retrieve("user1", "sess1")
assert result == "pass123"
def test_multiple_sessions_same_user(self):
"""Can store multiple sessions for same user."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("user1", "session_a", "pass_a")
store.store_session_password("user1", "session_b", "pass_b")
assert store.get_session_password("user1", "session_a") == "pass_a"
assert store.get_session_password("user1", "session_b") == "pass_b"
def test_overwrite_session_password(self):
"""Storing same session again overwrites password."""
from local_deep_research.database.session_passwords import (
SessionPasswordStore,
)
store = SessionPasswordStore(ttl_hours=1)
store.store_session_password("user1", "sess1", "original")
store.store_session_password("user1", "sess1", "updated")
result = store.get_session_password("user1", "sess1")
assert result == "updated"
class TestSessionPasswordStoreGlobalInstance:
"""Tests for the global session_password_store instance."""
def test_global_instance_is_session_password_store(self):
"""Global instance is SessionPasswordStore type."""
from local_deep_research.database.session_passwords import (
session_password_store,
SessionPasswordStore,
)
assert isinstance(session_password_store, SessionPasswordStore)