mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-12 04:53:52 -06:00
chore: one-liner cap 8 MiB, review at 3 MiB
The SHA-256 pin already refuses any changed byte: the cap in install.sh and install.ps1 only stops a sign-in portal's page before it is hashed, so it can be generous. The size test now fails once install.py passes 3 MiB, so its growth is looked at, and checks both bootstraps accept the same 8 MiB. The separate size test of the earlier commit is folded into the one test_install.py already had.
This commit is contained in:
1 parent
faa5ca89d0
commit
8518205be1
4 files changed
+22
-65
No files matched your search
+3
-1
@@ -17,7 +17,9 @@
|
||||
# the site's build rewrites this line there (scripts/sitebootstrap.py).
|
||||
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
$defaultInstallSha256 = "eb617bc1d0a220cc887e7763611a95cac9d3abd33acc1f115f7c048e51f218c7"
|
||||
$maximumInstallerBytes = 2MB
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
$maximumInstallerBytes = 8MB
|
||||
$installerExit = 0
|
||||
$installer = if ($PSScriptRoot) { Join-Path $PSScriptRoot "install.py" } else { $null }
|
||||
$temporary = $null
|
||||
|
||||
+3
-1
@@ -24,7 +24,9 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
|
||||
# build rewrites this line there (scripts/sitebootstrap.py).
|
||||
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
|
||||
DEFAULT_INSTALL_SHA256="eb617bc1d0a220cc887e7763611a95cac9d3abd33acc1f115f7c048e51f218c7"
|
||||
MAX_INSTALLER_BYTES=2097152
|
||||
# The pin above refuses any changed byte: this cap only stops a body that
|
||||
# cannot be the installer (a sign-in portal's page) before it is hashed.
|
||||
MAX_INSTALLER_BYTES=8388608
|
||||
|
||||
cleanup() {
|
||||
if [ -n "$TEMP_INSTALLER" ] && [ -f "$TEMP_INSTALLER" ]; then
|
||||
|
||||
+16
-10
@@ -4799,9 +4799,13 @@ class TheBoardSystemsAreNamedFromTheCode(unittest.TestCase):
|
||||
|
||||
|
||||
class TheInstallerFitsTheOneLiners(unittest.TestCase):
|
||||
"""install.sh and install.ps1 refuse an installer over 2 MiB, and
|
||||
install.py grew from 596 KB to 1.1 MB in twelve days with nothing
|
||||
holding it under that: past it, every one-line install would stop."""
|
||||
"""install.sh and install.ps1 refuse an installer over their cap, 8 MiB:
|
||||
the SHA-256 pin refuses any changed byte, and the cap only stops a page
|
||||
served in its place. install.py grew from 596 KB to 1.1 MB in twelve
|
||||
days: past REVIEW_BYTES its growth is looked at before it goes on."""
|
||||
|
||||
# The size past which install.py's growth is reviewed, well below the cap.
|
||||
REVIEW_BYTES = 3 * 1024 ** 2
|
||||
|
||||
def _caps(self) -> dict[str, int]:
|
||||
import re
|
||||
@@ -4813,14 +4817,16 @@ class TheInstallerFitsTheOneLiners(unittest.TestCase):
|
||||
return {"install.sh": int(re.search(r"^MAX_INSTALLER_BYTES=(\d+)$", shell, re.M)[1]),
|
||||
"install.ps1": int(number) * units[unit or ""]}
|
||||
|
||||
def test_a_quarter_of_each_cap_stays_free(self):
|
||||
def test_both_one_liners_accept_the_same_size(self):
|
||||
self.assertEqual(set(self._caps().values()), {8 * 1024 ** 2})
|
||||
|
||||
def test_install_py_stays_below_the_review_size(self):
|
||||
size = (REPO_ROOT / "install.py").stat().st_size
|
||||
for script, cap in self._caps().items():
|
||||
with self.subTest(script=script):
|
||||
self.assertLessEqual(
|
||||
size, cap * 3 // 4,
|
||||
f"install.py is {size} bytes, past three quarters of the {cap} {script} "
|
||||
"accepts: shrink it or raise the cap in both one-liners")
|
||||
self.assertLess(self.REVIEW_BYTES, min(self._caps().values()))
|
||||
self.assertLess(
|
||||
size, self.REVIEW_BYTES,
|
||||
f"install.py is {size} bytes, past the {self.REVIEW_BYTES} that call for a "
|
||||
"look at its growth: shrink it, or raise REVIEW_BYTES once reviewed")
|
||||
|
||||
def test_the_refusal_names_a_cause_and_a_way_out(self):
|
||||
for script in ("install.sh", "install.ps1"):
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
"""install.py stays under the size the one-liners accept.
|
||||
|
||||
install.sh refuses an installer above MAX_INSTALLER_BYTES and install.ps1
|
||||
above $maximumInstallerBytes: past them every curl | sh and irm | iex
|
||||
stops before the first file. This test fails while there is still room,
|
||||
so the cap is raised, or the installer made smaller, before a release.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests # noqa: F401 offline, scratch under tmp/, the suite's own cache
|
||||
|
||||
import re
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
# The share of the cap install.py may use: 1.9 MiB of 2 MiB. Raising the
|
||||
# cap in both bootstraps raises the alert with it.
|
||||
ALERT_SHARE = 0.95
|
||||
|
||||
_UNITS = {"": 1, "KB": 1024, "MB": 1024 ** 2, "GB": 1024 ** 3}
|
||||
|
||||
|
||||
def shell_cap() -> int:
|
||||
text = (REPO_ROOT / "install.sh").read_text(encoding="utf-8")
|
||||
return int(re.search(r"^MAX_INSTALLER_BYTES=(\d+)$", text, re.MULTILINE).group(1))
|
||||
|
||||
|
||||
def powershell_cap() -> int:
|
||||
text = (REPO_ROOT / "install.ps1").read_text(encoding="utf-8")
|
||||
found = re.search(r"\$maximumInstallerBytes\s*=\s*(\d+)\s*(KB|MB|GB)?\b", text)
|
||||
return int(found.group(1)) * _UNITS[found.group(2) or ""]
|
||||
|
||||
|
||||
class InstallerFitsTheOneLiners(unittest.TestCase):
|
||||
def test_both_bootstraps_accept_the_same_size(self):
|
||||
self.assertEqual(shell_cap(), powershell_cap())
|
||||
|
||||
def test_install_py_stays_below_the_alert(self):
|
||||
cap = shell_cap()
|
||||
size = (REPO_ROOT / "install.py").stat().st_size
|
||||
alert = int(cap * ALERT_SHARE)
|
||||
self.assertLess(
|
||||
size, alert,
|
||||
f"install.py is {size} bytes, past {alert} of the {cap} the one-liners "
|
||||
"accept: raise MAX_INSTALLER_BYTES in install.sh and $maximumInstallerBytes "
|
||||
"in install.ps1, or make the installer smaller")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user