tolleybot commented on code in PR #34616: URL: https://github.com/apache/arrow/pull/34616#discussion_r1163122221
########## cpp/src/arrow/dataset/dataset_encryption_test.cc: ########## @@ -0,0 +1,247 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <arrow/api.h> +#include <arrow/dataset/api.h> +#include <string_view> +#include "arrow/array/builder_primitive.h" +#include "arrow/builder.h" +#include "arrow/dataset/partition.h" +#include "arrow/filesystem/mockfs.h" +#include "arrow/status.h" +#include "arrow/table.h" +#include "arrow/testing/gtest_util.h" +#include "gtest/gtest.h" +#include "parquet/encryption/dataset_encryption_config.h" +#include "parquet/encryption/test_in_memory_kms.h" + +constexpr std::string_view dsFooterMasterKey = "0123456789012345"; +constexpr std::string_view dsFooterMasterKeyId = "footer_key"; +constexpr std::string_view dsColumnMasterKeys[] = {"1234567890123450"}; +constexpr std::string_view dsColumnMasterKeyIds[] = {"col_key"}; +const int dsNumColumns = 1; +namespace arrow { +namespace dataset { + +class DatasetEncryptionTest : public ::testing::Test { + protected: + std::unique_ptr<arrow::internal::TemporaryDir> temp_dir_; + std::shared_ptr<::arrow::dataset::InMemoryDataset> dataset_; + std::string footer_key_name_ = "footer_key"; + + ::parquet::encryption::DatasetEncryptionConfiguration dataset_encryption_config_; + ::parquet::encryption::DatasetDecryptionConfiguration dataset_decryption_config_; + std::string column_key_mapping_; + ::parquet::encryption::KmsConnectionConfig kms_connection_config_; + std::shared_ptr<::parquet::encryption::CryptoFactory> crypto_factory_; + std::shared_ptr<ParquetFileFormat> file_format_; + std::shared_ptr<::arrow::fs::FileSystem> file_system_; + + /** setup the test + * + */ + void SetUp() { + // create our mock file system + ::arrow::fs::TimePoint mock_now = std::chrono::system_clock::now(); + ASSERT_OK_AND_ASSIGN(file_system_, + ::arrow::fs::internal::MockFileSystem::Make(mock_now, {})); + // build our dummy table + BuildTable(); + + auto key_list = BuildKeyMap(dsColumnMasterKeyIds, dsColumnMasterKeys, dsNumColumns, + dsFooterMasterKeyId, dsFooterMasterKey); + + SetupCryptoFactory(true, key_list); + + column_key_mapping_ = "col_key: a"; + + // Setup our Dataset encrytion configurations + dataset_encryption_config_.crypto_factory = crypto_factory_; + dataset_encryption_config_.kms_connection_config = + std::make_shared<::parquet::encryption::KmsConnectionConfig>( + kms_connection_config_); + dataset_encryption_config_.encryption_config = + std::make_shared<::parquet::encryption::EncryptionConfiguration>( + footer_key_name_); + dataset_encryption_config_.encryption_config->column_keys = column_key_mapping_; + dataset_encryption_config_.encryption_config->footer_key = footer_key_name_; + + dataset_decryption_config_.crypto_factory = crypto_factory_; + dataset_decryption_config_.kms_connection_config = + std::make_shared<::parquet::encryption::KmsConnectionConfig>( + kms_connection_config_); + dataset_decryption_config_.decryption_config = + std::make_shared<::parquet::encryption::DecryptionConfiguration>(); + + // create our Parquet file format object + file_format_ = std::make_shared<ParquetFileFormat>(); + + file_format_->SetDatasetEncryptionConfig( + std::make_shared<::parquet::encryption::DatasetEncryptionConfiguration>( + dataset_encryption_config_)); + file_format_->SetDatasetDecryptionConfig( + std::make_shared<::parquet::encryption::DatasetDecryptionConfiguration>( + dataset_decryption_config_)); + } + + /** utility to build the key map + * + */ + std::unordered_map<std::string, std::string> BuildKeyMap( + const std::string_view* column_ids, const std::string_view* column_keys, + int num_columns, const std::string_view& footer_id, + const std::string_view& footer_key) { + std::unordered_map<std::string, std::string> key_map; + // add column keys + for (int i = 0; i < num_columns; i++) { + key_map.insert({std::string(column_ids[i]), std::string(column_keys[i])}); + } + // add footer key + key_map.insert({std::string(footer_id), std::string(footer_key)}); + + return key_map; + } + + /** utilty to build column key mapping Review Comment: changed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org