Fingerprint Console browser resources by content
This commit is contained in:
parent
cdba25924e
commit
a07871f4d7
|
|
@ -0,0 +1,6 @@
|
|||
# Console 3.1.33 — content-versioned browser resources
|
||||
|
||||
- The existing static file response owner fingerprints Console JS, translations and CSS in served HTML. Changing a file changes its URL even if the release label was reused.
|
||||
- Retain no-store headers and existing asset endpoints. No UI controls or installation logic are duplicated.
|
||||
- This hardens browser refresh after deployment; it does not prove the cause of the reported missing update button in an existing browser session.
|
||||
- Tests verify stable URLs for unchanged content and invalidation for a same-version JavaScript change.
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
"version": "1.0.1"
|
||||
},
|
||||
"stage_ui": {
|
||||
"version": "3.1.32"
|
||||
"version": "3.1.33"
|
||||
},
|
||||
"stage_avahi": {
|
||||
"version": "1.0.0"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
import glob
|
||||
import hashlib
|
||||
import base64
|
||||
import importlib.util
|
||||
import ipaddress
|
||||
|
|
@ -60,7 +61,7 @@ APP_DIR = "/opt/iomatex-console"
|
|||
PUBLIC_DIR = os.path.join(APP_DIR, "public")
|
||||
PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d")
|
||||
CONFIG_PATH = "/etc/iomatex/console.json"
|
||||
UI_VERSION = "V 3.1.32"
|
||||
UI_VERSION = "V 3.1.33"
|
||||
STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health"
|
||||
ZONEINFO_ROOT = "/usr/share/zoneinfo"
|
||||
|
||||
|
|
@ -2977,6 +2978,17 @@ def get_itscreen_binary_candidates():
|
|||
return [path for path in candidates if os.path.exists(path)]
|
||||
|
||||
|
||||
def fingerprint_console_assets(html, directory):
|
||||
"""Invalidate browser assets on content changes, including same-version deploys."""
|
||||
text = html.decode("utf-8")
|
||||
for name in ("console.js", "console.i18n.js", "console.css"):
|
||||
with open(os.path.join(directory, name), "rb") as stream:
|
||||
fingerprint = hashlib.sha256(stream.read()).hexdigest()[:16]
|
||||
pattern = r'(["\'])/' + re.escape(name) + r'(?:\?[^"\']*)?(["\'])'
|
||||
text = re.sub(pattern, lambda match: match[1] + "/" + name + "?sha=" + fingerprint + match[2], text)
|
||||
return text.encode("utf-8")
|
||||
|
||||
|
||||
def client_update_request(action=None):
|
||||
"""Console adapter only: the privileged updater owns feeds and installation."""
|
||||
if action not in (None, "check_only", "update"):
|
||||
|
|
@ -3474,6 +3486,8 @@ class Handler(BaseHTTPRequestHandler):
|
|||
except FileNotFoundError:
|
||||
self.send_error(404)
|
||||
return
|
||||
if os.path.basename(path) == "index.html":
|
||||
data = fingerprint_console_assets(data, os.path.dirname(path))
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", content_type)
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
import ast
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
source = Path(__file__).with_name('app.py').read_text()
|
||||
node = next(n for n in ast.parse(source).body if isinstance(n, ast.FunctionDef) and n.name == 'fingerprint_console_assets')
|
||||
namespace = dict(hashlib=hashlib, os=os, re=re)
|
||||
exec(compile(ast.Module(body=[node], type_ignores=[]), '<asset-owner>', 'exec'), namespace)
|
||||
|
||||
class AssetVersionTest(unittest.TestCase):
|
||||
def test_same_release_changed_content_gets_new_url(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
for name in ('console.js', 'console.i18n.js', 'console.css'):
|
||||
Path(directory, name).write_text('original')
|
||||
html = b'<script src="/console.js?v=3.1.32&rev=old"></script><link href="/console.css?v=3.1.32">'
|
||||
render = lambda: namespace['fingerprint_console_assets'](html, directory)
|
||||
first = render()
|
||||
self.assertIn(b'?sha=', first)
|
||||
self.assertNotIn(b'rev=old', first)
|
||||
self.assertEqual(first, render())
|
||||
Path(directory, 'console.js').write_text('new same-version bundle')
|
||||
self.assertNotEqual(first, render())
|
||||
self.assertEqual(first.split(b'<link')[1], render().split(b'<link')[1])
|
||||
|
||||
def test_html_response_uses_shared_asset_owner(self):
|
||||
handler = source.split(' def send_file(', 1)[1].split(' def send_sse_headers', 1)[0]
|
||||
self.assertIn('fingerprint_console_assets(data, os.path.dirname(path))', handler)
|
||||
self.assertLess(handler.index('fingerprint_console_assets'), handler.index('Content-Length'))
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
|
||||
{ mode: "custom", label: "Custom", host: "" }
|
||||
];
|
||||
const UI_VERSION = "V 3.1.32";
|
||||
const UI_VERSION = "V 3.1.33";
|
||||
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
||||
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
||||
const ITSCREEN_LOG_BATCH_MS = 250;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
} catch (error) {}
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="/console.css?v=3.1.32&rev=edge-runtime-profile-1">
|
||||
<link rel="stylesheet" href="/console.css?v=3.1.33&rev=edge-runtime-profile-1">
|
||||
</head>
|
||||
<body>
|
||||
<main class="shell">
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
</main>
|
||||
<div id="menuBackdrop" class="menuBackdrop" hidden></div>
|
||||
<div id="toastStack" class="toastStack" aria-live="polite" aria-atomic="true"></div>
|
||||
<script src="/console.i18n.js?v=3.1.32&rev=edge-runtime-profile-1"></script>
|
||||
<script src="/console.js?v=3.1.32&rev=edge-runtime-profile-1"></script>
|
||||
<script src="/console.i18n.js?v=3.1.33&rev=edge-runtime-profile-1"></script>
|
||||
<script src="/console.js?v=3.1.33&rev=edge-runtime-profile-1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"version": "3.1.32"
|
||||
"version": "3.1.33"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue