summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-26 21:45:35 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-04-27 01:35:06 +0100
commit637d57ddfd2e908f9508ac9a822d09063f0c146e (patch)
tree44d13ba671cf3199658e92e0b46401191f1b5643 /src/test
parent048bcb9d1f813df344a4aaed31c5687856ecf6e5 (diff)
downloadsystemd-637d57ddfd2e908f9508ac9a822d09063f0c146e.tar.gz
image-policy: split out code that "extends" underspecified partition policy flags
When encoding partition policy flags we allow parts of the flags to be "unspecified" (i.e. entirely zeros), which when actually checking the policy we'll automatically consider equivalent to "any" (i.e. entirely ones). This "extension" of the flags was so far done as part of partition_policy_normalized_flags(). Let's split this logic out into a new function partition_policy_flags_extend() that simply sets all bits in a specific part of the flags field if they were entirely zeroes so far. When comparing policy objects for equivalence we so far used partition_policy_normalized_flags() to compare the per-designator flags, which thus meant that "underspecified" flags, and fully specified ones that are set to "any" were considered equivalent. Which is great. However, we forgot to do that for the fallback policy flags, the flags that apply to all partitions for which no explicit policy flags are specified. Let's use the new partition_policy_flags_extend() call to compare them in extended form, so that there two we can hide the difference between "underspecified" and "any" flags.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-image-policy.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/test/test-image-policy.c b/src/test/test-image-policy.c
index 41941704d4..f2eba94961 100644
--- a/src/test/test-image-policy.c
+++ b/src/test/test-image-policy.c
@@ -119,4 +119,13 @@ TEST_RET(test_image_policy_to_string) {
return 0;
}
+TEST(extend) {
+ assert_se(partition_policy_flags_extend(0) == _PARTITION_POLICY_MASK);
+ assert_se(partition_policy_flags_extend(_PARTITION_POLICY_MASK) == _PARTITION_POLICY_MASK);
+ assert_se(partition_policy_flags_extend(PARTITION_POLICY_UNPROTECTED) == (PARTITION_POLICY_UNPROTECTED|_PARTITION_POLICY_PFLAGS_MASK));
+ assert_se(partition_policy_flags_extend(PARTITION_POLICY_UNPROTECTED|PARTITION_POLICY_READ_ONLY_ON) == (PARTITION_POLICY_UNPROTECTED|PARTITION_POLICY_READ_ONLY_ON|_PARTITION_POLICY_GROWFS_MASK));
+ assert_se(partition_policy_flags_extend(PARTITION_POLICY_UNPROTECTED|PARTITION_POLICY_READ_ONLY_ON|PARTITION_POLICY_GROWFS_OFF) == (PARTITION_POLICY_UNPROTECTED|PARTITION_POLICY_READ_ONLY_ON|PARTITION_POLICY_GROWFS_OFF));
+ assert_se(partition_policy_flags_extend(PARTITION_POLICY_GROWFS_ON) == (PARTITION_POLICY_GROWFS_ON|_PARTITION_POLICY_USE_MASK|_PARTITION_POLICY_READ_ONLY_MASK));
+}
+
DEFINE_TEST_MAIN(LOG_INFO);