Skip to content

Commit

Permalink
tests: Check setting the same xattr multiple times
Browse files Browse the repository at this point in the history
Came up in chat, the semantics defined today is last-one-wins.
Let's test that.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters authored and allisonkarlitskaya committed Dec 9, 2024
1 parent 4bab2fb commit ed3ee0d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test-lcfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "lcfs-writer.h"
#include "lcfs-mount.h"
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -119,4 +144,5 @@ int main(int argc, char **argv)
test_no_verity();
test_add_uninitialized_child();
test_xattr_addremove();
test_xattr_doubleadd();
}

0 comments on commit ed3ee0d

Please sign in to comment.