| 315 | }; |
| 316 | |
| 317 | TEST_P(TestGeneratedEncryptionConfiguration, AlgorithmMetadataAndRoundTrip) { |
| 318 | const auto cipher = std::get<0>(GetParam()); |
| 319 | const bool plaintext_footer = std::get<1>(GetParam()); |
| 320 | const auto prefix_mode = std::get<2>(GetParam()); |
| 321 | if (plaintext_footer) { |
| 322 | CheckPlaintextFooterSignature(); |
| 323 | } |
| 324 | auto reader = OpenReader(MakeDecryptionProperties()); |
| 325 | const auto metadata = reader->metadata(); |
| 326 | if (plaintext_footer) { |
| 327 | ASSERT_TRUE(metadata->is_encryption_algorithm_set()); |
| 328 | const auto algorithm = metadata->encryption_algorithm(); |
| 329 | ASSERT_EQ(cipher, algorithm.algorithm); |
| 330 | EXPECT_FALSE(algorithm.aad.aad_file_unique.empty()); |
| 331 | EXPECT_EQ(prefix_mode == AadPrefixMode::External, algorithm.aad.supply_aad_prefix); |
| 332 | EXPECT_EQ(prefix_mode == AadPrefixMode::Stored ? kFileName : "", |
| 333 | algorithm.aad.aad_prefix); |
| 334 | } else { |
| 335 | // An encrypted footer declares the algorithm in FileCryptoMetaData instead. |
| 336 | EXPECT_FALSE(metadata->is_encryption_algorithm_set()); |
| 337 | } |
| 338 | reader->Close(); |
| 339 | |
| 340 | FileDecryptor decryptor; |
| 341 | // Verify every physical column and all row groups through sync and async readers. |
| 342 | ASSERT_NO_THROW(decryptor.DecryptFile(file_path_, MakeDecryptionProperties())); |
| 343 | if (prefix_mode == AadPrefixMode::Stored) { |
| 344 | ASSERT_NO_THROW(decryptor.DecryptFile( |
| 345 | file_path_, MakeDecryptionProperties(Keys::All, AadPrefix::Missing))); |
| 346 | } |
| 347 | if (plaintext_footer) { |
| 348 | // This reads only public columns and does not authenticate the keyless footer. |
| 349 | ASSERT_NO_THROW(decryptor.DecryptFile(file_path_, nullptr)); |
| 350 | } |
| 351 | EXPECT_THROW(ReadFirstSecretValue(MakeDecryptionProperties(Keys::MissingColumn)), |
| 352 | std::out_of_range); |
| 353 | EXPECT_THROW(OpenReader(MakeDecryptionProperties(Keys::WrongFooter)), ParquetException); |
| 354 | if (prefix_mode == AadPrefixMode::External) { |
| 355 | EXPECT_THROW(OpenReader(MakeDecryptionProperties(Keys::All, AadPrefix::Missing)), |
| 356 | ParquetException); |
| 357 | EXPECT_THROW(OpenReader(MakeDecryptionProperties(Keys::All, AadPrefix::Wrong)), |
| 358 | ParquetException); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | INSTANTIATE_TEST_SUITE_P( |
| 363 | GeneratedFiles, TestGeneratedEncryptionConfiguration, |
nothing calls this directly
no test coverage detected