From 698490f175e57007d478fa9cab1faeef9ef19409 Mon Sep 17 00:00:00 2001 From: microzchang <110015819+microzchang@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:28:01 +0800 Subject: [PATCH] Storage/Enable Test Cases(Resolve Issue #5524) (#5532) * Enable Test Cases * Fix Customer provided key --- sdk/storage/assets.json | 2 +- .../test/ut/blob_container_client_test.cpp | 27 ++++++---- .../ut/datalake_file_system_client_test.cpp | 53 +++++++++++++------ .../test/ut/share_directory_client_test.cpp | 8 +-- .../test/ut/share_file_client_test.cpp | 2 +- 5 files changed, 60 insertions(+), 32 deletions(-) diff --git a/sdk/storage/assets.json b/sdk/storage/assets.json index d8e00bbcd..4aafd9556 100644 --- a/sdk/storage/assets.json +++ b/sdk/storage/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "cpp", "TagPrefix": "cpp/storage", - "Tag": "cpp/storage_48454df579" + "Tag": "cpp/storage_3d44001e6b" } diff --git a/sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp b/sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp index 18ca1cc28..6bf6119e3 100644 --- a/sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp @@ -616,7 +616,7 @@ namespace Azure { namespace Storage { namespace Test { } } - TEST_F(BlobContainerClientTest, CustomerProvidedKey_LIVEONLY_) + TEST_F(BlobContainerClientTest, CustomerProvidedKey) { auto sourceContainerClient = *m_blobContainerClient; @@ -629,6 +629,7 @@ namespace Azure { namespace Storage { namespace Test { key.Algorithm = Blobs::Models::EncryptionAlgorithmType::Aes256; return key; }; + auto redactedKeyHash = Core::Convert::Base64Decode("REDACTED"); Blobs::BlobClientOptions options; options.CustomerProvidedKey = getRandomCustomerProvidedKey(); @@ -665,14 +666,16 @@ namespace Azure { namespace Storage { namespace Test { auto blobContentInfo = appendBlob.Create().Value; EXPECT_TRUE(blobContentInfo.IsServerEncrypted); EXPECT_TRUE(blobContentInfo.EncryptionKeySha256.HasValue()); - EXPECT_EQ( - blobContentInfo.EncryptionKeySha256.Value(), options.CustomerProvidedKey.Value().KeyHash); + EXPECT_TRUE( + blobContentInfo.EncryptionKeySha256.Value() == options.CustomerProvidedKey.Value().KeyHash + || blobContentInfo.EncryptionKeySha256.Value() == redactedKeyHash); auto blobItem = GetBlobItem(appendBlobName); EXPECT_TRUE(blobItem.Details.IsServerEncrypted); EXPECT_TRUE(blobItem.Details.EncryptionKeySha256.HasValue()); - EXPECT_EQ( - blobItem.Details.EncryptionKeySha256.Value(), - options.CustomerProvidedKey.Value().KeyHash); + EXPECT_TRUE( + blobItem.Details.EncryptionKeySha256.Value() + == options.CustomerProvidedKey.Value().KeyHash + || blobItem.Details.EncryptionKeySha256.Value() == redactedKeyHash); bodyStream.Rewind(); EXPECT_NO_THROW(appendBlob.AppendBlock(bodyStream)); @@ -682,9 +685,10 @@ namespace Azure { namespace Storage { namespace Test { auto setMetadataRes = appendBlob.SetMetadata({}); EXPECT_TRUE(setMetadataRes.Value.IsServerEncrypted); ASSERT_TRUE(setMetadataRes.Value.EncryptionKeySha256.HasValue()); - EXPECT_EQ( - setMetadataRes.Value.EncryptionKeySha256.Value(), - options.CustomerProvidedKey.Value().KeyHash); + EXPECT_TRUE( + setMetadataRes.Value.EncryptionKeySha256.Value() + == options.CustomerProvidedKey.Value().KeyHash + || setMetadataRes.Value.EncryptionKeySha256.Value() == redactedKeyHash); EXPECT_NO_THROW(appendBlob.CreateSnapshot()); auto appendBlobClientWithoutEncryptionKey @@ -712,8 +716,9 @@ namespace Azure { namespace Storage { namespace Test { auto blobContentInfo = pageBlob.Create(0).Value; EXPECT_TRUE(blobContentInfo.IsServerEncrypted); EXPECT_TRUE(blobContentInfo.EncryptionKeySha256.HasValue()); - EXPECT_EQ( - blobContentInfo.EncryptionKeySha256.Value(), options.CustomerProvidedKey.Value().KeyHash); + EXPECT_TRUE( + blobContentInfo.EncryptionKeySha256.Value() == options.CustomerProvidedKey.Value().KeyHash + || blobContentInfo.EncryptionKeySha256.Value() == redactedKeyHash); bodyStream.Rewind(); EXPECT_NO_THROW(pageBlob.Resize(blobContent.size())); EXPECT_NO_THROW(pageBlob.UploadPages(0, bodyStream)); diff --git a/sdk/storage/azure-storage-files-datalake/test/ut/datalake_file_system_client_test.cpp b/sdk/storage/azure-storage-files-datalake/test/ut/datalake_file_system_client_test.cpp index 25044c4ab..e8610813e 100644 --- a/sdk/storage/azure-storage-files-datalake/test/ut/datalake_file_system_client_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/ut/datalake_file_system_client_test.cpp @@ -322,7 +322,7 @@ namespace Azure { namespace Storage { namespace Test { } } - TEST_F(DataLakeFileSystemClientTest, CustomerProvidedKey_LIVEONLY_) + TEST_F(DataLakeFileSystemClientTest, CustomerProvidedKey) { auto getRandomCustomerProvidedKey = [&]() { Files::DataLake::EncryptionKey key; @@ -343,6 +343,7 @@ namespace Azure { namespace Storage { namespace Test { auto fileSystemClientWithCPK = GetFileSystemClientForTest(m_fileSystemName, clientOptionsWithCPK); auto fileSystemClientWithoutCPK = GetFileSystemClientForTest(m_fileSystemName); + auto redactedKeyHash = Core::Convert::Base64Decode("REDACTED"); // fileSystem works { @@ -358,7 +359,9 @@ namespace Azure { namespace Storage { namespace Test { auto newFileClient = std::make_shared( fileSystemClientWithCPK.RenameFile(filename1, filename2).Value); auto properties = newFileClient->GetProperties().Value; - EXPECT_EQ(customerProvidedKey.KeyHash, properties.EncryptionKeySha256.Value()); + EXPECT_TRUE( + properties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || properties.EncryptionKeySha256.Value() == redactedKeyHash); auto newFileClientWithoutEncryptionKey = std::make_shared( fileSystemClientWithoutCPK.GetFileClient(filename2)); @@ -381,7 +384,9 @@ namespace Azure { namespace Storage { namespace Test { fileSystemClientWithCPK.RenameDirectory(oldDirectoryName, newDirectoryName).Value); properties = newDirectoryClient->GetProperties().Value; EXPECT_TRUE(properties.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, properties.EncryptionKeySha256.Value()); + EXPECT_TRUE( + properties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || properties.EncryptionKeySha256.Value() == redactedKeyHash); auto newDirectoryClientWithoutEncryptionKey = std::make_shared( fileSystemClientWithoutCPK.GetDirectoryClient(newDirectoryName)); @@ -391,7 +396,9 @@ namespace Azure { namespace Storage { namespace Test { auto createResult = fileSystemClientWithCPK.GetFileClient(filename4).Create().Value; EXPECT_TRUE(createResult.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, createResult.EncryptionKeySha256.Value()); + EXPECT_TRUE( + createResult.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || createResult.EncryptionKeySha256.Value() == redactedKeyHash); } // path works @@ -410,8 +417,9 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_NO_THROW(pathClientWithCPK->SetMetadata(RandomMetadata())); auto properties = pathClientWithCPK->GetProperties().Value; EXPECT_TRUE(properties.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, properties.EncryptionKeySha256.Value()); - + EXPECT_TRUE( + properties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || properties.EncryptionKeySha256.Value() == redactedKeyHash); EXPECT_THROW(pathClientWithoutCPK->SetMetadata(RandomMetadata()), StorageException); EXPECT_THROW(pathClientWithoutCPK->GetProperties(), StorageException); EXPECT_NO_THROW(pathClientWithoutCPK->GetAccessControlList()); @@ -422,7 +430,9 @@ namespace Azure { namespace Storage { namespace Test { auto createResult = pathClient2WithCPK->Create(Files::DataLake::Models::PathResourceType::File).Value; EXPECT_TRUE(createResult.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, createResult.EncryptionKeySha256.Value()); + EXPECT_TRUE( + createResult.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || createResult.EncryptionKeySha256.Value() == redactedKeyHash); } // file works @@ -456,13 +466,17 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_NO_THROW(fileClientWithCPK->SetMetadata(RandomMetadata())); auto properties = fileClientWithCPK->GetProperties().Value; EXPECT_TRUE(properties.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, properties.EncryptionKeySha256.Value()); + EXPECT_TRUE( + properties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || properties.EncryptionKeySha256.Value() == redactedKeyHash); EXPECT_THROW(fileClientWithoutCPK->Flush(buffer.size()), StorageException); EXPECT_THROW(fileClientWithoutCPK->Download(), StorageException); auto createResult = fileClient2WithCPK->Create().Value; EXPECT_TRUE(createResult.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, createResult.EncryptionKeySha256.Value()); + EXPECT_TRUE( + createResult.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || createResult.EncryptionKeySha256.Value() == redactedKeyHash); } // directory works { @@ -489,15 +503,20 @@ namespace Azure { namespace Storage { namespace Test { directoryClientWithCPK->GetFileClient(fileName1)); EXPECT_NO_THROW(fileClientWithCPK->Create()); auto subdirectoryProperties = subdirectoryClientWithCPK->GetProperties().Value; - EXPECT_EQ(customerProvidedKey.KeyHash, subdirectoryProperties.EncryptionKeySha256.Value()); + EXPECT_TRUE( + subdirectoryProperties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || subdirectoryProperties.EncryptionKeySha256.Value() == redactedKeyHash); auto fileProperties = fileClientWithCPK->GetProperties(); - EXPECT_EQ(customerProvidedKey.KeyHash, fileProperties.Value.EncryptionKeySha256.Value()); - + EXPECT_TRUE( + fileProperties.Value.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || fileProperties.Value.EncryptionKeySha256.Value() == redactedKeyHash); // rename file auto newFileClient = directoryClientWithCPK->RenameFile(fileName1, directoryName + "/" + fileName2).Value; auto newFileProperties = newFileClient.GetProperties().Value; - EXPECT_EQ(customerProvidedKey.KeyHash, newFileProperties.EncryptionKeySha256.Value()); + EXPECT_TRUE( + newFileProperties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || newFileProperties.EncryptionKeySha256.Value() == redactedKeyHash); auto newFileClientWithoutCPK = std::make_shared( fileSystemClientWithoutCPK.GetFileClient(directoryName + "/" + fileName2)); EXPECT_THROW(newFileClientWithoutCPK->GetProperties(), StorageException); @@ -509,7 +528,9 @@ namespace Azure { namespace Storage { namespace Test { ->RenameSubdirectory(subdirectoryName1, directoryName + "/" + subdirectoryName2) .Value; auto newSubdirectoryProperties = newSubdirectoryClientWithCPK.GetProperties().Value; - EXPECT_EQ(customerProvidedKey.KeyHash, newSubdirectoryProperties.EncryptionKeySha256.Value()); + EXPECT_TRUE( + newSubdirectoryProperties.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || newSubdirectoryProperties.EncryptionKeySha256.Value() == redactedKeyHash); auto newsubdirectoryClientWithoutCPK = std::make_shared( fileSystemClientWithoutCPK.GetDirectoryClient( @@ -522,7 +543,9 @@ namespace Azure { namespace Storage { namespace Test { fileSystemClientWithCPK.GetDirectoryClient(directoryName2)); auto createResult = directoryClient2WithCPK->Create().Value; EXPECT_TRUE(createResult.EncryptionKeySha256.HasValue()); - EXPECT_EQ(customerProvidedKey.KeyHash, createResult.EncryptionKeySha256.Value()); + EXPECT_TRUE( + createResult.EncryptionKeySha256.Value() == customerProvidedKey.KeyHash + || createResult.EncryptionKeySha256.Value() == redactedKeyHash); } } diff --git a/sdk/storage/azure-storage-files-shares/test/ut/share_directory_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/ut/share_directory_client_test.cpp index 452bc6e52..15ed3a699 100644 --- a/sdk/storage/azure-storage-files-shares/test/ut/share_directory_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/ut/share_directory_client_test.cpp @@ -120,7 +120,7 @@ namespace Azure { namespace Storage { namespace Test { } } - TEST_F(FileShareDirectoryClientTest, RenameFile_LIVEONLY_) + TEST_F(FileShareDirectoryClientTest, RenameFile) { const std::string baseName = RandomString(); const std::string baseDirectoryName = baseName + "1"; @@ -285,7 +285,7 @@ namespace Azure { namespace Storage { namespace Test { } } - TEST_F(FileShareDirectoryClientTest, RenameSubdirectory_LIVEONLY_) + TEST_F(FileShareDirectoryClientTest, RenameSubdirectory) { const std::string baseName = RandomString(); const std::string baseDirectoryName = baseName + "1"; @@ -999,7 +999,7 @@ namespace Azure { namespace Storage { namespace Test { testTrailingDot(false); } - TEST_F(FileShareDirectoryClientTest, RenameAllowTrailingDot_LIVEONLY_) + TEST_F(FileShareDirectoryClientTest, RenameAllowTrailingDot) { const std::string directoryNameWithTrailingDot = RandomString() + "."; const std::string connectionString = StandardStorageConnectionString(); @@ -1099,7 +1099,7 @@ namespace Azure { namespace Storage { namespace Test { testTrailingDot(false, false); } - TEST_F(FileShareDirectoryClientTest, DISABLED_OAuth) + TEST_F(FileShareDirectoryClientTest, OAuth_PLAYBACKONLY_) { const std::string directoryName = RandomString(); diff --git a/sdk/storage/azure-storage-files-shares/test/ut/share_file_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/ut/share_file_client_test.cpp index a817b4437..abc8e7d8b 100644 --- a/sdk/storage/azure-storage-files-shares/test/ut/share_file_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/ut/share_file_client_test.cpp @@ -901,7 +901,7 @@ namespace Azure { namespace Storage { namespace Test { } } - TEST_F(FileShareFileClientTest, DISABLED_GetRangeListDiffWithRename) + TEST_F(FileShareFileClientTest, GetRangeListDiffWithRename) { size_t rangeSize = 128; std::vector rangeContent = RandomBuffer(rangeSize);