]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/parquet/encryption/key_metadata_test.cc
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / parquet / encryption / key_metadata_test.cc
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 #include <string>
19
20 #include <gtest/gtest.h>
21
22 #include "parquet/encryption/key_material.h"
23 #include "parquet/encryption/key_metadata.h"
24
25 namespace parquet {
26 namespace encryption {
27 namespace test {
28
29 TEST(KeyMetadataTest, InternalMaterialStorage) {
30 bool is_footer_key = true;
31 std::string kms_instance_id = "DEFAULT";
32 std::string kms_instance_url = "DEFAULT";
33 std::string master_key_id = "kf";
34 bool double_wrapped = true;
35 std::string kek_id = "FANqyCuxfU1c526Uzb+MTA==";
36 std::string encoded_wrapped_kek =
37 "{\"masterKeyVersion\":\"NO_VERSION\",\"encryptedKey\":\"LAAAAGaoSfMV1YH/"
38 "oxwG2ES8Phva8wimEZcT7zi5bpuK5Jdvw9/zJuqDeIPGGFXd\"}";
39 std::string encoded_wrapped_dek =
40 "LAAAAA3RcNYT1Rxb/gqhA1KvBgHcjvEppST9+cV3bU5nLmtaZHJhsZakR20qRErX";
41 bool internal_storage = true;
42 std::string json = KeyMaterial::SerializeToJson(
43 is_footer_key, kms_instance_id, kms_instance_url, master_key_id, double_wrapped,
44 kek_id, encoded_wrapped_kek, encoded_wrapped_dek, internal_storage);
45
46 KeyMetadata key_metadata = KeyMetadata::Parse(json);
47
48 ASSERT_EQ(key_metadata.key_material_stored_internally(), true);
49
50 const KeyMaterial& key_material = key_metadata.key_material();
51 ASSERT_EQ(key_material.is_footer_key(), is_footer_key);
52 ASSERT_EQ(key_material.kms_instance_id(), kms_instance_id);
53 ASSERT_EQ(key_material.kms_instance_url(), kms_instance_url);
54 ASSERT_EQ(key_material.master_key_id(), master_key_id);
55 ASSERT_EQ(key_material.is_double_wrapped(), double_wrapped);
56 ASSERT_EQ(key_material.kek_id(), kek_id);
57 ASSERT_EQ(key_material.wrapped_kek(), encoded_wrapped_kek);
58 ASSERT_EQ(key_material.wrapped_dek(), encoded_wrapped_dek);
59 }
60
61 TEST(KeyMetadataTest, ExternalMaterialStorage) {
62 const std::string key_reference = "X44KIHSxDSFAS5q2223";
63
64 // generate key_metadata string in parquet file
65 std::string key_metadata_str =
66 KeyMetadata::CreateSerializedForExternalMaterial(key_reference);
67
68 // parse key_metadata string back
69 KeyMetadata key_metadata = KeyMetadata::Parse(key_metadata_str);
70
71 ASSERT_EQ(key_metadata.key_material_stored_internally(), false);
72 ASSERT_EQ(key_metadata.key_reference(), key_reference);
73 }
74
75 } // namespace test
76 } // namespace encryption
77 } // namespace parquet