mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
Added filesystem .. test
Supporting relative paths
This commit is contained in:
parent
6ad580a5de
commit
93577f3ab2
@ -505,12 +505,25 @@ Status resolveFilePattern(std::vector<std::string> components,
|
||||
|
||||
Status resolveFilePattern(const boost::filesystem::path& fs_path,
|
||||
std::vector<std::string>& results) {
|
||||
if (fs_path.string()[0] != '/') {
|
||||
return resolveFilePattern(split(boost::filesystem::current_path().string() +
|
||||
"/" + fs_path.string(),
|
||||
"/"),
|
||||
results);
|
||||
}
|
||||
return resolveFilePattern(split(fs_path.string(), "/"), results);
|
||||
}
|
||||
|
||||
Status resolveFilePattern(const boost::filesystem::path& fs_path,
|
||||
std::vector<std::string>& results,
|
||||
ReturnSetting setting) {
|
||||
if (fs_path.string()[0] != '/') {
|
||||
return resolveFilePattern(split(boost::filesystem::current_path().string() +
|
||||
"/" + fs_path.string(),
|
||||
"/"),
|
||||
results,
|
||||
setting);
|
||||
}
|
||||
return resolveFilePattern(split(fs_path.string(), "/"), results, setting);
|
||||
}
|
||||
|
||||
|
@ -204,6 +204,33 @@ TEST_F(FilesystemTests, test_letter_wild_opt) {
|
||||
EXPECT_NE(std::find(all.begin(), all.end(), kFakeDirectory + "/door.txt"),
|
||||
all.end());
|
||||
}
|
||||
|
||||
TEST_F(FilesystemTests, test_dotdot) {
|
||||
std::vector<std::string> all;
|
||||
auto status = resolveFilePattern(kFakeDirectory + "/deep11/deep2/../../%",
|
||||
all, REC_LIST_FILES);
|
||||
EXPECT_TRUE(status.ok());
|
||||
EXPECT_EQ(all.size(), 3);
|
||||
EXPECT_NE(std::find(all.begin(), all.end(),
|
||||
kFakeDirectory + "/deep11/deep2/../../door.txt"),
|
||||
all.end());
|
||||
}
|
||||
|
||||
TEST_F(FilesystemTests, test_dotdot_relative) {
|
||||
std::vector<std::string> all;
|
||||
auto status =
|
||||
resolveFilePattern("../../../../tools/tests/%", all, REC_LIST_ALL);
|
||||
EXPECT_TRUE(status.ok());
|
||||
|
||||
bool found = false;
|
||||
for (const auto& file : all) {
|
||||
if (file.find("test.config")) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(found);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user