Skip to content

Commit

Permalink
Storage/Stg94 Support for authorization ExtendedErrorDetail (#5633)
Browse files Browse the repository at this point in the history
* Support for authorization ExtendedErrorDetail

* fix clang format

* fix build error

* make tests live only
  • Loading branch information
microzchang authored May 21, 2024
1 parent 20955db commit f28e10e
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 106 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/storage",
"Tag": "cpp/storage_87fc2e350b"
"Tag": "cpp/storage_6c30beab27"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Azure { namespace Storage { namespace Blobs {
/**
* The version used for the operations to Azure storage services.
*/
constexpr static const char* ApiVersion = "2023-11-03";
constexpr static const char* ApiVersion = "2024-08-04";
} // namespace _detail
namespace Models {
/**
Expand Down
138 changes: 69 additions & 69 deletions sdk/storage/azure-storage-blobs/src/rest_client.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blobs/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ directive:
"name": "ApiVersion",
"modelAsString": false
},
"enum": ["2023-11-03"]
"enum": ["2024-08-04"]
};
- from: swagger-document
where: $.parameters
transform: >
$.ApiVersionParameter.enum[0] = "2023-11-03";
$.ApiVersionParameter.enum[0] = "2024-08-04";
```
### Rename Operations
Expand Down
32 changes: 32 additions & 0 deletions sdk/storage/azure-storage-blobs/test/ut/blob_sas_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,36 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_NO_THROW(blobClient1.Delete());
}

TEST_F(BlobSasTest, AccountSasAuthorizationErrorDetail_LIVEONLY_)
{
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);

auto keyCredential
= _internal::ParseConnectionString(StandardStorageConnectionString()).KeyCredential;
auto accountName = keyCredential->AccountName;

auto blobContainerClient = *m_blobContainerClient;
auto blobClient = *m_blockBlobClient;
const std::string blobName = m_blobName;

Sas::AccountSasBuilder accountSasBuilder;
accountSasBuilder.Protocol = Sas::SasProtocol::HttpsAndHttp;
accountSasBuilder.StartsOn = sasStartsOn;
accountSasBuilder.ExpiresOn = sasExpiresOn;
accountSasBuilder.Services = Sas::AccountSasServices::Blobs;
accountSasBuilder.ResourceTypes = Sas::AccountSasResource::Service;
accountSasBuilder.SetPermissions(Sas::AccountSasPermissions::All);
auto sasToken = accountSasBuilder.GenerateSasToken(*keyCredential);
auto unauthorizedBlobClient = GetSasAuthenticatedClient(blobClient, sasToken);
try
{
unauthorizedBlobClient.Download();
}
catch (StorageException& e)
{
EXPECT_EQ("AuthorizationResourceTypeMismatch", e.ErrorCode);
EXPECT_TRUE(e.AdditionalInformation.count("ExtendedErrorDetail") != 0);
}
}
}}} // namespace Azure::Storage::Test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Azure { namespace Storage { namespace Sas {
namespace {
constexpr static const char* SasVersion = "2024-05-04";
constexpr static const char* SasVersion = "2024-08-04";
}

void AccountSasBuilder::SetPermissions(AccountSasPermissions permissions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
/**
* The version used for the operations to Azure storage services.
*/
constexpr static const char* ApiVersion = "2023-11-03";
constexpr static const char* ApiVersion = "2024-08-04";
} // namespace _detail
namespace Models {
namespace _detail {
Expand Down
18 changes: 9 additions & 9 deletions sdk/storage/azure-storage-files-datalake/src/rest_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
request.GetUrl().AppendQueryParameter("timeout", std::to_string(options.Timeout.Value()));
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
if (options.ContinuationToken.HasValue() && !options.ContinuationToken.Value().empty())
{
request.GetUrl().AppendQueryParameter(
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
request.GetUrl().AppendQueryParameter("timeout", std::to_string(options.Timeout.Value()));
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
if (options.Resource.HasValue() && !options.Resource.Value().ToString().empty())
{
request.GetUrl().AppendQueryParameter(
Expand Down Expand Up @@ -345,7 +345,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
request.GetUrl().AppendQueryParameter("timeout", std::to_string(options.Timeout.Value()));
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
if (options.Recursive.HasValue())
{
request.GetUrl().AppendQueryParameter(
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
"If-Unmodified-Since",
options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
Expand Down Expand Up @@ -490,7 +490,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
request.SetHeader("x-ms-acl", options.Acl.Value());
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
Expand Down Expand Up @@ -543,7 +543,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
request.SetHeader("x-ms-undelete-source", options.UndeleteSource.Value());
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
Expand Down Expand Up @@ -594,7 +594,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
"If-Unmodified-Since",
options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
Expand Down Expand Up @@ -693,7 +693,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
"If-Unmodified-Since",
options.IfUnmodifiedSince.Value().ToString(Azure::DateTime::DateFormat::Rfc1123));
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
if (options.EncryptionKey.HasValue() && !options.EncryptionKey.Value().empty())
{
request.SetHeader("x-ms-encryption-key", options.EncryptionKey.Value());
Expand Down Expand Up @@ -777,7 +777,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
request.SetHeader("x-ms-proposed-lease-id", options.ProposedLeaseId.Value());
}
request.SetHeader("x-ms-version", "2023-11-03");
request.SetHeader("x-ms-version", "2024-08-04");
if (options.EncryptionKey.HasValue() && !options.EncryptionKey.Value().empty())
{
request.SetHeader("x-ms-encryption-key", options.EncryptionKey.Value());
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-files-datalake/swagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ directive:
"name": "ApiVersion",
"modelAsString": false
},
"enum": ["2023-11-03"]
"enum": ["2024-08-04"]
};
- from: swagger-document
where: $.parameters
transform: >
$.ApiVersionParameter.enum[0] = "2023-11-03";
$.ApiVersionParameter.enum[0] = "2024-08-04";
```
### Rename Operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,41 @@ namespace Azure { namespace Storage { namespace Test {
ASSERT_TRUE(properties.EncryptionScope.HasValue());
EXPECT_EQ(properties.EncryptionScope.Value(), encryptionScope);
}

TEST_F(DataLakeSasTest, AccountSasAuthorizationErrorDetail_LIVEONLY_)
{
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);

Sas::AccountSasBuilder accountSasBuilder;
accountSasBuilder.Protocol = Sas::SasProtocol::HttpsAndHttp;
accountSasBuilder.StartsOn = sasStartsOn;
accountSasBuilder.ExpiresOn = sasExpiresOn;
accountSasBuilder.Services = Sas::AccountSasServices::Blobs;
accountSasBuilder.ResourceTypes = Sas::AccountSasResource::Service;
accountSasBuilder.SetPermissions(Sas::AccountSasPermissions::All);

auto keyCredential = _internal::ParseConnectionString(AdlsGen2ConnectionString()).KeyCredential;

std::string directoryName = RandomString();
std::string fileName = RandomString();

auto dataLakeFileSystemClient = *m_fileSystemClient;
auto dataLakeDirectoryClient = dataLakeFileSystemClient.GetDirectoryClient(directoryName);
dataLakeDirectoryClient.Create();
auto dataLakeFileClient = dataLakeFileSystemClient.GetFileClient(fileName);
dataLakeFileClient.Create();

auto sasToken = accountSasBuilder.GenerateSasToken(*keyCredential);
auto unauthorizedFileClient = GetSasAuthenticatedClient(dataLakeFileClient, sasToken);
try
{
unauthorizedFileClient.Download();
}
catch (StorageException& e)
{
EXPECT_EQ("AuthorizationResourceTypeMismatch", e.ErrorCode);
EXPECT_TRUE(e.AdditionalInformation.count("ExtendedErrorDetail") != 0);
}
}
}}} // namespace Azure::Storage::Test
35 changes: 35 additions & 0 deletions sdk/storage/azure-storage-files-shares/test/ut/share_sas_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,39 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_EQ(properties.Value.HttpHeaders.CacheControl, fileSasBuilder.CacheControl);
EXPECT_EQ(properties.Value.HttpHeaders.ContentEncoding, fileSasBuilder.ContentEncoding);
}

TEST_F(ShareSasTest, AccountSasAuthorizationErrorDetail_LIVEONLY_)
{
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);

auto keyCredential
= _internal::ParseConnectionString(StandardStorageConnectionString()).KeyCredential;
auto accountName = keyCredential->AccountName;

std::string fileName = RandomString();

auto shareClient = *m_shareClient;
auto fileClient = shareClient.GetRootDirectoryClient().GetFileClient(fileName);
fileClient.Create(1);

Sas::AccountSasBuilder accountSasBuilder;
accountSasBuilder.Protocol = Sas::SasProtocol::HttpsAndHttp;
accountSasBuilder.StartsOn = sasStartsOn;
accountSasBuilder.ExpiresOn = sasExpiresOn;
accountSasBuilder.Services = Sas::AccountSasServices::Files;
accountSasBuilder.ResourceTypes = Sas::AccountSasResource::Service;
accountSasBuilder.SetPermissions(Sas::AccountSasPermissions::All);
auto sasToken = accountSasBuilder.GenerateSasToken(*keyCredential);
auto unauthorizedFileClient = GetSasAuthenticatedClient(fileClient, sasToken);
try
{
unauthorizedFileClient.Download();
}
catch (StorageException& e)
{
EXPECT_EQ("AuthorizationResourceTypeMismatch", e.ErrorCode);
EXPECT_TRUE(e.AdditionalInformation.count("ExtendedErrorDetail") != 0);
}
}
}}} // namespace Azure::Storage::Test
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ namespace Azure { namespace Storage { namespace Queues {
*/
AZ_STORAGE_QUEUES_DLLEXPORT const static ServiceVersion V2019_12_12;

/**
* @brief API version 2024-08-04.
*
*/
AZ_STORAGE_QUEUES_DLLEXPORT const static ServiceVersion V2024_08_04;

private:
std::string m_version;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Azure { namespace Storage { namespace Queues {
/**
* The version used for the operations to Azure storage services.
*/
constexpr static const char* ApiVersion = "2019-12-12";
constexpr static const char* ApiVersion = "2024-08-04";
} // namespace _detail
namespace Models {
/**
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-queues/src/queue_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Azure { namespace Storage { namespace Queues {

const ServiceVersion ServiceVersion::V2018_03_28(std::string("2018-03-28"));
const ServiceVersion ServiceVersion::V2019_12_12(std::string("2019-12-12"));
const ServiceVersion ServiceVersion::V2024_08_04(std::string("2024-08-04"));
const std::chrono::seconds EnqueueMessageOptions::MessageNeverExpires{-1};

}}} // namespace Azure::Storage::Queues
Loading

0 comments on commit f28e10e

Please sign in to comment.