Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): add a test that has assertion statement values as objects #245

Merged
merged 11 commits into from
Jan 29, 2025
Binary file not shown.
3 changes: 3 additions & 0 deletions xtest/sdk/go/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ elif [ "$1" == "decrypt" ]; then
if [ -n "$8" ]; then
args+=(--with-assertion-verification-keys "$8")
fi
if [ "$VERIFY_ASSERTIONS" == 'false' ]; then
args+=(--no-verify-assertions)
fi
echo "${cmd[@]}" decrypt "${args[@]}" "$2"
"${cmd[@]}" decrypt "${args[@]}" "$2"
else
Expand Down
4 changes: 4 additions & 0 deletions xtest/sdk/java/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ if [ -n "$8" ]; then
args+=(--with-assertion-verification-keys "$8")
fi

if [ "$VERIFY_ASSERTIONS" == 'false' ]; then
args+=(--with-assertion-verification-disabled)
fi

echo java -jar "$SCRIPT_DIR"/cmdline.jar "${args[@]}" -f "$2" ">" "$3"
java -jar "$SCRIPT_DIR"/cmdline.jar "${args[@]}" -f "$2" >"$3"
3 changes: 3 additions & 0 deletions xtest/sdk/js/cli/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ if [ "$1" == "encrypt" ]; then

npx $CTL encrypt "$2" "${args[@]}"
elif [ "$1" == "decrypt" ]; then
if [ "$VERIFY_ASSERTIONS" == 'false' ]; then
args+=(--noVerifyAssertions)
fi
npx $CTL decrypt "$2" "${args[@]}"
else
echo "Incorrect argument provided"
Expand Down
6 changes: 5 additions & 1 deletion xtest/tdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def decrypt(
rt_file: str,
fmt: format_type = "nano",
assert_keys: str = "",
verify_assertions: bool = True,
):
c = [
sdk_paths[sdk],
Expand All @@ -265,8 +266,11 @@ def decrypt(
"",
assert_keys,
]
env = dict(os.environ)
if not verify_assertions:
env |= {"VERIFY_ASSERTIONS": "false"}
logger.info(f"dec [{' '.join(c)}]")
subprocess.check_output(c, stderr=subprocess.STDOUT)
subprocess.check_output(c, stderr=subprocess.STDOUT, env=env)


def supports(sdk: sdk_type, feature: feature_type) -> bool:
Expand Down
27 changes: 19 additions & 8 deletions xtest/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,42 @@ def test_decrypt_small(
assert b == expected_bytes


def test_decrypt_no_splitid(
def test_decrypt_big(
decrypt_sdk: tdfs.sdk_type,
tmp_dir,
):
ct_file = get_golden_file("no-splitids-java.tdf")
rt_file = os.path.join(tmp_dir, "no-splitids-java.untdf")
ct_file = get_golden_file("big-java-4.3.0-e0f8caf.tdf")
rt_file = os.path.join(tmp_dir, "big-java.untdf")
tdfs.decrypt(decrypt_sdk, ct_file, rt_file, fmt="ztdf")
file_stats = os.stat(rt_file)
assert file_stats.st_size == 5 * 2**10
assert file_stats.st_size == 10 * 2**20
expected_bytes = bytes([0] * 1024)
with open(rt_file, "rb") as f:
while b := f.read(1024):
assert b == expected_bytes


def test_decrypt_big(
def test_decrypt_no_splitid(
decrypt_sdk: tdfs.sdk_type,
tmp_dir,
):
ct_file = get_golden_file("big-java-4.3.0-e0f8caf.tdf")
rt_file = os.path.join(tmp_dir, "big-java.untdf")
ct_file = get_golden_file("no-splitids-java.tdf")
rt_file = os.path.join(tmp_dir, "no-splitids-java.untdf")
tdfs.decrypt(decrypt_sdk, ct_file, rt_file, fmt="ztdf")
file_stats = os.stat(rt_file)
assert file_stats.st_size == 10 * 2**20
assert file_stats.st_size == 5 * 2**10
expected_bytes = bytes([0] * 1024)
with open(rt_file, "rb") as f:
while b := f.read(1024):
assert b == expected_bytes


def test_decrypt_object_statement_value_json(
decrypt_sdk: tdfs.sdk_type,
tmp_dir,
):
ct_file = get_golden_file("with-json-object-assertions-java.tdf")
rt_file = os.path.join(tmp_dir, "with-json-object-assertions-java.untdf")
tdfs.decrypt(decrypt_sdk, ct_file, rt_file, fmt="ztdf", verify_assertions=False)
with open(rt_file, "rb") as f:
assert f.read().decode("utf-8") == "text"
Loading