Skip to content

Commit

Permalink
add option to skip non standard flags
Browse files Browse the repository at this point in the history
  • Loading branch information
RTUnreal committed Jun 25, 2024
1 parent 503d6eb commit e78c6f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions enochecker_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ def pytest_addoption(parser):
parser.addoption("--checker-address", action="store", type=str)
parser.addoption("--checker-port", action="store", type=int)
parser.addoption("--service-address", action="store", type=str)
parser.addoption("--skip-non-eno-flags", action="store_true")
parser.addoption("--flag-variants", action="store", type=int)
parser.addoption("--noise-variants", action="store", type=int)
parser.addoption("--havoc-variants", action="store", type=int)
Expand Down
15 changes: 12 additions & 3 deletions enochecker_test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from urllib3.util.retry import Retry


def run_tests(host, port, service_address, test_expr):
def run_tests(host, port, service_address, test_expr, skip_non_eno_flags: bool):
s = requests.Session()
retry_strategy = Retry(
total=5,
Expand Down Expand Up @@ -44,7 +44,7 @@ def run_tests(host, port, service_address, test_expr):
f"--exploit-variants={info.exploit_variants}",
"--durations=0",
"-v",
]
] + (["--skip-non-eno-flags"] if skip_non_eno_flags else [])

if test_expr:
test_args.append("-k")
Expand Down Expand Up @@ -91,6 +91,11 @@ def main():
help="The address on which the checker can reach the service (defaults to ENOCHECKER_TEST_SERVICE_ADDRESS environment variable)",
default=os.environ.get("ENOCHECKER_TEST_SERVICE_ADDRESS"),
)
parser.add_argument(
"--skip-non-eno-flags",
action="store_true",
help="Skips all test that do not use a ENO[A-Za-z0-9+\/=]{48} flag. SHOULD ONLY BE USED AS AN EXCEPTION!!",
)
parser.add_argument(
"testexpr",
help="Specify the tests that should be run in the syntax expected by pytests -k flag, e.g. 'test_getflag' or 'not exploit'. If no expr is specified, all tests will be run.",
Expand All @@ -117,5 +122,9 @@ def main():

logging.basicConfig(level=logging.INFO)
run_tests(
args.checker_address, args.checker_port, args.service_address, args.testexpr
args.checker_address,
args.checker_port,
args.service_address,
args.testexpr,
args.skip_non_eno_flags,
)
13 changes: 10 additions & 3 deletions enochecker_test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def checker_url(checker_address, checker_port):
return f"http://{checker_address}:{checker_port}"


posible_encodings = ["ascii", "utf8"]


@pytest.fixture(params=posible_encodings)
def encoding(request):
if request.config.getoption("--skip-non-eno-flags") and request.param != "ascii":
pytest.skip("skipped by --skip-non-eno-flags")
return request.param


def pytest_generate_tests(metafunc):
flag_variants: int = metafunc.config.getoption("--flag-variants")
noise_variants: int = metafunc.config.getoption("--noise-variants")
Expand Down Expand Up @@ -80,9 +90,6 @@ def pytest_generate_tests(metafunc):
if "exploit_variants" in metafunc.fixturenames:
metafunc.parametrize("exploit_variants", [exploit_variants])

if "encoding" in metafunc.fixturenames:
metafunc.parametrize("encoding", ["ascii", "utf8"])


def generate_dummyflag(encoding: str) -> str:
if encoding == "utf8":
Expand Down

0 comments on commit e78c6f3

Please sign in to comment.