mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
Merge pull request #661 from theopolis/hash_tests
Fix #646] Add unit testing to hashing
This commit is contained in:
commit
ac08ef441a
@ -21,6 +21,7 @@ ADD_OSQUERY_CORE_LIBRARY(osquery_core
|
||||
hash.cpp
|
||||
)
|
||||
|
||||
ADD_OSQUERY_TEST(hash_test hash_tests.cpp)
|
||||
ADD_OSQUERY_TEST(status_test status_tests.cpp)
|
||||
ADD_OSQUERY_TEST(sql_test sql_tests.cpp)
|
||||
ADD_OSQUERY_TEST(sqlite_util_tests sqlite_util_tests.cpp)
|
||||
|
55
osquery/core/hash_tests.cpp
Normal file
55
osquery/core/hash_tests.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <osquery/hash.h>
|
||||
|
||||
#include "osquery/core/test_util.h"
|
||||
|
||||
namespace osquery {
|
||||
|
||||
class HashTests : public testing::Test {};
|
||||
|
||||
TEST_F(HashTests, test_algorithms) {
|
||||
const unsigned char buffer[1] = {'0'};
|
||||
|
||||
auto digest = hashFromBuffer(HASH_TYPE_MD5, buffer, 1);
|
||||
EXPECT_EQ(digest, "cfcd208495d565ef66e7dff9f98764da");
|
||||
|
||||
digest = hashFromBuffer(HASH_TYPE_SHA1, buffer, 1);
|
||||
EXPECT_EQ(digest, "b6589fc6ab0dc82cf12099d1c2d40ab994e8410c");
|
||||
|
||||
digest = hashFromBuffer(HASH_TYPE_SHA256, buffer, 1);
|
||||
EXPECT_EQ(digest,
|
||||
"5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9");
|
||||
}
|
||||
|
||||
TEST_F(HashTests, test_update) {
|
||||
const unsigned char buffer[1] = {'0'};
|
||||
|
||||
Hash hash(HASH_TYPE_MD5);
|
||||
hash.update(buffer, 1);
|
||||
hash.update(buffer, 1);
|
||||
auto digest = hash.digest();
|
||||
EXPECT_EQ(digest, "b4b147bc522828731f1a016bfa72c073");
|
||||
}
|
||||
|
||||
TEST_F(HashTests, test_file_hashing) {
|
||||
auto digest = hashFromFile(HASH_TYPE_MD5, kTestDataPath + "test_hashing.bin");
|
||||
EXPECT_EQ(digest, "88ee11f2aa7903f34b8b8785d92208b1");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
osquery::initOsquery(argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
BIN
tools/tests/test_hashing.bin
Normal file
BIN
tools/tests/test_hashing.bin
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user