mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-03 13:35:37 +00:00
Fix: Various small bugs found during typing updates (#14593)
* Fix: match Apple Mail tag colors case-insensitively * Fix: reject OAuth callbacks with an unrecognized scope * Fix: refuse to refresh OAuth tokens for non-OAuth accounts or missing refresh tokens * Fix: parse datetime strings in the format_datetime filter and reject invalid ones * Fix: reject a PAPERLESS_URL without a hostname * Fix: report a database error in the system status instead of failing with a 500 * Fix: surface the database error when refreshing a document before moving its files * Fix: report no unapplied migrations when the applied migrations cannot be read * Fix: return the parsed value directly in format_datetime for typing * Chore: annotate the paperless_dirs fixture in the refresh failure test * Allow null for the latest_migration system status type --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
1 parent
d98918dd97
commit
3289be7383
14 files changed
+241
-14
No files matched your search
@@ -461,9 +461,14 @@ def _parse_paperless_url():
|
||||
global CSRF_TRUSTED_ORIGINS, CORS_ALLOWED_ORIGINS, ALLOWED_HOSTS
|
||||
url = os.getenv("PAPERLESS_URL")
|
||||
if url:
|
||||
hostname = urlparse(url).hostname
|
||||
if not hostname:
|
||||
raise ImproperlyConfigured(
|
||||
f"PAPERLESS_URL {url!r} has no hostname, expected a URL like https://example.com",
|
||||
)
|
||||
CSRF_TRUSTED_ORIGINS.append(url)
|
||||
CORS_ALLOWED_ORIGINS.append(url)
|
||||
ALLOWED_HOSTS.append(urlparse(url).hostname)
|
||||
ALLOWED_HOSTS.append(hostname)
|
||||
|
||||
return url
|
||||
|
||||
|
||||
@@ -166,3 +166,22 @@ class TestPaperlessURLSettings(TestCase):
|
||||
|
||||
self.assertIn(url, settings.CSRF_TRUSTED_ORIGINS)
|
||||
self.assertIn(url, settings.CORS_ALLOWED_ORIGINS)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("url", ["example.com", "https://", "/just/a/path"])
|
||||
def test_paperless_url_without_hostname_is_rejected(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
url: str,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- PAPERLESS_URL is set to a value with no hostname
|
||||
WHEN:
|
||||
- The URL is parsed
|
||||
THEN:
|
||||
- A configuration error is raised instead of adding None to ALLOWED_HOSTS
|
||||
"""
|
||||
monkeypatch.setenv("PAPERLESS_URL", url)
|
||||
|
||||
with pytest.raises(ImproperlyConfigured, match="no hostname"):
|
||||
_parse_paperless_url()
|
||||
Reference in new issue
Block a user