Skip to content

Commit

Permalink
Improve gefsetting validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Aug 26, 2023
1 parent e7a4b1f commit 9b06aee
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tests/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,32 @@ def test_config_show_opcodes_size(self):
# example: 0x5555555546b2 897dec <main+8> 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)

0 comments on commit 9b06aee

Please sign in to comment.