-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- convert inline JSON to dicts - use pytest temporary files instead of tempfile - create a seccompiler fixture to make running it easy Signed-off-by: Pablo Barbáchano <[email protected]>
- Loading branch information
Showing
3 changed files
with
136 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Fixtures for security tests""" | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from host_tools.cargo_build import run_seccompiler_bin | ||
|
||
|
||
@pytest.fixture() | ||
def seccompiler(tmp_path): | ||
"A seccompiler helper fixture" | ||
|
||
class Seccompiler: | ||
"A seccompiler helper class" | ||
|
||
def compile(self, data: dict, basic=False) -> Path: | ||
"Use seccompiler-bin to compile a filter from a dict" | ||
inp = tmp_path / "input.json" | ||
inp.write_text(json.dumps(data)) | ||
bpf = tmp_path / "output.bpfmap" | ||
run_seccompiler_bin(bpf_path=bpf, json_path=inp, basic=basic) | ||
return bpf | ||
|
||
return Seccompiler() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.