tolleybot commented on code in PR #34616: URL: https://github.com/apache/arrow/pull/34616#discussion_r1267123041
########## cpp/src/arrow/dataset/dataset_encryption_test.cc: ########## @@ -0,0 +1,402 @@ +// 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 <string_view> + +#include "gtest/gtest.h" + +#include "arrow/api.h" +#include "arrow/array/builder_primitive.h" +#include "arrow/builder.h" +#include "arrow/dataset/api.h" +#include "arrow/dataset/parquet_encryption_config.h" +#include "arrow/dataset/partition.h" +#include "arrow/filesystem/mockfs.h" +#include "arrow/io/api.h" +#include "arrow/status.h" +#include "arrow/table.h" +#include "arrow/testing/gtest_util.h" +#include "parquet/arrow/reader.h" +#include "parquet/encryption/test_in_memory_kms.h" + +constexpr std::string_view kFooterKeyMasterKey = "0123456789012345"; +constexpr std::string_view kFooterKeyMasterKeyId = "footer_key"; +constexpr std::string_view kColumnMasterKeys[] = {"1234567890123450"}; +constexpr std::string_view kColumnMasterKeysIds[] = {"col_key"}; +constexpr std::string_view kBaseDir = ""; +const int kNumColumns = 1; + +namespace arrow { +namespace dataset { + +class DatasetEncryptionTest : public ::testing::Test { + protected: + // Create our parquetfileformat with encryption properties + std::pair<std::shared_ptr<DatasetEncryptionConfiguration>, + std::shared_ptr<DatasetDecryptionConfiguration>> + CreateDatasetEncryptionConfig(const std::string_view* column_ids, + const std::string_view* column_keys, int num_columns, + std::string_view footer_id, std::string_view footer_key, + std::string_view footer_key_name = "footer_key", + std::string_view column_key_mapping = "col_key: a") { + auto key_list = + BuildKeyMap(column_ids, column_keys, num_columns, footer_id, footer_key); + + auto crypto_factory = SetupCryptoFactory(/*wrap_locally=*/true, key_list); + + auto encryption_config = + std::make_shared<::parquet::encryption::EncryptionConfiguration>( + std::string(footer_key_name)); + encryption_config->column_keys = column_key_mapping; + if (footer_key_name.size() > 0) { + encryption_config->footer_key = footer_key_name; + } + + // DatasetEncryptionConfiguration + DatasetEncryptionConfiguration dataset_encryption_config; + dataset_encryption_config.crypto_factory = crypto_factory; + dataset_encryption_config.encryption_config = encryption_config; + + // DatasetDecryptionConfiguration + DatasetDecryptionConfiguration dataset_decryption_config; + dataset_decryption_config.crypto_factory = crypto_factory; + + return std::make_pair( + std::make_shared<DatasetEncryptionConfiguration>(dataset_encryption_config), + std::make_shared<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; + } + + // A utility function to validate our files were written out */ + void ValidateFilesExist(const std::shared_ptr<arrow::fs::internal::MockFileSystem>& fs, + const std::vector<std::string>& files) { + for (const auto& file_path : files) { + ASSERT_OK_AND_ASSIGN(auto result, fs->GetFileInfo(file_path)); + + ASSERT_NE(result.type(), arrow::fs::FileType::NotFound); Review Comment: Ok -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
