Skip to content

Commit

Permalink
Add tests for --data-unit-size
Browse files Browse the repository at this point in the history
  • Loading branch information
ebiggers committed Nov 3, 2023
1 parent cc4d85b commit 3b21f5e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def directory():


def describe_policy(path=TEST_DIR, key=TEST_KEY, contents="AES-256-XTS",
filenames="AES-256-CTS", flags="PAD_32"):
filenames="AES-256-CTS", flags="PAD_32",
data_unit_size="default"):
"""Builds the expected output for a successful invocation of the get_policy
command. The arguments specify the settings used in the encryption policy
as well as the path to the file or directory that has the policy."""
Expand All @@ -150,7 +151,7 @@ def describe_policy(path=TEST_DIR, key=TEST_KEY, contents="AES-256-XTS",
out += "\tContents encryption mode: {}\n".format(contents)
out += "\tFilenames encryption mode: {}\n".format(filenames)
out += "\tFlags: {}\n".format(flags)
out += "\tData unit size: default"
out += "\tData unit size: {}".format(data_unit_size)
return out


Expand Down Expand Up @@ -307,6 +308,20 @@ def test_set_get_policy_alternate_padding(directory):
check_policy(directory, flags="PAD_{}".format(padding))


def test_set_get_policy_custom_data_unit_size(directory):
"""Tests getting and setting an encryption policy that uses a custom data
unit size."""

for size in [512, 1024, 2048, 4096, 8192, 16384]:
try:
prepare_encrypted_dir(directory, "--data-unit-size={}".format(size))
except SystemError as e:
assert "invalid encryption options provided" in str(e)
continue

check_policy(directory, data_unit_size=size)


def test_set_get_policy_aes_256_xts(directory):
"""Tests getting and setting an encryption policy that uses AES-256-XTS
contents encryption and AES-256-CTS filenames encryption. (Note that this
Expand Down Expand Up @@ -480,6 +495,14 @@ def test_set_policy_bad_mode(directory):
expected_error="error: invalid {} mode: foo".format(mode_type))


def test_set_policy_bad_data_unit_size(directory):
"""Tests that the set_policy command rejects non-power-of-2 data unit
sizes."""
for size in [0, 100, 1000, 10000, 10000000000000, 'not a number']:
prepare_encrypted_dir(directory, "--data-unit-size={}".format(size),
expected_error="error: invalid data unit size: {}".format(size))


def test_set_policy_bad_mode_combination(directory):
""" Tests setting and using an encryption policy with a combination of
encryption modes that isn't supported by the kernel."""
Expand Down

0 comments on commit 3b21f5e

Please sign in to comment.