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
141 lines
5.2 KiB
Python
141 lines
5.2 KiB
Python
"""
|
|
Tests for _get_min_kdf_iterations() in database/sqlcipher_utils.py
|
|
|
|
Tests cover:
|
|
- Production mode (no test env vars) returns 100K iterations
|
|
- PYTEST_CURRENT_TEST env var triggers test mode (1 iteration)
|
|
- LDR_TEST_MODE env var triggers test mode (1 iteration)
|
|
- Both env vars set → still returns 1
|
|
- Constants have correct values
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
class TestGetMinKdfIterations:
|
|
"""Tests for _get_min_kdf_iterations()."""
|
|
|
|
def test_production_mode_returns_100k(self, monkeypatch):
|
|
"""No test env vars → production iterations (100_000)."""
|
|
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
|
|
monkeypatch.delenv("LDR_TEST_MODE", raising=False)
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 100_000
|
|
|
|
def test_pytest_current_test_triggers_test_mode(self, monkeypatch):
|
|
"""PYTEST_CURRENT_TEST set → test iterations (1)."""
|
|
monkeypatch.setenv("PYTEST_CURRENT_TEST", "tests/test_foo.py::test_bar")
|
|
monkeypatch.delenv("LDR_TEST_MODE", raising=False)
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 1
|
|
|
|
def test_ldr_test_mode_triggers_test_mode(self, monkeypatch):
|
|
"""LDR_TEST_MODE set → test iterations (1)."""
|
|
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
|
|
monkeypatch.setenv("LDR_TEST_MODE", "1")
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 1
|
|
|
|
def test_both_env_vars_set(self, monkeypatch):
|
|
"""Both env vars set → still returns test iterations."""
|
|
monkeypatch.setenv("PYTEST_CURRENT_TEST", "tests/test_foo.py::test_bar")
|
|
monkeypatch.setenv("LDR_TEST_MODE", "1")
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 1
|
|
|
|
def test_empty_pytest_current_test_is_production(self, monkeypatch):
|
|
"""Empty string for PYTEST_CURRENT_TEST is falsy → production mode."""
|
|
monkeypatch.setenv("PYTEST_CURRENT_TEST", "")
|
|
monkeypatch.delenv("LDR_TEST_MODE", raising=False)
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 100_000
|
|
|
|
def test_empty_ldr_test_mode_is_production(self, monkeypatch):
|
|
"""Empty string for LDR_TEST_MODE is falsy → production mode."""
|
|
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
|
|
monkeypatch.setenv("LDR_TEST_MODE", "")
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 100_000
|
|
|
|
@pytest.mark.parametrize(
|
|
"falsey", ["0", "false", "False", "no", "off", "banana"]
|
|
)
|
|
def test_falsey_ldr_test_mode_is_production(self, monkeypatch, falsey):
|
|
"""LDR_TEST_MODE is parsed as a boolean: explicit falsey values (and
|
|
unrecognised strings like 'banana') must NOT relax the floor. A bare
|
|
truthiness check would treat any non-empty string as enabled and
|
|
silently weaken encryption.
|
|
"""
|
|
# Load-bearing: _get_min_kdf_iterations() also relaxes the floor when
|
|
# PYTEST_CURRENT_TEST is present (which it always is under pytest), so
|
|
# we must clear it to isolate the LDR_TEST_MODE behaviour under test.
|
|
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
|
|
monkeypatch.setenv("LDR_TEST_MODE", falsey)
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 100_000
|
|
|
|
@pytest.mark.parametrize("truthy", ["true", "TRUE", "yes", "on", "enabled"])
|
|
def test_extended_truthy_ldr_test_mode_relaxes(self, monkeypatch, truthy):
|
|
"""LDR_TEST_MODE accepts the full boolean truthy set (to_bool), not
|
|
just '1'/'true' — locks that behavior so a narrower parser would be
|
|
caught.
|
|
"""
|
|
# Clear PYTEST_CURRENT_TEST so the relaxation we observe is attributable
|
|
# to LDR_TEST_MODE, not pytest's own presence (see falsey test above).
|
|
monkeypatch.delenv("PYTEST_CURRENT_TEST", raising=False)
|
|
monkeypatch.setenv("LDR_TEST_MODE", truthy)
|
|
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
_get_min_kdf_iterations,
|
|
)
|
|
|
|
assert _get_min_kdf_iterations() == 1
|
|
|
|
|
|
class TestKdfConstants:
|
|
"""Tests for KDF iteration constants."""
|
|
|
|
def test_production_constant_is_100k(self):
|
|
"""MIN_KDF_ITERATIONS_PRODUCTION should be 100_000."""
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
MIN_KDF_ITERATIONS_PRODUCTION,
|
|
)
|
|
|
|
assert MIN_KDF_ITERATIONS_PRODUCTION == 100_000
|
|
|
|
def test_testing_constant_is_1(self):
|
|
"""MIN_KDF_ITERATIONS_TESTING should be 1."""
|
|
from local_deep_research.database.sqlcipher_utils import (
|
|
MIN_KDF_ITERATIONS_TESTING,
|
|
)
|
|
|
|
assert MIN_KDF_ITERATIONS_TESTING == 1
|