]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_encryption_test.cc
38eee56459e5000e015597b8e560f285e224bbce
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 #include "db/db_test_util.h"
7 #include "port/stack_trace.h"
8 #include "rocksdb/perf_context.h"
9 #if !defined(ROCKSDB_LITE)
10 #include "util/sync_point.h"
17 class DBEncryptionTest
: public DBTestBase
{
19 DBEncryptionTest() : DBTestBase("/db_encryption_test") {}
24 TEST_F(DBEncryptionTest
, CheckEncrypted
) {
25 ASSERT_OK(Put("foo567", "v1.fetdq"));
26 ASSERT_OK(Put("bar123", "v2.dfgkjdfghsd"));
29 // Open all files and look for the values we've put in there.
30 // They should not be found if encrypted, otherwise
31 // they should be found.
32 std::vector
<std::string
> fileNames
;
33 auto status
= env_
->GetChildren(dbname_
, &fileNames
);
36 auto defaultEnv
= Env::Default();
38 for (auto it
= fileNames
.begin() ; it
!= fileNames
.end(); ++it
) {
39 if ((*it
== "..") || (*it
== ".")) {
42 auto filePath
= dbname_
+ "/" + *it
;
43 unique_ptr
<SequentialFile
> seqFile
;
44 auto envOptions
= EnvOptions(CurrentOptions());
45 status
= defaultEnv
->NewSequentialFile(filePath
, &seqFile
, envOptions
);
49 status
= defaultEnv
->GetFileSize(filePath
, &fileSize
);
53 scratch
.reserve(fileSize
);
55 status
= seqFile
->Read(fileSize
, &data
, (char*)scratch
.data());
58 if (data
.ToString().find("foo567") != std::string::npos
) {
60 //std::cout << "Hit in " << filePath << "\n";
62 if (data
.ToString().find("v1.fetdq") != std::string::npos
) {
64 //std::cout << "Hit in " << filePath << "\n";
66 if (data
.ToString().find("bar123") != std::string::npos
) {
68 //std::cout << "Hit in " << filePath << "\n";
70 if (data
.ToString().find("v2.dfgkjdfghsd") != std::string::npos
) {
72 //std::cout << "Hit in " << filePath << "\n";
74 if (data
.ToString().find("dfgk") != std::string::npos
) {
76 //std::cout << "Hit in " << filePath << "\n";
86 #endif // ROCKSDB_LITE
88 } // namespace rocksdb
90 int main(int argc
, char** argv
) {
91 rocksdb::port::InstallStackTraceHandler();
92 ::testing::InitGoogleTest(&argc
, argv
);
93 return RUN_ALL_TESTS();