diff --git a/tests/actual_tests/z_special_test.py b/tests/actual_tests/z_special_test.py index 14802399..075e3314 100644 --- a/tests/actual_tests/z_special_test.py +++ b/tests/actual_tests/z_special_test.py @@ -13,7 +13,7 @@ @pytest.mark.skipif("NC_AUTH_USER" not in environ or "NC_AUTH_PASS" not in environ, reason="Needs login & paasword.") @pytest.mark.skipif(environ.get("CI", None) is None, reason="run only on GitHub") def test_password_confirmation(nc_client): - patch_path, cwd_path = _test_password_confirmation() + patch_path, cwd_path = _test_password_confirmation(nc_client.srv_version["major"]) nc_client.update_server_info() old_adapter = nc_client._session.adapter with contextlib.suppress(NextcloudException): @@ -27,7 +27,7 @@ def test_password_confirmation(nc_client): @pytest.mark.skipif("NC_AUTH_USER" not in environ or "NC_AUTH_PASS" not in environ, reason="Needs login & paasword.") @pytest.mark.skipif(environ.get("CI", None) is None, reason="run only on GitHub") async def test_password_confirmation_async(anc_client): - patch_path, cwd_path = _test_password_confirmation() + patch_path, cwd_path = _test_password_confirmation((await anc_client.srv_version)["major"]) await anc_client.update_server_info() old_adapter = anc_client._session.adapter with contextlib.suppress(NextcloudException): @@ -37,9 +37,12 @@ async def test_password_confirmation_async(anc_client): run(["git", "apply", "-R", patch_path], cwd=cwd_path, check=True) -def _test_password_confirmation() -> tuple[str, str]: +def _test_password_confirmation(nc_version) -> tuple[str, str]: # patch "PasswordConfirmationMiddleware.php" decreasing asking before Password Confirmation from 30 min to 5 secs - patch_path = path.join(path.dirname(path.dirname(path.abspath(__file__))), "data/nc_pass_confirm.patch") + if nc_version <= 30: + patch_path = path.join(path.dirname(path.dirname(path.abspath(__file__))), "data/nc_pass_confirm.patch") + else: + patch_path = path.join(path.dirname(path.dirname(path.abspath(__file__))), "data/nc_pass_confirm_nc31.patch") cwd_path = path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__))))) run(["patch", "-p", "1", "-i", patch_path], cwd=cwd_path, check=True) sleep(6) diff --git a/tests/data/nc_pass_confirm_nc31.patch b/tests/data/nc_pass_confirm_nc31.patch new file mode 100644 index 00000000..722c03ef --- /dev/null +++ b/tests/data/nc_pass_confirm_nc31.patch @@ -0,0 +1,13 @@ +diff --git a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php +index 5ff9d7386da..04edf4e9991 100644 +--- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php ++++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php +@@ -93,7 +93,7 @@ class PasswordConfirmationMiddleware extends Middleware { + + $lastConfirm = (int)$this->session->get('last-password-confirm'); + // TODO: confirm excludedUserBackEnds can go away and remove it +- if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay ++ if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - 5)) { // allow 5 seconds delay + throw new NotConfirmedException(); + } + }