added escape route to allow ios webapp homepage creation

This commit is contained in:
2026-10-15 21:46:19 +02:00
parent 95da8038f0
commit 7633767afd
4 changed files with 70 additions and 1 deletions
+44
View File
@@ -1,4 +1,6 @@
import unittest
from datetime import datetime
from unittest.mock import patch
from urllib.parse import quote
from flask import Blueprint, Flask
@@ -10,6 +12,10 @@ from models import User, db
class PasswordHashLoginTest(unittest.TestCase):
def setUp(self):
clock = patch("auth.datetime")
self.clock = clock.start()
self.addCleanup(clock.stop)
self.clock.now.return_value = datetime(2026, 10, 15, 12)
self.app = Flask(__name__)
self.app.config.update(
TESTING=True, SECRET_KEY="test-only",
@@ -57,6 +63,44 @@ class PasswordHashLoginTest(unittest.TestCase):
def test_unknown_hash(self):
self.assert_rejected(self.login("unknown"))
def test_blank_displays_thank_you_without_login(self):
self.app.config["blank"] = True
for suffix in (self.user.password_hash.split(":", 3)[3], "unknown"):
with self.subTest(suffix=suffix):
response = self.login(suffix)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get_data(as_text=True), "thank you")
self.assertEqual(response.mimetype, "text/plain")
self.assertNotIn("Location", response.headers)
with self.client.session_transaction() as session:
self.assertNotIn("_user_id", session)
def test_blank_false_preserves_login(self):
self.app.config["blank"] = False
self.test_valid_hash_logs_in_and_redirects()
def test_daily_blank_window(self):
self.app.config["blank"] = False
for hour, minute, second, expected_status in (
(21, 59, 59, 302),
(22, 0, 0, 200),
(22, 5, 0, 200),
(22, 9, 59, 200),
(22, 10, 0, 302),
):
with self.subTest(time=(hour, minute, second)):
self.client = self.app.test_client()
self.clock.now.return_value = datetime(
2026, 10, 15, hour, minute, second
)
response = self.login()
self.assertEqual(response.status_code, expected_status)
if expected_status == 200:
self.assertEqual(response.get_data(as_text=True), "thank you")
self.assertNotIn("Location", response.headers)
with self.client.session_transaction() as session:
self.assertNotIn("_user_id", session)
def test_full_hash_is_rejected(self):
self.assert_rejected(self.login(self.user.password_hash))