Exemplo n.º 1
0
 def check(self):
     tap.plan(len(self.rules))
     for i in self.rules:
         success = i.check(self)
         if success == 1:
             self.result["success"] += 1
         else:
             self.result["fail"] += 1
         tap.ok(success, i)
Exemplo n.º 2
0
 def check(self):
     tap.plan(len(self.rules))
     for i in self.rules:
         success = i.check(self)
         if success == 1:
             self.result["success"] += 1
         else:
             self.result["fail"] += 1
         tap.ok(success, i)
Exemplo n.º 3
0
def run_test(test: Callable[[TestEnv], None]) -> None:
    with tempfile.TemporaryDirectory() as upper_dir:
        env = os.environ.copy()
        lower_dir = f"{SCRIPT_DIR}/lower"
        env["LIBOVERLAY_LOWER_DIR"] = lower_dir
        env["LIBOVERLAY_UPPER_DIR"] = upper_dir
        env["LD_PRELOAD"] = os.path.realpath(
            f"{SCRIPT_DIR}/../target/debug/liboverlay.so")

        try:
            test(TestEnv(upper=Path(upper_dir), lower=Path(lower_dir),
                         env=env))
        except:
            tap.not_ok(f"{test.__name__}")
            for line in traceback.format_exc().splitlines():
                tap.diagnostic(line)
        else:
            tap.ok(f"{test.__name__}")
Exemplo n.º 4
0
def check_vaultenv_result(
    process_handle: subprocess.Popen, secrets_version: int, api_version: int
) -> None:
    """
    Check the return code and output of the Vaultenv process under the given
    process_handle.

    Emit an appropriate TAP message for the result of the test.
    """

    description = f"v{secrets_version} secrets/v{api_version} API"

    return_code = process_handle.wait()
    if return_code != 0:
        tap.not_ok(f"{description} returned with code {return_code}")
        return

    expected_env: Set[str]
    if secrets_version == 1:
        expected_env = {
            "TESTING_KEY=testing42",
            "TESTING_OTHERKEY=testing8",
            "TESTING2_FOO=val1",
            "TESTING2_BAR=val2",
            "TEST_TEST=testing42",
            "TEST__TEST=testing42",
            "_TEST__TEST=testing42",
        }
    elif secrets_version == 2:
        expected_env = {
            "SECRET_TESTING_KEY=testing42",
            "SECRET_TESTING_OTHERKEY=testing8",
            "SECRET_TESTING2_FOO=val1",
            "SECRET_TESTING2_BAR=val2",
        }

    actual_env = set(line.strip() for line in process_handle.stdout.readlines())

    if not expected_env <= actual_env:
        missing = ", ".join(expected_env - actual_env)
        tap.not_ok(f"{description} missing vars {missing}")
        return

    tap.ok(description)