From 6dbc44800291a8a8aadd9036ff7a8697e595682f Mon Sep 17 00:00:00 2001
From: kmochocki <kmochocki@syncad.com>
Date: Fri, 14 Feb 2025 09:17:55 +0000
Subject: [PATCH] Fix regex for wallet path detection

---
 helpy/helpy/_communication/rules.py                  | 12 +++++++-----
 .../handle/api_tests/test_api_unlock.py              |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/helpy/helpy/_communication/rules.py b/helpy/helpy/_communication/rules.py
index 531b42ed..5af17469 100644
--- a/helpy/helpy/_communication/rules.py
+++ b/helpy/helpy/_communication/rules.py
@@ -27,6 +27,9 @@ if TYPE_CHECKING:
     from helpy.exceptions import OverseerError
 
 
+REGEX_FOR_PATH_WITH_CAPTURE_GROUP_ON_WALLET_NAME: Final[str] = r"\/(?:(?:[^\/]+\/)+)([^\/]+)\.wallet"
+
+
 class UnableToAcquireDatabaseLock(OverseerRule):
     LOOKUP_MESSAGE: ClassVar[str] = "Unable to acquire database lock"
 
@@ -236,7 +239,7 @@ class WalletIsAlreadyUnlocked(OverseerRule):
 class UnableToOpenWallet(OverseerRule):
     _UNABLE_TO_OPEN_WALLET_REGEX: ClassVar[re.Pattern[str]] = re.compile(
         r"Assert Exception:_new_item->load_wallet_file\(\): "
-        r"Unable to open file: (?:\/[\w-]+)+\/([\w-]+\.wallet)(?:rethrow)?"
+        r"Unable to open file: " + REGEX_FOR_PATH_WITH_CAPTURE_GROUP_ON_WALLET_NAME + r"(?:rethrow)?"
     )
 
     def _check_single(self, parsed_response: Json, whole_response: Json | list[Json]) -> list[OverseerError]:
@@ -253,12 +256,11 @@ class UnableToOpenWallet(OverseerRule):
         return []
 
 
-#
-
-
 class InvalidPassword(OverseerRule):
     _INVALID_PASSWORD_REGEX: ClassVar[re.Pattern[str]] = re.compile(
-        r"Assert Exception:false: Invalid password for wallet: (?:\/[\w-]+)+\/([\w-]+\.wallet)(?:rethrow)?"
+        r"Assert Exception:false: Invalid password for wallet: "
+        + REGEX_FOR_PATH_WITH_CAPTURE_GROUP_ON_WALLET_NAME
+        + r"(?:rethrow)?"
     )
 
     def _check_single(self, parsed_response: Json, whole_response: Json | list[Json]) -> list[OverseerError]:
diff --git a/tests/beekeepy_test/handle/api_tests/test_api_unlock.py b/tests/beekeepy_test/handle/api_tests/test_api_unlock.py
index 918ba1d9..2794ff92 100644
--- a/tests/beekeepy_test/handle/api_tests/test_api_unlock.py
+++ b/tests/beekeepy_test/handle/api_tests/test_api_unlock.py
@@ -86,5 +86,5 @@ def test_api_unlock_with_invalid_password(beekeeper: Beekeeper, setup_wallets: W
     wallet = setup_wallets(1, keys_per_wallet=0)[0]
 
     # ASSERT
-    with pytest.raises(InvalidPasswordError, match="Invalid password for wallet: wallet-0.wallet"):
+    with pytest.raises(InvalidPasswordError, match="Invalid password for wallet: wallet-0"):
         beekeeper.api.unlock(wallet_name=wallet.name, password="invalid password")  # noqa: S106
-- 
GitLab