Skip to content

Commit

Permalink
password confirmation test (#53)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 authored Jul 29, 2023
1 parent fa764a7 commit 3c397f0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/data/nc_pass_confirm.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 a72a7a40016..c6738de65df 100644
--- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php
@@ -88,7 +88,7 @@ class PasswordConfirmationMiddleware extends Middleware {

$lastConfirm = (int) $this->session->get('last-password-confirm');
// we can't check the password against a SAML backend, so skip password confirmation in this case
- 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();
}
}
8 changes: 8 additions & 0 deletions tests/misc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from gfixture import NC_APP

from nc_py_api import NextcloudException, check_error, misc
from nc_py_api._session import BasicConfig # noqa


@pytest.mark.parametrize("code", (995, 996, 997, 998, 999, 1000))
Expand Down Expand Up @@ -34,3 +35,10 @@ def test_require_capabilities():
misc.require_capabilities(
["non_exist_capability", "non_exist_capability2", "app_ecosystem_v2"], NC_APP.capabilities
)


def test_config_get_value():
BasicConfig()._get_value("non_exist_value", raise_not_found=False)
with pytest.raises(ValueError):
BasicConfig()._get_value("non_exist_value")
assert BasicConfig()._get_value("non_exist_value", non_exist_value=123) == 123
30 changes: 30 additions & 0 deletions tests/z_special_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from os import environ, path
from subprocess import run
from time import sleep

import pytest
from gfixture import NC

from nc_py_api import NextcloudException

# These tests should be run only on GitHub and only in special environment.


@pytest.mark.skipif("NC_AUTH_USER" not in environ or "NC_AUTH_PASS" not in environ, reason="Needs login & paasword.")
@pytest.mark.skipif(NC is None, reason="Not available for NextcloudApp.")
@pytest.mark.skipif(environ.get("CI", None) is None, reason="run only on GitHub")
def test_password_confirmation():
# patch "PasswordConfirmationMiddleware.php" decreasing asking before Password Confirmation from 30 min to 15 secs
patch_path = path.join(path.dirname(path.abspath(__file__)), "data/nc_pass_confirm.patch")
cwd_path = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
run(["patch", "-p", "1", "-i", patch_path], cwd=cwd_path, check=True)
sleep(6)
NC.update_server_info()
old_adapter = NC._session.adapter
try:
NC.users.create("test_cover_user_spec", password="ThisIsA54StrongPassword013")
except NextcloudException:
pass
NC.users.delete("test_cover_user_spec")
assert old_adapter != NC._session.adapter
run(["git", "apply", "-R", patch_path], cwd=cwd_path, check=True)

0 comments on commit 3c397f0

Please sign in to comment.