Skip to content

Commit

Permalink
Add testing for xattr
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Apr 10, 2024
1 parent 96f1d6d commit 3dcb743
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/test_common.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#include "test_common.h"
#include "crypto.h"
#include "fuse_high_level_ops_base.h"
#include "lite_format.h"
#include "lite_long_name_lookup_table.h"
#include "logger.h"
#include "myutils.h"

#include <cryptopp/osrng.h>

#include <cstddef>
#include <cstdlib>
#include <fuse/fuse.h>
#include <string>
#include <thread>
#include <vector>

std::mt19937& get_random_number_engine()
{
Expand Down Expand Up @@ -95,6 +100,29 @@ namespace
result.resize(strlen(result.c_str()));
return result;
}
std::vector<std::string> listxattr(FuseHighLevelOpsBase& ops, const char* path)
{
auto size = ops.vlistxattr(path, nullptr, 0, nullptr);
REQUIRE(size > 0);
std::vector<char> buffer(size);
REQUIRE(ops.vlistxattr(path, buffer.data(), buffer.size(), nullptr) > 0);
std::vector<std::string> result;
for (const char* ptr = buffer.data(); ptr < buffer.data() + buffer.size();
ptr += result.back().size() + 1)
{
result.emplace_back(ptr);
}
std::sort(result.begin(), result.end());
return result;
}
std::string getxattr(FuseHighLevelOpsBase& ops, const char* path, const char* name)
{
auto size = ops.vgetxattr(path, name, nullptr, 0, 0, nullptr);
REQUIRE(size > 0);
std::string result(size, '\0');
REQUIRE(ops.vgetxattr(path, name, result.data(), result.size(), 0, nullptr) > 0);
return result;
}
} // namespace
void test_fuse_ops(FuseHighLevelOpsBase& ops, OSService& repo_root, bool case_insensitive)
{
Expand Down Expand Up @@ -248,5 +276,16 @@ void test_fuse_ops(FuseHighLevelOpsBase& ops, OSService& repo_root, bool case_in
REQUIRE(ops.vgetattr("/check-mark", &st, &ctx) == 0);
CHECK(st.st_nlink == 1);
}
if (is_apple())
{
CHECK(listxattr(ops, "/cbd") == std::vector<std::string>{});
CHECK(ops.vsetxattr("/cbd", "com.apple.FinderInfo", "65535", 5, 0, 0, nullptr) >= 0);
CHECK(ops.vsetxattr("/cbd", "org.securefs.test", "blah", 4, 0, 0, nullptr) >= 0);
CHECK(listxattr(ops, "/cbd")
== std::vector<std::string>{"com.apple.FinderInfo", "org.securefs.test"});
CHECK(ops.vremovexattr("/cbd", "com.apple.FinderInfo", nullptr) > 0);
CHECK(listxattr(ops, "/cbd") == std::vector<std::string>{"org.securefs.test"});
CHECK(getxattr(ops, "/cbd", "org.securefs.test") == "blah");
}
}
} // namespace securefs::testing

0 comments on commit 3dcb743

Please sign in to comment.