-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
hash.cpp
79 lines (62 loc) · 2.1 KB
/
hash.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed in accordance with the terms specified in
* the LICENSE file found in the root directory of this source tree.
*/
// Sanity check integration test for hash
// Spec file: specs/hash.table
#include <osquery/filesystem/filesystem.h>
#include <osquery/tests/integration/tables/helper.h>
#include <osquery/utils/info/platform_type.h>
namespace osquery {
namespace table_tests {
namespace fs = boost::filesystem;
class Hash : public testing::Test {
public:
void SetUp() override {
setUpEnvironment();
path = fs::temp_directory_path() /
fs::unique_path("osquery.tests.file.hashes.%%%%.%%%%.%%%%.%%%%");
EXPECT_TRUE(
writeTextFile(
path, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.ok());
}
void TearDown() override {
fs::remove(path.native());
}
fs::path path;
};
TEST_F(Hash, test_sanity) {
const std::string query =
"select * from hash where path = '" + path.string() + "'";
QueryData data = execute_query(query);
ASSERT_EQ(data.size(), 1ul);
ValidationMap row_map = {
{"path", NonEmptyString},
{"directory", NonEmptyString},
{"md5", NonEmptyString},
{"sha1", NonEmptyString},
{"sha256", NonEmptyString},
};
if (isPlatform(PlatformType::TYPE_POSIX)) {
row_map.emplace("ssdeep", NonEmptyString);
}
ASSERT_EQ(data[0]["path"], path.string());
ASSERT_EQ(data[0]["directory"], path.parent_path().string());
ASSERT_EQ(data[0]["md5"], "35899082e51edf667f14477ac000cbba");
ASSERT_EQ(data[0]["sha1"], "e7505beb754bed863e3885f73e3bb6866bdd7f8c");
ASSERT_EQ(data[0]["sha256"],
"a58dd8680234c1f8cc2ef2b325a43733605a7f16f288e072de8eae81fd8d6433");
if (isPlatform(PlatformType::TYPE_POSIX)) {
ASSERT_EQ(data[0]["ssdeep"], "3:f4oo8MRwRJFGW1gC64:f4kPvtHF");
}
validate_rows(data, row_map);
if (isPlatform(PlatformType::TYPE_LINUX)) {
validate_container_rows("hash", row_map, "path = '" + path.string() + "'");
}
}
} // namespace table_tests
} // namespace osquery