Merge branch 'maintenance' into devel

This commit is contained in:
GitHub Nightly Merge Action committed 2022-08-12 00:12:29 +00:00
commit 8bf68fae87
5 files changed
+100 -10

No files matched your search

@@ -861,13 +861,13 @@ $(function () {
var icon = $("i.fa-trash-alt", element);
if (icon.length) {
activateSpinner = function () {
icon.removeClass("fa-trash-alt").addClass(
"fa-spinner fa-spin"
icon.removeClass("far fa-trash-alt").addClass(
"fas fa-spinner fa-spin"
);
};
finishSpinner = function () {
icon.removeClass("fa-spinner fa-spin").addClass(
"fa-trash-alt"
icon.removeClass("fas fa-spinner fa-spin").addClass(
"far fa-trash-alt"
);
};
}
+45
View File
@@ -2,6 +2,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp
__copyright__ = "Copyright (C) 2021 The OctoPrint Project - Released under terms of the AGPLv3 License"
import itertools
import logging
import os.path
import re
@@ -270,3 +271,47 @@ def silent_remove(file):
os.remove(file)
except OSError:
pass
def search_through_file(path, term, regex=False):
if regex:
pattern = term
else:
pattern = re.escape(term)
compiled = re.compile(pattern)
logger = logging.getLogger(__name__)
try:
try:
# try native grep
import sarge
result = sarge.capture_stderr(["grep", "-q", "-E", pattern, path])
if result.stderr.text:
logger.warning(
"Error raised by native grep, falling back to python "
"implementation: {}".format(result.stderr.text.strip())
)
return search_through_file_python(path, term, compiled)
return result.returncode == 0
except ValueError as exc:
if "Command not found" in str(exc):
return search_through_file_python(path, term, compiled)
else:
raise
except Exception:
logger.exception(
"Something unexpectedly went wrong while trying to "
"search for {} in {} via grep".format(term, path)
)
return False
def search_through_file_python(path, term, compiled):
with open(path, encoding="utf8", errors="replace") as f:
for line in f:
if term in line or compiled.match(term):
return True
return False
+11 -5
View File
@@ -1,4 +1,10 @@
import {prepare_server, await_coreui, await_loginui, login} from "../util/util";
import {
prepare_server,
await_coreui,
await_loginui,
login,
get_cookie_name
} from "../util/util";
context("Login tests", () => {
const username = "admin";
@@ -27,8 +33,8 @@ context("Login tests", () => {
await_coreui();
cy.get("[data-test-id=login-menu-title]").should("contain", username);
cy.getCookie("session_P5000").should("exist");
cy.getCookie("remember_token_P5000").should("not.exist");
cy.getCookie(get_cookie_name("session")).should("exist");
cy.getCookie(get_cookie_name("remember_token")).should("not.exist");
cy.location().should((loc) => {
expect(loc.hash).to.eq("#temp");
});
@@ -45,8 +51,8 @@ context("Login tests", () => {
await_coreui();
cy.get("[data-test-id=login-menu-title]").should("contain", username);
cy.getCookie("session_P5000").should("exist");
cy.getCookie("remember_token_P5000").should(($cookie) => {
cy.getCookie(get_cookie_name("session")).should("exist");
cy.getCookie(get_cookie_name("remember_token")).should(($cookie) => {
expect($cookie).to.have.property("value");
expect($cookie.value).to.match(new RegExp("^" + username + "|"));
});
+6
View File
@@ -70,3 +70,9 @@ export const ensure_file_unknown = (location, name) => {
failOnStatusCode: false
});
};
export const get_cookie_name = (cookie) => {
const url = new URL(Cypress.config("baseUrl"));
const port = url.port || (url.protocol === "https:" ? 443 : 80);
return `${cookie}_P${port}`;
};
+34 -1
View File
@@ -1,11 +1,17 @@
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
__copyright__ = "Copyright (C) 2021 The OctoPrint Project - Released under terms of the AGPLv3 License"
import os
import re
import unittest
from ddt import data, ddt, unpack
from octoprint.util.files import sanitize_filename
from octoprint.util.files import (
sanitize_filename,
search_through_file,
search_through_file_python,
)
@ddt
@@ -33,3 +39,30 @@ class FilesUtilTest(unittest.TestCase):
self.fail("expected ValueError")
except ValueError as ex:
self.assertEqual(str(ex), "name must not contain / or \\")
@data(
("umlaut", False, True),
("BOM", False, True),
(r"^[^#]*BOM", True, False),
)
@unpack
def test_search_through_file(self, term, regex, expected):
path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "_files", "utf8_without_bom.txt"
)
actual = search_through_file(path, term, regex=regex)
self.assertEqual(actual, expected)
@data(
("umlaut", True),
("BOM", True),
(r"^[^#]*BOM", False),
)
@unpack
def test_search_through_file_python(self, term, expected):
compiled = re.compile(term)
path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "_files", "utf8_without_bom.txt"
)
actual = search_through_file_python(path, term, compiled)
self.assertEqual(actual, expected)