From 2f62feaaeca2ebabda7b9ba55f7f399b63d36924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 27 Sep 2022 17:47:38 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=96=20staging/bugfix=20is=20now=20?= =?UTF-8?q?1.8.5.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index fd66b44e7..e67009478 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,10 +24,10 @@ maintenance 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev fix/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev improve/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev -# staging/bugfix is the branch for preparation of the 1.8.4 bugfix release +# staging/bugfix is the branch for preparation of the 1.8.5 bugfix release # so are any bug/... branches -staging/bugfix 1.8.4 d0d226f3e0ad0a6436e4f32519bf38a82aa576ca pep440-dev -bug/.* 1.8.4 d0d226f3e0ad0a6436e4f32519bf38a82aa576ca pep440-dev +staging/bugfix 1.8.5 27a576e352a9b3d9abee89ab92cd02012c0e39dd pep440-dev +bug/.* 1.8.5 27a576e352a9b3d9abee89ab92cd02012c0e39dd pep440-dev # staging/maintenance is currently the branch for preparation of 1.8.0rc6 # so is regressionfix/... From 5091487719268f4d2ffabe2d10515a12218134aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 5 Oct 2022 13:21:07 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=90=9B=20Fix=20js=20getCookieSuffix?= =?UTF-8?q?=20for=20multi=20level=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add Unit test coverage for getCookieSuffix and getParsedBaseUrl. Closes #4656 --- .github/workflows/build.yml | 15 +++ src/octoprint/static/js/app/client/base.js | 7 +- tests/static/js/test-client-base.html | 18 ++++ tests/static/js/test-client-base.js | 110 +++++++++++++++++++++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 tests/static/js/test-client-base.html create mode 100644 tests/static/js/test-client-base.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44d27367b..2837192b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,6 +65,20 @@ jobs: run: | pytest + test-js-unit: + name: 🧪 JavaScript unit tests + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: 🏗 Set up test dependencies + run: | + npm -g install node-qunit-puppeteer@2.1.0 + - 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 needs: build @@ -146,6 +160,7 @@ jobs: needs: - pre-commit - test-unit + - test-js-unit - test-install - test-e2e runs-on: ubuntu-latest 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 @@ + + + + + src/octoprint/static/js/app/client/base.js Tests + + + +
+
+ + + + + + + + diff --git a/tests/static/js/test-client-base.js b/tests/static/js/test-client-base.js new file mode 100644 index 000000000..6d39fa39f --- /dev/null +++ b/tests/static/js/test-client-base.js @@ -0,0 +1,110 @@ +_.mixin({sprintf: sprintf, vsprintf: vsprintf}); + +QUnit.module("getParsedBaseUrl"); +QUnit.cases( + (function () { + return [ + { + title: "fully qualified baseurl", + baseurl: "https://example.com", + location: undefined, + expected: "https://example.com/" + }, + { + title: "fully qualified baseurl with http", + baseurl: "http://example.com", + location: undefined, + expected: "http://example.com/" + }, + { + title: "fully qualified baseurl with custom port", + baseurl: "https://example.com:5000", + location: undefined, + expected: "https://example.com:5000/" + }, + { + title: "website root", + baseurl: "/", + location: "https://example.com", + expected: "https://example.com/" + }, + { + title: "website root with custom port", + baseurl: "/", + location: "https://example.com:5000", + expected: "https://example.com:5000/" + }, + { + title: "single level prefix", + baseurl: "/octoprint/", + location: "https://example.com", + expected: "https://example.com/octoprint/" + }, + { + title: "multi level prefix", + baseurl: "/path/to/octoprint/", + location: "https://example.com", + expected: "https://example.com/path/to/octoprint/" + }, + { + title: "multi level prefix with http and custom port", + baseurl: "/path/to/octoprint/", + location: "http://example.com:5000", + expected: "http://example.com:5000/path/to/octoprint/" + }, + { + title: "multi level prefix with https, custom port, no trailing slash", + baseurl: "/path/to/octoprint", + location: "https://example.com:5001", + expected: "https://example.com:5001/path/to/octoprint" + } + ]; + })() +).test("getParsedBaseUrl", function (params, assert) { + OctoPrint.options.baseurl = params.baseurl; + assert.equal( + OctoPrint.getParsedBaseUrl(params.location).toString(), + params.expected, + "Expected: " + String(params.expected) + ); +}); + +QUnit.module("getCookieSuffix"); +QUnit.cases( + (function () { + return [ + { + title: "http with default port", + baseurl: "http://example.com", + expected: "_P80" + }, + { + title: "https with default port", + baseurl: "https://example.com", + expected: "_P443" + }, + { + title: "custom port", + baseurl: "http://example.com:5000", + expected: "_P5000" + }, + { + title: "single level prefix", + baseurl: "https://example.com/octoprint/", + expected: "_P443_R|octoprint" + }, + { + title: "multi level prefix", + baseurl: "https://example.com/path/to/octoprint", + expected: "_P443_R|path|to|octoprint" + } + ]; + })() +).test("getCookieSuffix", function (params, assert) { + OctoPrint.options.baseurl = params.baseurl; + assert.equal( + OctoPrint.getCookieSuffix(), + params.expected, + "Expected: " + String(params.expected) + ); +}); From 8e9c09a81893e4658d0776fa2fe60333bc84b50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 5 Oct 2022 15:10:59 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=92=9A=20Downgrade=20importlib-metada?= =?UTF-8?q?ta=20in=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://stackoverflow.com/a/73932581 --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bbf5c3e8a..73b286f05 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,6 +55,7 @@ repos: - id: flake8 additional_dependencies: - flake8-bugbear==22.1.11 + - importlib-metadata<5.0 - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.5.1 hooks: From b4d0ed30ab66878412066e21ef1f0c23fcecf5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 5 Oct 2022 17:03:14 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=90=9B=20backup:=20fix=20file=20valid?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just going by name breaks backups with arbitrary file names created from CLI or the helper. Instead of matching on the name, we now check whether it's a zip and contains a metadata.json. Closes #4659 --- src/octoprint/plugins/backup/__init__.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) 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 = {} From eb9e144746aa0d0a5e71ae77bb7a60f6f7dd50c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 5 Oct 2022 17:37:54 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=90=9B=20Explicitly=20declare=20stora?= =?UTF-8?q?ge=20for=20flask-limiter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents warnings in latest versions. --- src/octoprint/server/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index fd2ed32ac..659d83bd0 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): From 395354212c2bb65b37b303de171418f6475ca346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 17 Oct 2022 15:49:29 +0200 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=94=96=20Preparing=20release=20of=201?= =?UTF-8?q?.8.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SUPPORTERS.md | 4 ++-- src/octoprint/plugins/errortracking/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SUPPORTERS.md b/SUPPORTERS.md index c54300973..4edb73897 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -19,6 +19,7 @@ thanks to everyone who contributed! * Christian Wolf * Christian Würthner * Christoph Sigrist + * Codense Consulting Oy * Creality3D * DeltaMaker 3D Printers * Dennis Breining @@ -43,7 +44,6 @@ thanks to everyone who contributed! * Makespace Madrid * Mark Greenwald * Mark Walker - * Matt Van Itallie * Michael Aumock * Mike Kershaw * Mosaic Manufacturing @@ -68,4 +68,4 @@ thanks to everyone who contributed! * TJ Horner * Ulrich Kempken -and 2188 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)! +and 2145 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel) or via [GitHub Sponsors](https://github.com/users/foosel/sponsorship)! diff --git a/src/octoprint/plugins/errortracking/__init__.py b/src/octoprint/plugins/errortracking/__init__.py index a9c4295b7..7e0fc5647 100644 --- a/src/octoprint/plugins/errortracking/__init__.py +++ b/src/octoprint/plugins/errortracking/__init__.py @@ -18,10 +18,10 @@ from octoprint.util.version import ( ) SENTRY_URL_SERVER = ( - "https://289cde39ce7d410f82280cb5b0bb62e8@o118517.ingest.sentry.io/1373987" + "https://ed6946a2c4f344738768ac7f34ce27df@o118517.ingest.sentry.io/1373987" ) SENTRY_URL_COREUI = ( - "https://af2c0c034c9044889b8cf06163ea00fc@o118517.ingest.sentry.io/1374096" + "https://1b37bf389cbc4150890838f99c42adab@o118517.ingest.sentry.io/1374096" ) SETTINGS_DEFAULTS = {