Skip to content

Commit

Permalink
fixed "password_confirmation" test
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 committed Sep 3, 2024
1 parent 2d49cea commit 76bbf1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/actual_tests/z_special_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/data/nc_pass_confirm_nc31.patch
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 76bbf1a

Please sign in to comment.