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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
20 #include <gtest/gtest.h>
22 #include "parquet/encryption/key_material.h"
23 #include "parquet/encryption/key_metadata.h"
26 namespace encryption
{
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
);
46 KeyMetadata key_metadata
= KeyMetadata::Parse(json
);
48 ASSERT_EQ(key_metadata
.key_material_stored_internally(), true);
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
);
61 TEST(KeyMetadataTest
, ExternalMaterialStorage
) {
62 const std::string key_reference
= "X44KIHSxDSFAS5q2223";
64 // generate key_metadata string in parquet file
65 std::string key_metadata_str
=
66 KeyMetadata::CreateSerializedForExternalMaterial(key_reference
);
68 // parse key_metadata string back
69 KeyMetadata key_metadata
= KeyMetadata::Parse(key_metadata_str
);
71 ASSERT_EQ(key_metadata
.key_material_stored_internally(), false);
72 ASSERT_EQ(key_metadata
.key_reference(), key_reference
);
76 } // namespace encryption
77 } // namespace parquet