Add VK callback auth support and admin demotion
This commit is contained in:
@@ -31,6 +31,15 @@ class AutoUpdateServiceTests(unittest.TestCase):
|
||||
expected = hashlib.sha256(payload).hexdigest()
|
||||
self.assertEqual(AutoUpdateService.sha256_file(str(path)), expected)
|
||||
|
||||
def test_extract_sha256_from_build_sidecar_format(self):
|
||||
digest = "b" * 64
|
||||
text = f"{digest} AnabasisManager-2.2.5.zip\n"
|
||||
extracted = AutoUpdateService.extract_sha256_from_text(
|
||||
text,
|
||||
"AnabasisManager-2.2.5.zip",
|
||||
)
|
||||
self.assertEqual(extracted, digest)
|
||||
|
||||
def test_build_update_script_contains_core_vars(self):
|
||||
script = AutoUpdateService.build_update_script(
|
||||
app_dir=r"C:\Apps\AnabasisManager",
|
||||
|
||||
@@ -27,7 +27,7 @@ class MainContractsTests(unittest.TestCase):
|
||||
return ast.walk(node)
|
||||
|
||||
def test_auth_error_contexts_contains_only_supported_contexts(self):
|
||||
expected_contexts = {"load_chats", "execute_user_action", "set_user_admin"}
|
||||
expected_contexts = {"load_chats", "execute_user_action", "set_user_admin", "unset_user_admin"}
|
||||
for node in self.module.body:
|
||||
if isinstance(node, ast.Assign):
|
||||
for target in node.targets:
|
||||
@@ -37,6 +37,52 @@ class MainContractsTests(unittest.TestCase):
|
||||
return
|
||||
self.fail("AUTH_ERROR_CONTEXTS assignment not found")
|
||||
|
||||
def test_unset_user_admin_method_exists(self):
|
||||
self._find_method("unset_user_admin")
|
||||
|
||||
def test_uses_custom_standalone_vk_app(self):
|
||||
constants = {}
|
||||
for node in self.module.body:
|
||||
if not isinstance(node, ast.Assign) or len(node.targets) != 1:
|
||||
continue
|
||||
target = node.targets[0]
|
||||
if isinstance(target, ast.Name):
|
||||
try:
|
||||
constants[target.id] = ast.literal_eval(node.value)
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
self.assertEqual(constants.get("VK_APP_ID"), "54454043")
|
||||
self.assertIn("ANABASIS_VK_REDIRECT_URI", self.main_source)
|
||||
self.assertIn("https://vk.daemonlord.ru/vk/callback", self.main_source)
|
||||
|
||||
def test_remove_action_demotes_member_before_removing(self):
|
||||
bulk_worker = None
|
||||
for node in self.module.body:
|
||||
if isinstance(node, ast.ClassDef) and node.name == "BulkActionWorker":
|
||||
bulk_worker = node
|
||||
break
|
||||
self.assertIsNotNone(bulk_worker, "BulkActionWorker class not found")
|
||||
|
||||
run_method = None
|
||||
for node in bulk_worker.body:
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "run":
|
||||
run_method = node
|
||||
break
|
||||
self.assertIsNotNone(run_method, "BulkActionWorker.run method not found")
|
||||
|
||||
has_member_role = False
|
||||
has_remove_call = False
|
||||
for node in ast.walk(run_method):
|
||||
if isinstance(node, ast.keyword) and node.arg == "role":
|
||||
if isinstance(node.value, ast.Constant) and node.value.value == "member":
|
||||
has_member_role = True
|
||||
if isinstance(node, ast.Attribute) and node.attr == "removeChatUser":
|
||||
has_remove_call = True
|
||||
|
||||
self.assertTrue(has_member_role, "remove action must demote admins with role='member'")
|
||||
self.assertTrue(has_remove_call, "remove action must still call removeChatUser")
|
||||
|
||||
def test_check_for_updates_has_reentry_guard(self):
|
||||
method = self._find_method("check_for_updates")
|
||||
has_guard = False
|
||||
|
||||
Reference in New Issue
Block a user