From ed3ee0d4530e624df2dbf78977651ce84abb14a2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 2 Dec 2024 21:46:02 +0000 Subject: [PATCH] tests: Check setting the same xattr multiple times Came up in chat, the semantics defined today is last-one-wins. Let's test that. Signed-off-by: Colin Walters --- tests/test-lcfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test-lcfs.c b/tests/test-lcfs.c index 6d34abe..fc53655 100644 --- a/tests/test-lcfs.c +++ b/tests/test-lcfs.c @@ -3,6 +3,7 @@ #include "lcfs-writer.h" #include "lcfs-mount.h" +#include #include #include #include @@ -77,6 +78,30 @@ static void test_xattr_addremove(void) child = NULL; } +// Test that calling lcfs_node_set_xattr multiple times +// with the same key has last-one-wins semantics. +static void test_xattr_doubleadd(void) +{ + cleanup_node struct lcfs_node_s *node = lcfs_node_new(); + lcfs_node_set_mode(node, S_IFDIR | 0755); + cleanup_node struct lcfs_node_s *child = lcfs_node_new(); + lcfs_node_set_mode(child, S_IFDIR | 0700); + int r = lcfs_node_set_xattr(child, "user.foo", "bar", 3); + assert(r == 0); + // Should successfully silently overwrite. + r = lcfs_node_set_xattr(child, "user.foo", "baz", 3); + assert(r == 0); + + size_t found_len; + const char *found_value = lcfs_node_get_xattr(child, "user.foo", &found_len); + assert(found_value); + assert(found_len == 3); + assert(memcmp(found_value, "baz", found_len) == 0); + r = lcfs_node_add_child(node, child, "somechild"); + assert(r == 0); + child = NULL; +} + static void test_add_uninitialized_child(void) { cleanup_node struct lcfs_node_s *node = lcfs_node_new(); @@ -119,4 +144,5 @@ int main(int argc, char **argv) test_no_verity(); test_add_uninitialized_child(); test_xattr_addremove(); + test_xattr_doubleadd(); }