YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/tserver/header_manager_impl-test.cc
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include <string>
15
16
#include <glog/logging.h>
17
#include <gtest/gtest.h>
18
19
#include "yb/encryption/encryption_util.h"
20
#include "yb/encryption/header_manager_impl.h"
21
#include "yb/encryption/universe_key_manager.h"
22
23
#include "yb/gutil/endian.h"
24
25
#include "yb/tserver/universe_key_test_util.h"
26
27
#include "yb/util/status.h"
28
#include "yb/util/test_util.h"
29
30
using yb::tserver::GenerateTestUniverseKeyManager;
31
32
namespace yb {
33
34
namespace enterprise {
35
36
class TestHeaderManagerImpl : public YBTest {};
37
38
1
TEST_F(TestHeaderManagerImpl, FileOps) {
39
1
  auto universe_key_manger = GenerateTestUniverseKeyManager();
40
1
  auto header_manager =
41
1
      DefaultHeaderManager(universe_key_manger.get());
42
1
  auto params = encryption::EncryptionParams::NewEncryptionParams();
43
1
  string header = ASSERT_RESULT(header_manager->SerializeEncryptionParams(*params.get()));
44
1
  auto start_idx = header_manager->GetEncryptionMetadataStartIndex();
45
1
  auto status = ASSERT_RESULT(header_manager->GetFileEncryptionStatusFromPrefix(
46
1
      Slice(header.c_str(), start_idx)));
47
1
  ASSERT_TRUE(status.is_encrypted);
48
1
  Slice s = Slice(header.c_str() + start_idx, status.header_size);
49
1
  auto new_params = ASSERT_RESULT(header_manager->DecodeEncryptionParamsFromEncryptionMetadata(s));
50
1
  ASSERT_TRUE(params->Equals(*new_params.get()));
51
1
}
52
53
} // namespace enterprise
54
} // namespace yb