From 9b06aee162b916608ce82d915920d23d28652e26 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Sat, 26 Aug 2023 11:53:12 -0400 Subject: [PATCH] Improve gefsetting validator tests --- tests/config/__init__.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/config/__init__.py b/tests/config/__init__.py index e4d7a805f..1d35df3ec 100644 --- a/tests/config/__init__.py +++ b/tests/config/__init__.py @@ -20,12 +20,32 @@ def test_config_show_opcodes_size(self): # example: 0x5555555546b2 897dec mov DWORD PTR [rbp-0x14], edi self.assertRegex(res, r"(0x([0-9a-f]{2})+)\s+(([0-9a-f]{2})+)\s+<[^>]+>\s+(.*)") - def test_config_validator(self): + def test_config_hook_validator(self): """Check that a GefSetting hook can prevent setting a config.""" res = gdb_run_cmd("gef config gef.tempdir '/tmp/path with space'") # Validators just use `err` to print an error self.assertNoException(res) - self.assertRegex(res, r".+Cannot set.+setting cannot contain spaces") + self.assertRegex(res, r"[!].+Cannot set.+setting cannot contain spaces") res = gdb_run_cmd("gef config gef.tempdir '/tmp/valid-path'") self.assertNoException(res) + self.assertNotIn("[!]", res) + + def test_config_type_validator(self): + """Check that a GefSetting type can prevent setting a config.""" + res = gdb_run_cmd("gef config gef.debug invalid") + self.assertNoException(res) + self.assertRegex(res, r"[!].+expects type 'bool'") + + res = gdb_run_cmd("gef config gef.debug true") + self.assertNoException(res) + self.assertNotIn("[!]", res) + res = gdb_run_cmd("gef config gef.debug 1") + self.assertNoException(res) + self.assertNotIn("[!]", res) + res = gdb_run_cmd("gef config gef.debug F") + self.assertNoException(res) + self.assertNotIn("[!]", res) + res = gdb_run_cmd("gef config gef.debug 0") + self.assertNoException(res) + self.assertNotIn("[!]", res)