Skip to content

Commit e77eff6

Browse files
authored
Storage test cases improvements (#4819)
* soft delete test * enable setTierCold * IsConnectionReuse in record-playback mode * DISABLED_UploadPagesFromUriCrc64AccessCondition * update recording assets * ClientSecretCredentialWorks works in record-playback mode * ServiceContainerSasPermissions and ServiceBlobSasPermissions work in record-playback mode * BlobServiceClientTest.UserDelegationKey works in record-playback mode * update recordings * f
1 parent ce85f6f commit e77eff6

File tree

7 files changed

+74
-34
lines changed

7 files changed

+74
-34
lines changed

sdk/storage/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "cpp",
44
"TagPrefix": "cpp/storage",
5-
"Tag": "cpp/storage_17c4a656fc"
5+
"Tag": "cpp/storage_b920de0000"
66
}

sdk/storage/azure-storage-blobs/test/ut/blob_sas_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace Azure { namespace Storage { namespace Test {
170170
}
171171
}
172172

173-
TEST_F(BlobSasTest, ServiceContainerSasPermissions_LIVEONLY_)
173+
TEST_F(BlobSasTest, ServiceContainerSasPermissions)
174174
{
175175
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
176176
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);
@@ -184,7 +184,8 @@ namespace Azure { namespace Storage { namespace Test {
184184
auto blobServiceClient = Blobs::BlobServiceClient(
185185
m_blobServiceClient->GetUrl(),
186186
std::make_shared<Azure::Identity::ClientSecretCredential>(
187-
AadTenantId(), AadClientId(), AadClientSecret()));
187+
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions()),
188+
InitStorageClientOptions<Blobs::BlobClientOptions>());
188189
userDelegationKey = blobServiceClient.GetUserDelegationKey(sasExpiresOn).Value;
189190
}
190191

@@ -279,7 +280,7 @@ namespace Azure { namespace Storage { namespace Test {
279280
}
280281
}
281282

282-
TEST_F(BlobSasTest, ServiceBlobSasPermissions_LIVEONLY_)
283+
TEST_F(BlobSasTest, ServiceBlobSasPermissions)
283284
{
284285
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
285286
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);
@@ -293,7 +294,8 @@ namespace Azure { namespace Storage { namespace Test {
293294
auto blobServiceClient = Blobs::BlobServiceClient(
294295
m_blobServiceClient->GetUrl(),
295296
std::make_shared<Azure::Identity::ClientSecretCredential>(
296-
AadTenantId(), AadClientId(), AadClientSecret()));
297+
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions()),
298+
InitStorageClientOptions<Blobs::BlobClientOptions>());
297299
userDelegationKey = blobServiceClient.GetUserDelegationKey(sasExpiresOn).Value;
298300
}
299301

sdk/storage/azure-storage-blobs/test/ut/blob_service_client_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,15 @@ namespace Azure { namespace Storage { namespace Test {
438438
containerClient.DeleteIfExists();
439439
}
440440

441-
TEST_F(BlobServiceClientTest, UserDelegationKey_LIVEONLY_)
441+
TEST_F(BlobServiceClientTest, UserDelegationKey)
442442
{
443443
auto serviceClient = *m_blobServiceClient;
444444

445445
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);
446446

447447
std::shared_ptr<Azure::Core::Credentials::TokenCredential> credential
448448
= std::make_shared<Azure::Identity::ClientSecretCredential>(
449-
AadTenantId(), AadClientId(), AadClientSecret());
449+
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions());
450450
Blobs::BlobClientOptions options;
451451
InitStorageClientOptions(options);
452452

sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,48 @@ namespace Azure { namespace Storage { namespace Test {
7676

7777
TEST_F(BlockBlobClientTest, SoftDelete)
7878
{
79-
const std::string blobName = m_blobName;
80-
auto blobClient = *m_blockBlobClient;
81-
82-
std::vector<uint8_t> emptyContent;
83-
auto blobContent = Azure::Core::IO::MemoryBodyStream(emptyContent.data(), emptyContent.size());
84-
blobClient.Upload(blobContent);
79+
auto clientOptions = InitStorageClientOptions<Blobs::BlobClientOptions>();
80+
auto blobContainerClient
81+
= Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
82+
AdlsGen2ConnectionString(), LowercaseRandomString(), clientOptions);
83+
blobContainerClient.CreateIfNotExists();
84+
auto blobName = RandomString();
85+
auto blobClient = blobContainerClient.GetBlockBlobClient(blobName);
86+
87+
blobClient.UploadFrom(nullptr, 0);
88+
89+
auto getBlobItem = [&]() {
90+
Blobs::ListBlobsOptions options;
91+
options.Prefix = blobName;
92+
options.Include = Blobs::Models::ListBlobsIncludeFlags::Deleted;
93+
for (auto page = blobContainerClient.ListBlobs(options); page.HasPage();
94+
page.MoveToNextPage())
95+
{
96+
for (auto& blob : page.Blobs)
97+
{
98+
if (blob.Name == blobName)
99+
{
100+
return std::move(blob);
101+
}
102+
}
103+
}
104+
std::abort();
105+
};
85106

86-
auto blobItem = GetBlobItem(blobName);
107+
auto blobItem = getBlobItem();
87108
EXPECT_FALSE(blobItem.IsDeleted);
88109
EXPECT_FALSE(blobItem.Details.DeletedOn.HasValue());
89110
EXPECT_FALSE(blobItem.Details.RemainingRetentionDays.HasValue());
90111

91112
blobClient.Delete();
92113

93-
/*
94-
// Soft delete doesn't work in storage account with versioning enabled.
95-
blobItem = GetBlobItem(blobName, Blobs::Models::ListBlobsIncludeFlags::Deleted);
114+
blobItem = getBlobItem();
96115
EXPECT_TRUE(blobItem.IsDeleted);
97116
ASSERT_TRUE(blobItem.Details.DeletedOn.HasValue());
98117
EXPECT_TRUE(IsValidTime(blobItem.Details.DeletedOn.Value()));
99118
EXPECT_TRUE(blobItem.Details.RemainingRetentionDays.HasValue());
100-
*/
119+
120+
blobContainerClient.Delete();
101121
}
102122

103123
TEST_F(BlockBlobClientTest, SmallUploadDownload)
@@ -798,7 +818,7 @@ namespace Azure { namespace Storage { namespace Test {
798818
blobItem.Details.RehydratePriority.Value(), Blobs::Models::RehydratePriority::Standard);
799819
}
800820

801-
TEST_F(BlockBlobClientTest, DISABLED_SetTierCold)
821+
TEST_F(BlockBlobClientTest, SetTierCold)
802822
{
803823
m_blockBlobClient->SetAccessTier(Blobs::Models::AccessTier::Cold);
804824
auto properties = m_blockBlobClient->GetProperties().Value;

sdk/storage/azure-storage-blobs/test/ut/connection_reuse_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Azure { namespace Storage { namespace Test {
77

88
// If connection is reused, the requests with the same connection should hit the same sever. So
99
// this test verifies whether a series of requests hit the same server.
10-
TEST_F(BlockBlobClientTest, IsConnectionReused_LIVEONLY_)
10+
TEST_F(BlockBlobClientTest, IsConnectionReused)
1111
{
1212
const std::string containerName = LowercaseRandomString();
1313
const std::string blobName = LowercaseRandomString();

sdk/storage/azure-storage-blobs/test/ut/page_blob_client_test.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,37 @@ namespace Azure { namespace Storage { namespace Test {
344344
options2.TransactionalContentHash.Value().Value = contentMd5;
345345
EXPECT_NO_THROW(pageBlobClient2.UploadPagesFromUri(
346346
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2));
347-
options2.TransactionalContentHash.Value().Algorithm = HashAlgorithm::Crc64;
348-
options2.TransactionalContentHash.Value().Value
349-
= Azure::Core::Convert::Base64Decode(DummyCrc64);
350-
// EXPECT_THROW(
351-
// pageBlobClient2.UploadPagesFromUri(
352-
// 0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2),
353-
// StorageException);
354-
options2.TransactionalContentHash.Value().Value = contentCrc64;
347+
}
348+
349+
TEST_F(PageBlobClientTest, DISABLED_UploadPagesFromUriCrc64AccessCondition)
350+
{
351+
auto pageBlobClient = *m_pageBlobClient;
352+
353+
std::vector<uint8_t> blobContent = RandomBuffer(static_cast<size_t>(4_KB));
354+
const std::vector<uint8_t> contentCrc64
355+
= Azure::Storage::Crc64Hash().Final(blobContent.data(), blobContent.size());
356+
357+
pageBlobClient.Create(blobContent.size());
358+
auto contentStream = Azure::Core::IO::MemoryBodyStream(blobContent.data(), blobContent.size());
359+
pageBlobClient.UploadPages(0, contentStream);
360+
361+
auto pageBlobClient2 = GetPageBlobClientTestForTest(RandomString());
362+
pageBlobClient2.Create(blobContent.size());
363+
364+
Blobs::UploadPagesFromUriOptions options;
365+
Azure::Core::Http::HttpRange sourceRange;
366+
sourceRange.Offset = 0;
367+
sourceRange.Length = blobContent.size();
368+
options.TransactionalContentHash = ContentHash();
369+
options.TransactionalContentHash.Value().Algorithm = HashAlgorithm::Crc64;
370+
options.TransactionalContentHash.Value().Value = Azure::Core::Convert::Base64Decode(DummyCrc64);
371+
EXPECT_THROW(
372+
pageBlobClient2.UploadPagesFromUri(
373+
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options),
374+
StorageException);
375+
options.TransactionalContentHash.Value().Value = contentCrc64;
355376
EXPECT_NO_THROW(pageBlobClient2.UploadPagesFromUri(
356-
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2));
377+
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options));
357378
}
358379

359380
TEST_F(PageBlobClientTest, CreateIfNotExists)

sdk/storage/azure-storage-common/test/ut/bearer_token_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
namespace Azure { namespace Storage { namespace Test {
77

8-
TEST_F(StorageTest, ClientSecretCredentialWorks_LIVEONLY_)
8+
TEST_F(StorageTest, ClientSecretCredentialWorks)
99
{
1010
const std::string containerName = LowercaseRandomString();
1111
auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
1212
StandardStorageConnectionString(), containerName);
1313
auto credential = std::make_shared<Azure::Identity::ClientSecretCredential>(
14-
AadTenantId(),
15-
AadClientId(),
16-
AadClientSecret(),
17-
InitStorageClientOptions<Core::Credentials::TokenCredentialOptions>());
14+
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions());
1815
containerClient = Blobs::BlobContainerClient(
1916
containerClient.GetUrl(), credential, InitStorageClientOptions<Blobs::BlobClientOptions>());
2017

0 commit comments

Comments
 (0)