Add unit test cases that require SAS token (#359)

This commit is contained in:
JinmingHu 2020-07-29 17:42:14 +08:00 committed by GitHub
parent b0b5a18d18
commit cbec5c6af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 18 deletions

View File

@ -73,7 +73,12 @@ namespace Azure { namespace Storage { namespace Test {
blockContent = Azure::Core::Http::MemoryBodyStream(m_blobContent.data(), m_blobContent.size());
appendBlobClient.AppendBlock(&blockContent, options);
// TODO: AppendBlockFromUri must be authorized with SAS, but we don't have SAS for now.
properties = *appendBlobClient.GetProperties();
int64_t originalLength = properties.ContentLength;
appendBlobClient.AppendBlockFromUri(m_appendBlobClient->GetUri() + GetSas());
properties = *appendBlobClient.GetProperties();
EXPECT_EQ(
properties.ContentLength, static_cast<int64_t>(originalLength + m_blobContent.size()));
appendBlobClient.Delete();
EXPECT_THROW(appendBlobClient.Delete(), StorageError);

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT
#include "blob_container_client_test.hpp"
#include "blobs/blob_sas_builder.hpp"
namespace Azure { namespace Storage { namespace Test {
@ -22,6 +23,18 @@ namespace Azure { namespace Storage { namespace Test {
void BlobContainerClientTest::TearDownTestSuite() { m_blobContainerClient->Delete(); }
std::string BlobContainerClientTest::GetSas()
{
Blobs::BlobSasBuilder sasBuilder;
sasBuilder.Protocol = SasProtocol::HttpsAndHtttp;
sasBuilder.ExpiresOn = ToISO8601(std::chrono::system_clock::now() + std::chrono::hours(72));
sasBuilder.ContainerName = m_containerName;
sasBuilder.Resource = Blobs::BlobSasResource::Container;
sasBuilder.SetPermissions(Blobs::BlobContainerSasPermissions::All);
return sasBuilder.ToSasQueryParameters(
*Details::ParseConnectionString(StandardStorageConnectionString()).KeyCredential);
}
TEST_F(BlobContainerClientTest, CreateDelete)
{
auto container_client = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(

View File

@ -11,6 +11,8 @@ namespace Azure { namespace Storage { namespace Test {
static void SetUpTestSuite();
static void TearDownTestSuite();
static std::string GetSas();
static std::shared_ptr<Azure::Storage::Blobs::BlobContainerClient> m_blobContainerClient;
static std::string m_containerName;
};

View File

@ -236,22 +236,22 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_EQ(res->CommittedBlocks[0].Size, static_cast<int64_t>(block1Content.size()));
EXPECT_TRUE(res->UncommittedBlocks.empty());
// TODO: StageBlockFromUri must be authorized with SAS, but we don't have SAS for now.
/*
blockBlobClient.StageBlockFromUri(blockId2, m_blockBlobClient->GetUri());
res = blockBlobClient.GetBlockList();
EXPECT_EQ(res.ContentLength, block1Content.size());
ASSERT_FALSE(res.UncommittedBlocks.empty());
EXPECT_EQ(res.UncommittedBlocks[0].Name, blockId2);
EXPECT_EQ(res.UncommittedBlocks[0].Size, m_blobContent.size());
blockBlobClient.StageBlockFromUri(blockId2, m_blockBlobClient->GetUri() + GetSas());
Blobs::GetBlockListOptions options2;
options2.ListType = Blobs::BlockListTypeOption::All;
res = blockBlobClient.GetBlockList(options2);
EXPECT_EQ(res->ContentLength, static_cast<int64_t>(block1Content.size()));
ASSERT_FALSE(res->UncommittedBlocks.empty());
EXPECT_EQ(res->UncommittedBlocks[0].Name, blockId2);
EXPECT_EQ(res->UncommittedBlocks[0].Size, static_cast<int64_t>(m_blobContent.size()));
blockBlobClient.CommitBlockList(
{{Azure::Storage::Blobs::BlockType::Committed, blockId1},
{Azure::Storage::Blobs::BlockType::Uncommitted, blockId2}});
res = blockBlobClient.GetBlockList();
EXPECT_EQ(res.ContentLength, block1Content.size() + m_blobContent.size());
EXPECT_TRUE(res.UncommittedBlocks.empty());
*/
res = blockBlobClient.GetBlockList(options2);
EXPECT_EQ(
res->ContentLength, static_cast<int64_t>(block1Content.size() + m_blobContent.size()));
EXPECT_TRUE(res->UncommittedBlocks.empty());
}
TEST_F(BlockBlobClientTest, ConcurrentDownload)

View File

@ -121,18 +121,21 @@ namespace Azure { namespace Storage { namespace Test {
TEST_F(PageBlobClientTest, UploadFromUri)
{
// TODO: PutPageFromUri must be authorized with SAS, but we don't have SAS for now.
/*
auto pageBlobClient = Azure::Storage::Blobs::PageBlobClient::CreateFromConnectionString(
StandardStorageConnectionString(), m_containerName, RandomString());
pageBlobClient.Create(m_blobContent.size(), m_blobUploadOptions);
pageBlobClient.UploadPagesFromUri(m_pageBlobClient->GetUri(), 0, m_blobContent.size(), 0);
*/
pageBlobClient.UploadPagesFromUri(
m_pageBlobClient->GetUri() + GetSas(), 0, m_blobContent.size(), 0);
}
TEST_F(PageBlobClientTest, StartCopyIncremental)
{
// TODO: IncrementalCopyBlob must be authorized with SAS, but we don't have SAS for now.
auto pageBlobClient = Azure::Storage::Blobs::PageBlobClient::CreateFromConnectionString(
StandardStorageConnectionString(), m_containerName, RandomString());
std::string snapshot = m_pageBlobClient->CreateSnapshot()->Snapshot;
UriBuilder sourceUri(m_pageBlobClient->WithSnapshot(snapshot).GetUri());
sourceUri.AppendQueries(GetSas());
pageBlobClient.StartCopyIncremental(sourceUri.ToString());
}
}}} // namespace Azure::Storage::Test