From f58ed9a2705a54235821347becc50a77acafbb5c Mon Sep 17 00:00:00 2001 From: Grazfather Date: Fri, 25 Aug 2023 21:48:44 -0400 Subject: [PATCH] Add test --- tests/config/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/config/__init__.py b/tests/config/__init__.py index 891742c96..615d3a5ed 100644 --- a/tests/config/__init__.py +++ b/tests/config/__init__.py @@ -2,17 +2,16 @@ Test GEF configuration parameters. """ - from tests.utils import gdb_run_cmd from tests.utils import GefUnitTestGeneric class TestGefConfigUnit(GefUnitTestGeneric): - """Test GEF configuration paramaters.""" + """Test GEF configuration parameters.""" def test_config_show_opcodes_size(self): - """Check opcodes are correctly shown""" + """Check opcodes are correctly shown.""" res = gdb_run_cmd("entry-break", before=["gef config context.show_opcodes_size 4"]) self.assertNoException(res) self.assertGreater(len(res.splitlines()), 1) @@ -20,3 +19,12 @@ def test_config_show_opcodes_size(self): # output format: 0xaddress opcode mnemo [operands, ...] # 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): + """Check that a GefSetting hook can prevent setting a config.""" + res = gdb_run_cmd("gef config gef.tempdir '/tmp/path with space'") + self.assertException(res) + self.assertRegex(res, r".+Cannot set.+setting cannot contain spaces") + + res = gdb_run_cmd("gef config gef.tempdir '/tmp/valid-path'") + self.assertNoException(res)