diff --git a/server.py b/server.py index 91140fb..6496c14 100644 --- a/server.py +++ b/server.py @@ -30,7 +30,7 @@ STORAGE_DIR = Path(os.environ.get("APP_STORAGE_DIR", ROOT / "data" / "files")) SESSION_COOKIE = "cw_fusion_session" if portal_sso.enabled() else "cw_session" # Local plain-HTTP deployment: the cookie intentionally carries no Secure # flag (see docs/decisions/003-auth.md). -COOKIE_FLAGS = "HttpOnly; SameSite=Lax; Path=/" +COOKIE_FLAGS = "HttpOnly; SameSite=Lax; Path=/" + ("; Secure" if os.environ.get("PORTAL_COOKIE_SECURE") == "1" else "") class AppHandler(portal_sso.PortalMixin, SimpleHTTPRequestHandler): diff --git a/tests/ledger_helpers.py b/tests/ledger_helpers.py index 475f29f..6d72d0c 100644 --- a/tests/ledger_helpers.py +++ b/tests/ledger_helpers.py @@ -3,6 +3,7 @@ from __future__ import annotations from pathlib import Path +import hashlib import sqlite3 import tempfile import unittest @@ -13,6 +14,7 @@ from bank_importer.db import connect, migrate, utc_now class LedgerBase(unittest.TestCase): def setUp(self) -> None: + self._source_file_sequence = 0 self.temp_dir = tempfile.TemporaryDirectory() self.addCleanup(self.temp_dir.cleanup) root = Path(self.temp_dir.name) @@ -66,13 +68,15 @@ class LedgerBase(unittest.TestCase): summary: str | None = None, purpose: str | None = None, ) -> int: + self._source_file_sequence = getattr(self, "_source_file_sequence", 0) + 1 + fixture_hash = hashlib.sha256(f"ledger-fixture-{self._source_file_sequence}".encode()).hexdigest() with self.connection: cursor = self.connection.execute( """ INSERT INTO source_files (sha256, original_filename, size_bytes, storage_path, created_at) VALUES (?, '测试.xlsx', 1, 'data/files/测试.xlsx', ?) """, - (utc_now(), utc_now()), + (fixture_hash, utc_now()), ) source_file_id = int(cursor.lastrowid) cursor = self.connection.execute( diff --git a/tests/test_matching.py b/tests/test_matching.py index 964c9b5..6779155 100644 --- a/tests/test_matching.py +++ b/tests/test_matching.py @@ -5,6 +5,7 @@ idempotency, concurrency, Decimal precision and B-44 eligibility.""" from __future__ import annotations from decimal import Decimal +import hashlib from pathlib import Path import sqlite3 import tempfile @@ -17,6 +18,7 @@ from bank_importer.db import connect, migrate, utc_now class MatchingBase(unittest.TestCase): def setUp(self) -> None: + self._source_file_sequence = 0 self.temp_dir = tempfile.TemporaryDirectory() self.addCleanup(self.temp_dir.cleanup) root = Path(self.temp_dir.name) @@ -74,13 +76,15 @@ class MatchingBase(unittest.TestCase): summary: str | None = None, sheet: str = "流水", ) -> int: + self._source_file_sequence = getattr(self, "_source_file_sequence", 0) + 1 + fixture_hash = hashlib.sha256(f"matching-fixture-{self._source_file_sequence}".encode()).hexdigest() with self.connection: cursor = self.connection.execute( """ INSERT INTO source_files (sha256, original_filename, size_bytes, storage_path, created_at) VALUES (?, '测试.xlsx', 1, 'data/files/测试.xlsx', ?) """, - (utc_now(), utc_now()), + (fixture_hash, utc_now()), ) source_file_id = int(cursor.lastrowid) cursor = self.connection.execute( diff --git a/web/admin.html b/web/admin.html index 761cc80..b5350f4 100644 --- a/web/admin.html +++ b/web/admin.html @@ -205,8 +205,8 @@