diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ef20ac0f..c6f89e6d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,6 +77,7 @@ jobs: - name: ๐ Run helpers.js test suite run: | node-qunit-puppeteer tests/static/js/test-helpers.html + node-qunit-puppeteer tests/static/js/test-client-base.html test-install: name: ๐งช Installation tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c26984a43..889a84977 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,6 +54,7 @@ repos: - id: flake8 additional_dependencies: - flake8-bugbear==22.3.20 + - importlib-metadata<5.0 exclude: ^(docs/) - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.5.1 diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index 19e1e69b3..643f9aa11 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -390,9 +390,7 @@ class BackupPlugin( "as_attachment": True, "path_validation": path_validation_factory( lambda path: not is_hidden_path(path) - and self._match_backup_filename( - os.path.basename(path), self._settings - ), + and self._valid_backup(path), status_code=404, ), "access_validation": access_validation_factory( @@ -739,9 +737,7 @@ class BackupPlugin( for entry in os.scandir(self.get_plugin_data_folder()): if is_hidden_path(entry.path): continue - if not entry.is_file(): - continue - if not entry.name.endswith(".zip"): + if not self._valid_backup(entry.path): continue backups.append( @@ -1373,13 +1369,6 @@ class BackupPlugin( backup_prefix, time.strftime(BACKUP_DATE_TIME_FMT) ) - @classmethod - def _match_backup_filename(cls, path, settings): - import re - - backup_prefix = cls._get_backup_prefix(settings) - return re.match(re.escape(backup_prefix) + r"-backup-\d{8}-\d{6}.zip", path) - @classmethod def _get_backup_prefix(cls, settings): if settings.global_get(["appearance", "name"]) == "": @@ -1397,6 +1386,17 @@ class BackupPlugin( not in valid_boolean_trues ) + @classmethod + def _valid_backup(cls, path): + if not path.endswith(".zip") or not zipfile.is_zipfile(path): + return False + + try: + with zipfile.ZipFile(path) as z: + return "metadata.json" in z.namelist() + except Exception: + return False + def _send_client_message(self, message, payload=None): if payload is None: payload = {} diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 0617b9209..533c1ddbc 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -1472,6 +1472,7 @@ class Server: app, key_func=get_remote_address, enabled=s.getBoolean(["devel", "enableRateLimiter"]), + storage_uri="memory://", ) def _setup_i18n(self, app): diff --git a/src/octoprint/static/js/app/client/base.js b/src/octoprint/static/js/app/client/base.js index 79870fd86..9bc72ce2f 100644 --- a/src/octoprint/static/js/app/client/base.js +++ b/src/octoprint/static/js/app/client/base.js @@ -107,13 +107,14 @@ return url; }; - OctoPrintClient.prototype.getParsedBaseUrl = function () { + OctoPrintClient.prototype.getParsedBaseUrl = function (location) { if (!this.options.baseurl) return ""; try { var url = new URL(this.options.baseurl); } catch (e) { - var parsed = new URL(window.location); + location = location || window.location; + var parsed = new URL(location); var path = this.options.baseurl; if (!path || path[0] !== "/") { path = "/" + (path ? path : ""); @@ -135,7 +136,7 @@ if (path.endsWith("/")) { path = path.substring(0, path.length - 1); } - return "_P" + port + "_R" + path.replace(/\//, "|"); + return "_P" + port + "_R" + path.replace(/\//g, "|"); } else { return "_P" + port; } diff --git a/tests/static/js/test-client-base.html b/tests/static/js/test-client-base.html new file mode 100644 index 000000000..fa69c3fea --- /dev/null +++ b/tests/static/js/test-client-base.html @@ -0,0 +1,18 @@ + + +
+ +