]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_encryption_test.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / db / db_encryption_test.cc
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).
5 //
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"
11 #endif
12 #include <iostream>
13 #include <string>
14
15 namespace rocksdb {
16
17 class DBEncryptionTest : public DBTestBase {
18 public:
19 DBEncryptionTest() : DBTestBase("/db_encryption_test") {}
20 };
21
22 #ifndef ROCKSDB_LITE
23
24 TEST_F(DBEncryptionTest, CheckEncrypted) {
25 ASSERT_OK(Put("foo567", "v1.fetdq"));
26 ASSERT_OK(Put("bar123", "v2.dfgkjdfghsd"));
27 Close();
28
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);
34 ASSERT_OK(status);
35
36 auto defaultEnv = Env::Default();
37 int hits = 0;
38 for (auto it = fileNames.begin() ; it != fileNames.end(); ++it) {
39 if ((*it == "..") || (*it == ".")) {
40 continue;
41 }
42 auto filePath = dbname_ + "/" + *it;
43 unique_ptr<SequentialFile> seqFile;
44 auto envOptions = EnvOptions(CurrentOptions());
45 status = defaultEnv->NewSequentialFile(filePath, &seqFile, envOptions);
46 ASSERT_OK(status);
47
48 uint64_t fileSize;
49 status = defaultEnv->GetFileSize(filePath, &fileSize);
50 ASSERT_OK(status);
51
52 std::string scratch;
53 scratch.reserve(fileSize);
54 Slice data;
55 status = seqFile->Read(fileSize, &data, (char*)scratch.data());
56 ASSERT_OK(status);
57
58 if (data.ToString().find("foo567") != std::string::npos) {
59 hits++;
60 //std::cout << "Hit in " << filePath << "\n";
61 }
62 if (data.ToString().find("v1.fetdq") != std::string::npos) {
63 hits++;
64 //std::cout << "Hit in " << filePath << "\n";
65 }
66 if (data.ToString().find("bar123") != std::string::npos) {
67 hits++;
68 //std::cout << "Hit in " << filePath << "\n";
69 }
70 if (data.ToString().find("v2.dfgkjdfghsd") != std::string::npos) {
71 hits++;
72 //std::cout << "Hit in " << filePath << "\n";
73 }
74 if (data.ToString().find("dfgk") != std::string::npos) {
75 hits++;
76 //std::cout << "Hit in " << filePath << "\n";
77 }
78 }
79 if (encrypted_env_) {
80 ASSERT_EQ(hits, 0);
81 } else {
82 ASSERT_GE(hits, 4);
83 }
84 }
85
86 #endif // ROCKSDB_LITE
87
88 } // namespace rocksdb
89
90 int main(int argc, char** argv) {
91 rocksdb::port::InstallStackTraceHandler();
92 ::testing::InitGoogleTest(&argc, argv);
93 return RUN_ALL_TESTS();
94 }