From c4c7e6a983c99e1433f0e3ce5342f0c026d8dfb0 Mon Sep 17 00:00:00 2001 From: gearama <50641385+gearama@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:18:56 -0800 Subject: [PATCH] Remove SAS and deps from tables (#6311) * test1 * dsaf * clangs * remove enum_operators as they where only used for sas related operations --- sdk/tables/azure-data-tables/CMakeLists.txt | 10 +- .../inc/azure/data/tables.hpp | 5 - .../azure/data/tables/account_sas_builder.hpp | 207 ------------------ .../credentials/azure_sas_credential.hpp | 47 ---- .../credentials/named_key_credential.hpp | 68 ------ .../inc/azure/data/tables/enum_operators.hpp | 85 ------- .../inc/azure/data/tables/models.hpp | 1 - .../inc/azure/data/tables/table_client.hpp | 17 -- .../data/tables/table_service_client.hpp | 14 -- .../azure/data/tables/tables_sas_builder.hpp | 151 ------------- .../src/account_sas_builder.cpp | 131 ----------- .../src/cryptography/hmacsha256.cpp | 166 -------------- .../src/private/hmacsha256.hpp | 21 -- .../azure-data-tables/src/table_clients.cpp | 21 -- .../src/tables_sas_builder.cpp | 155 ------------- .../azure-data-tables/test/ut/CMakeLists.txt | 3 - .../test/ut/enum_operators_test.cpp | 147 ------------- .../test/ut/enum_operators_test.hpp | 21 -- .../azure-data-tables/test/ut/sas_test.cpp | 133 ----------- .../azure-data-tables/test/ut/sas_test.hpp | 30 --- .../test/ut/table_client_test.cpp | 39 +--- .../test/ut/table_client_test.hpp | 3 +- 22 files changed, 3 insertions(+), 1472 deletions(-) delete mode 100644 sdk/tables/azure-data-tables/inc/azure/data/tables/account_sas_builder.hpp delete mode 100644 sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/azure_sas_credential.hpp delete mode 100644 sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/named_key_credential.hpp delete mode 100644 sdk/tables/azure-data-tables/inc/azure/data/tables/enum_operators.hpp delete mode 100644 sdk/tables/azure-data-tables/inc/azure/data/tables/tables_sas_builder.hpp delete mode 100644 sdk/tables/azure-data-tables/src/account_sas_builder.cpp delete mode 100644 sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp delete mode 100644 sdk/tables/azure-data-tables/src/private/hmacsha256.hpp delete mode 100644 sdk/tables/azure-data-tables/src/tables_sas_builder.cpp delete mode 100644 sdk/tables/azure-data-tables/test/ut/enum_operators_test.cpp delete mode 100644 sdk/tables/azure-data-tables/test/ut/enum_operators_test.hpp delete mode 100644 sdk/tables/azure-data-tables/test/ut/sas_test.cpp delete mode 100644 sdk/tables/azure-data-tables/test/ut/sas_test.hpp diff --git a/sdk/tables/azure-data-tables/CMakeLists.txt b/sdk/tables/azure-data-tables/CMakeLists.txt index fcc5b35fa..ee396af9c 100644 --- a/sdk/tables/azure-data-tables/CMakeLists.txt +++ b/sdk/tables/azure-data-tables/CMakeLists.txt @@ -41,27 +41,19 @@ endif() set( AZURE_DATA_TABLES_HEADER - inc/azure/data/tables/account_sas_builder.hpp - inc/azure/data/tables/credentials/azure_sas_credential.hpp - inc/azure/data/tables/credentials/named_key_credential.hpp inc/azure/data/tables/dll_import_export.hpp - inc/azure/data/tables/enum_operators.hpp inc/azure/data/tables/models.hpp inc/azure/data/tables/rtti.hpp inc/azure/data/tables.hpp inc/azure/data/tables/table_client.hpp inc/azure/data/tables/table_service_client.hpp - inc/azure/data/tables/tables_sas_builder.hpp ) set( AZURE_DATA_TABLES_SOURCE - src/account_sas_builder.cpp - src/cryptography/hmacsha256.cpp src/models.cpp src/policies/tenant_bearer_token_policy.cpp src/policies/timeout_policy.cpp - src/private/hmacsha256.hpp src/private/package_version.hpp src/private/policies/service_version_policy.hpp src/private/policies/tenant_bearer_token_policy.hpp @@ -72,7 +64,7 @@ set( src/private/xml_wrapper.hpp src/serializers.cpp src/table_clients.cpp - src/tables_sas_builder.cpp + src/xml_wrapper.cpp ) diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables.hpp index e61964580..a0587a4b8 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables.hpp @@ -8,13 +8,8 @@ #pragma once -#include "azure/data/tables/account_sas_builder.hpp" -#include "azure/data/tables/credentials/azure_sas_credential.hpp" -#include "azure/data/tables/credentials/named_key_credential.hpp" #include "azure/data/tables/dll_import_export.hpp" -#include "azure/data/tables/enum_operators.hpp" #include "azure/data/tables/models.hpp" #include "azure/data/tables/rtti.hpp" #include "azure/data/tables/table_client.hpp" #include "azure/data/tables/table_service_client.hpp" -#include "azure/data/tables/tables_sas_builder.hpp" diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/account_sas_builder.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/account_sas_builder.hpp deleted file mode 100644 index 0fa3706f2..000000000 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/account_sas_builder.hpp +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include "azure/data/tables/credentials/named_key_credential.hpp" -#include "azure/data/tables/enum_operators.hpp" - -#include -#include - -#include - -namespace Azure { namespace Data { namespace Tables { namespace Sas { - constexpr const char* HttpsAndHttp = "https,http"; - constexpr const char* HttpsOnly = "https"; - /** - * @brief Defines the protocols permitted for Storage requests made with a shared access - * signature. - */ - enum class SasProtocol - { - /** - * @brief Only requests issued over HTTPS or HTTP will be permitted. - */ - HttpsAndHttp, - - /** - * @brief Only requests issued over HTTPS will be permitted. - */ - HttpsOnly, - }; - - namespace _detail { - inline std::string SasProtocolToString(SasProtocol protocol) - { - return protocol == SasProtocol::HttpsAndHttp ? HttpsAndHttp : HttpsOnly; - } - } // namespace _detail - - /** - * @brief Specifies the resource types accessible from an account level shared access - * signature. - */ - enum class AccountSasResourceType - { - /** - * @brief Indicates whether service-level APIs are accessible from this shared access - * signature. - */ - Service = 1, - - /** - * @brief Indicates whether container-level APIs are accessible from this shared - * access signature. - */ - Container = 2, - - /** - * @brief Indicates whether object-level APIs for blobs, queue messages, and files are - * accessible from this shared access signature. - */ - Object = 4, - - /** - * @brief Indicates all service-level APIs are accessible from this shared access - * signature. - */ - All = ~0, - }; - - /** - * @brief Specifies the services accessible from an account level shared access signature. - */ - enum class AccountSasServices - { - /** - * @brief Indicates whether Azure Table Storage resources are accessible from the shared - * access signature. - */ - Table = 1, - /** - * @brief Indicates all services are accessible from the shared - * access signature. - */ - All = ~0, - }; - - /** - * @brief The list of permissions that can be set for an account's access policy. - */ - enum class AccountSasPermissions - { - /** - * @brief Indicates that Read is permitted. - */ - Read = 1, - - /** - * @brief Indicates that Write is permitted. - */ - Write = 2, - - /** - * @brief Indicates that Delete is permitted. - */ - Delete = 4, - - /** - * @brief Indicates that List is permitted. - */ - List = 8, - - /** - * @brief Indicates that Add is permitted. - */ - Add = 16, - - /** - * @brief Indicates that Update is permitted. - */ - Update = 32, - - /** - * @brief Indicates that all permissions are set. - */ - All = ~0, - }; - - /** - * @brief AccountSasBuilder is used to generate an account level Shared Access Signature - * (SAS) for Azure Storage services. - */ - class AccountSasBuilder final { - public: - /** - * @brief The optional signed protocol field specifies the protocol permitted for a - * request made with the SAS. - */ - SasProtocol Protocol = SasProtocol::HttpsOnly; - - /** - * @brief Optionally specify the time at which the shared access signature becomes - * valid. - */ - Azure::Nullable StartsOn; - - /** - * @brief The time at which the shared access signature becomes invalid. This field must - * be omitted if it has been specified in an associated stored access policy. - */ - Azure::DateTime ExpiresOn; - - /** - * @brief Specifies an IP address or a range of IP addresses from which to accept - * requests. If the IP address from which the request originates does not match the IP address - * or address range specified on the SAS token, the request is not authenticated. When - * specifying a range of IP addresses, note that the range is inclusive. - */ - Azure::Nullable IPRange; - - /** - * @brief The services associated with the shared access signature. The user is - * restricted to operations with the specified services. - */ - AccountSasServices Services; - - /** - * The resource types associated with the shared access signature. The user is - * restricted to operations on the specified resources. - */ - AccountSasResourceType ResourceTypes; - - /** - * @brief Optional encryption scope to use when sending requests authorized with this SAS url. - */ - std::string EncryptionScope; - - /** - * @brief Sets the permissions for an account SAS. - * - * @param permissions The - * allowed permissions. - */ - void SetPermissions(AccountSasPermissions permissions); - - /** - * @brief Sets the permissions for the SAS using a raw permissions string. - * - * @param rawPermissions Raw permissions string for the SAS. - */ - void SetPermissions(std::string rawPermissions) { Permissions = std::move(rawPermissions); } - - /** - * @brief Uses the NamedKeyCredential to sign this shared access signature, to produce - * the proper SAS query parameters for authentication requests. - * - * @param credential The named key credential. - * @return The SAS query parameters used for authenticating requests. - */ - std::string GenerateSasToken( - const Azure::Data::Tables::Credentials::NamedKeyCredential& credential); - - private: - std::string Permissions; - }; -}}}} // namespace Azure::Data::Tables::Sas diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/azure_sas_credential.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/azure_sas_credential.hpp deleted file mode 100644 index 9312538aa..000000000 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/azure_sas_credential.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include - -#include -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace Credentials { - /** - * @brief Azure Shared Access Signature (SAS) credential. - */ - class AzureSasCredential final { - private: - std::string m_signature; - mutable std::mutex m_mutex; - - public: - /** - * @brief Initializes a new instance of the AzureSasCredential. - * - * @param signature The signature for the SAS token. - */ - explicit AzureSasCredential(std::string signature) : m_signature(std::move(signature)) {} - - /** - * @brief Get the signature for the SAS token. - */ - std::string GetSignature() const - { - std::lock_guard guard(m_mutex); - return m_signature; - } - - /** - * @brief Update the signature for the SAS token. - */ - void Update(std::string signature) - { - std::lock_guard guard(m_mutex); - m_signature = std::move(signature); - } - }; -}}}} // namespace Azure::Data::Tables::Credentials diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/named_key_credential.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/named_key_credential.hpp deleted file mode 100644 index 3a25d8a3e..000000000 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/credentials/named_key_credential.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include - -#include -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace Sas { - class AccountSasBuilder; - class TablesSasBuilder; -}}}} // namespace Azure::Data::Tables::Sas - -namespace Azure { namespace Data { namespace Tables { namespace Credentials { - - /** - * @brief A NamedKeyCredential is a credential backed by an account's name and - * one of its access keys. - */ - class NamedKeyCredential final { - public: - /** - * @brief Initializes a new instance of the NamedKeyCredential. - * - * @param accountName Name of the account. - * @param accountKey Access key of the - * account. - */ - explicit NamedKeyCredential(std::string accountName, std::string accountKey) - : AccountName{std::move(accountName)}, m_accountKey{std::move(accountKey)} - { - } - - /** - * @brief Update the account's access key. This intended to be used when you've - * regenerated your account's access keys and want to update long lived clients. - * - * @param accountKey An account access key. - */ - void Update(std::string accountKey) - { - std::lock_guard guard(m_mutex); - m_accountKey = std::move(accountKey); - } - - /** - * @brief The name of the Account. - */ - const std::string AccountName; - - private: - friend class Azure::Data::Tables::Sas::AccountSasBuilder; - friend class Azure::Data::Tables::Sas::TablesSasBuilder; - - std::string GetAccountKey() const - { - std::lock_guard guard(m_mutex); - return m_accountKey; - } - - mutable std::mutex m_mutex; - std::string m_accountKey; - }; - -}}}} // namespace Azure::Data::Tables::Credentials diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/enum_operators.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/enum_operators.hpp deleted file mode 100644 index 462a3ec44..000000000 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/enum_operators.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @file enum_operators.hpp - * @brief Defines bitwise operators for enums. - * @details This file defines bitwise operators for enum classes. This allows the use of the - * operators |, |=, &, &=, ^, ^=, and ~ with enum classes. This is useful for flags enums. - * Example: enum class MyEnum { A = 1, B = 2, C = 4 }; MyEnum e = MyEnum::A | MyEnum::B; - * Example: enum class MyEnum { A = 1, B = 2, C = 4 }; MyEnum e = MyEnum::A; e &= MyEnum::B; - */ -#pragma once - -#include - -namespace Azure { namespace Data { namespace Tables { - /** - * @brief Bitwise OR operator for enum class. - */ - template {}>> - constexpr E operator|(E lhs, E rhs) - { - using type = std::underlying_type_t; - return static_cast(static_cast(lhs) | static_cast(rhs)); - } - - /** - * @brief Bitwise OR EQUALS operator for enum class. - */ - template {}>> - constexpr E& operator|=(E& lhs, E rhs) - { - lhs = lhs | rhs; - return lhs; - } - - /** - * @brief Bitwise AND operator for enum class. - */ - template {}>> - constexpr E operator&(E lhs, E rhs) - { - using type = std::underlying_type_t; - return static_cast(static_cast(lhs) & static_cast(rhs)); - } - - /** - * @brief Bitwise AND EQUALS operator for enum class. - */ - template {}>> - constexpr E& operator&=(E& lhs, E rhs) - { - lhs = lhs & rhs; - return lhs; - } - - /** - * @brief Bitwise XOR operator for enum class. - */ - template {}>> - constexpr E operator^(E lhs, E rhs) - { - using type = std::underlying_type_t; - return static_cast(static_cast(lhs) ^ static_cast(rhs)); - } - - /** - * @brief Bitwise XOR EQUALS operator for enum class. - */ - template {}>> - constexpr E& operator^=(E& lhs, E rhs) - { - lhs = lhs ^ rhs; - return lhs; - } - - /** - * @brief Bitwise COMPLEMENT operator for enum class. - */ - template {}>> constexpr E operator~(E rhs) - { - using type = std::underlying_type_t; - return static_cast(~static_cast(rhs)); - } -}}} // namespace Azure::Data::Tables diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/models.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/models.hpp index 9df5e3d0c..18219b428 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/models.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables/models.hpp @@ -4,7 +4,6 @@ #pragma once #include "azure/data/tables/dll_import_export.hpp" -#include "azure/data/tables/enum_operators.hpp" #include #include diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/table_client.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/table_client.hpp index bf0967f19..2f774cc57 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/table_client.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables/table_client.hpp @@ -3,8 +3,6 @@ #pragma once -#include "azure/data/tables/credentials/azure_sas_credential.hpp" -#include "azure/data/tables/credentials/named_key_credential.hpp" #include "azure/data/tables/models.hpp" #include @@ -88,21 +86,6 @@ namespace Azure { namespace Data { namespace Tables { std::shared_ptr credential, const TableClientOptions& options = {}); - /** - * @brief Initializes a new instance of tableClient. - * - * @param serviceUrl The service Url - * @param credential The SAS credential used to sign requests. - * @param tableName The name of the table. - * @param options Optional client options that define the transport pipeline policies for - * authentication, retries, etc., that are applied to every request. - */ - explicit TableClient( - const std::string& serviceUrl, - std::shared_ptr credential, - const std::string& tableName, - const TableClientOptions& options = {}); - /** * @brief Add entity in a table. * diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/table_service_client.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/table_service_client.hpp index 6fb8c759c..94ebcc857 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/table_service_client.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables/table_service_client.hpp @@ -50,20 +50,6 @@ namespace Azure { namespace Data { namespace Tables { std::shared_ptr credential, const TableClientOptions& options = {}); - /** - * @brief Initializes a new instance of tableClient. - * - * @param serviceUrl A url referencing the table that includes the name of the account and the - * name of the table. - * @param credential The SAS credential used to sign requests. - * @param options Optional client options that define the transport pipeline policies for - * authentication, retries, etc., that are applied to every request. - */ - explicit TableServiceClient( - const std::string& serviceUrl, - std::shared_ptr credential, - const TableClientOptions& options = {}); - /** * @brief Creates a new table under the given account. * diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_sas_builder.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_sas_builder.hpp deleted file mode 100644 index 156af16f4..000000000 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_sas_builder.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include "azure/data/tables/account_sas_builder.hpp" -#include "azure/data/tables/credentials/named_key_credential.hpp" -#include "azure/data/tables/enum_operators.hpp" - -#include -#include - -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace Sas { - - /** - * @brief Contains the list of - * permissions that can be set for a table's access policy. - */ - enum class TablesSasPermissions - { - /** - * @brief Indicates that Read is permitted. - */ - Read = 1, - /** - * @brief Indicates that Add is permitted. - */ - Add = 2, - /** - * @brief Indicates that Delete is permitted. - */ - Delete = 4, - /** - * @brief Indicates that Update is permitted. - */ - Update = 8, - /** - * @brief Indicates that all permissions are set. - */ - All = ~0 - }; - - /** - * @brief TableSasBuilder is used to generate a Shared Access Signature (SAS) for an Azure - * Storage Tables. - */ - class TablesSasBuilder final { - public: - /** - * @brief The optional signed protocol field specifies the protocol permitted for a - * request made with the SAS. - */ - SasProtocol Protocol; - - /** - * @brief Optionally specify the time at which the shared access signature becomes - * valid. This timestamp will be truncated to second. - */ - Azure::Nullable StartsOn; - - /** - * @brief The time at which the shared access signature becomes invalid. This field must - * be omitted if it has been specified in an associated stored access policy. This timestamp - * will be truncated to second. - */ - Azure::DateTime ExpiresOn; - - /** - * @brief Specifies an IP address or a range of IP addresses from which to accept - * requests. If the IP address from which the request originates does not match the IP address - * or address range specified on the SAS token, the request is not authenticated. When - * specifying a range of IP addresses, note that the range is inclusive. - */ - Azure::Nullable IPRange; - - /** - * @brief An optional unique value up to 64 characters in length that correlates to an - * access policy specified for the table. - */ - std::string Identifier; - - /** - * @brief The name of the table being made accessible. - */ - std::string TableName; - - /** - * @brief The optional start of the partition key values range being made available. - */ - std::string PartitionKeyStart; - - /** - * @brief The optional end of the partition key values range being made available. - */ - std::string PartitionKeyEnd; - - /** - * @brief The optional start of the row key values range being made available. - */ - std::string RowKeyStart; - - /** - * @brief The optional end of the partition key values range being made available. - */ - std::string RowKeyEnd; - - /** - * @brief Sets the permissions for the table SAS. - * - * @param permissions The allowed permissions. - */ - void SetPermissions(TablesSasPermissions permissions); - - /** - * @brief Sets the permissions for the SAS using a raw permissions string. - * - * @param rawPermissions Raw permissions string for the SAS. - */ - void SetPermissions(std::string rawPermissions) { Permissions = std::move(rawPermissions); } - - /** - * @brief Uses the NamedKeyCredential to sign this shared access signature, to produce - * the proper SAS query parameters for authentication requests. - * - * @param credential The named key credential. - * @return The SAS query parameters used for authenticating requests. - */ - std::string GenerateSasToken( - const Azure::Data::Tables::Credentials::NamedKeyCredential& credential); - - /** - * @brief Gets the canonical path for the shared access signature. - * - * @param credential The named key credential. - * @return Canonical path. - */ - std::string GetCanonicalName( - const Azure::Data::Tables::Credentials::NamedKeyCredential& credential) const - { - return Azure::Core::_internal::StringExtensions::ToLower( - "/table/" + credential.AccountName + "/" + TableName); - } - - private: - std::string Permissions; - }; - -}}}} // namespace Azure::Data::Tables::Sas diff --git a/sdk/tables/azure-data-tables/src/account_sas_builder.cpp b/sdk/tables/azure-data-tables/src/account_sas_builder.cpp deleted file mode 100644 index 8fe601749..000000000 --- a/sdk/tables/azure-data-tables/src/account_sas_builder.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#include "azure/data/tables/account_sas_builder.hpp" - -#include "private/hmacsha256.hpp" -#include "private/url_encode.hpp" - -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace Sas { - namespace { - constexpr const char* SasVersion = "2023-08-03"; - } - - void AccountSasBuilder::SetPermissions(AccountSasPermissions permissions) - { - Permissions.clear(); - if ((permissions & AccountSasPermissions::Read) == AccountSasPermissions::Read) - { - Permissions += "r"; - } - if ((permissions & AccountSasPermissions::Write) == AccountSasPermissions::Write) - { - Permissions += "w"; - } - if ((permissions & AccountSasPermissions::Delete) == AccountSasPermissions::Delete) - { - Permissions += "d"; - } - if ((permissions & AccountSasPermissions::List) == AccountSasPermissions::List) - { - Permissions += "l"; - } - if ((permissions & AccountSasPermissions::Add) == AccountSasPermissions::Add) - { - Permissions += "a"; - } - if ((permissions & AccountSasPermissions::Update) == AccountSasPermissions::Update) - { - Permissions += "u"; - } - } - - std::string AccountSasBuilder::GenerateSasToken( - const Azure::Data::Tables::Credentials::NamedKeyCredential& credential) - { - std::string protocol = _detail::SasProtocolToString(Protocol); - - std::string services; - if ((Services & AccountSasServices::Table) == AccountSasServices::Table) - { - services += "t"; - } - - std::string resourceTypes; - if ((ResourceTypes & AccountSasResourceType::Service) == AccountSasResourceType::Service) - { - resourceTypes += "s"; - } - if ((ResourceTypes & AccountSasResourceType::Container) == AccountSasResourceType::Container) - { - resourceTypes += "c"; - } - if ((ResourceTypes & AccountSasResourceType::Object) == AccountSasResourceType::Object) - { - resourceTypes += "o"; - } - - std::string startsOnStr = StartsOn.HasValue() - ? StartsOn.Value().ToString( - Azure::DateTime::DateFormat::Rfc3339, Azure::DateTime::TimeFractionFormat::Truncate) - : ""; - std::string expiresOnStr = ExpiresOn.ToString( - Azure::DateTime::DateFormat::Rfc3339, Azure::DateTime::TimeFractionFormat::Truncate); - - std::string stringToSign = credential.AccountName + "\n" + Permissions + "\n" + services + "\n" - + resourceTypes + "\n" + startsOnStr + "\n" + expiresOnStr + "\n" - + (IPRange.HasValue() ? IPRange.Value() : "") + "\n" + protocol + "\n" + SasVersion + "\n" - + EncryptionScope + "\n"; - - std::string signature = Azure::Core::Convert::Base64Encode( - Azure::Data::Tables::_detail::Cryptography::HmacSha256::Compute( - std::vector(stringToSign.begin(), stringToSign.end()), - Azure::Core::Convert::Base64Decode(credential.GetAccountKey()))); - - Azure::Core::Url builder; - builder.AppendQueryParameter( - "sv", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(SasVersion)); - builder.AppendQueryParameter( - "ss", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(services)); - builder.AppendQueryParameter( - "srt", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - resourceTypes)); - builder.AppendQueryParameter( - "sp", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(Permissions)); - if (!startsOnStr.empty()) - { - builder.AppendQueryParameter("st", startsOnStr); - } - builder.AppendQueryParameter("se", expiresOnStr); - if (IPRange.HasValue()) - { - builder.AppendQueryParameter( - "sip", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - IPRange.Value())); - } - builder.AppendQueryParameter( - "spr", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(protocol)); - builder.AppendQueryParameter( - "sig", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(signature)); - if (!EncryptionScope.empty()) - { - builder.AppendQueryParameter( - "ses", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - EncryptionScope)); - } - - return builder.GetAbsoluteUrl(); - } - -}}}} // namespace Azure::Data::Tables::Sas diff --git a/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp b/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp deleted file mode 100644 index 290b92a84..000000000 --- a/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#include "../private/hmacsha256.hpp" - -#include -#include -#include -#if defined(AZ_PLATFORM_WINDOWS) -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -// Windows needs to go before bcrypt -#include - -#include -#elif defined(AZ_PLATFORM_POSIX) -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography { -#if defined(AZ_PLATFORM_WINDOWS) - - enum class AlgorithmType - { - HmacSha256, - }; - - struct AlgorithmProviderInstance final - { - BCRYPT_ALG_HANDLE Handle; - size_t ContextSize; - size_t HashLength; - - AlgorithmProviderInstance(AlgorithmType type) - { - const wchar_t* algorithmId = nullptr; - if (type == AlgorithmType::HmacSha256) - { - algorithmId = BCRYPT_SHA256_ALGORITHM; - } - else - { - throw std::runtime_error("Unknown algorithm type."); - } - - unsigned long algorithmFlags = 0; - if (type == AlgorithmType::HmacSha256) - { - algorithmFlags = BCRYPT_ALG_HANDLE_HMAC_FLAG; - } - Handle = nullptr; - NTSTATUS status = BCryptOpenAlgorithmProvider(&Handle, algorithmId, nullptr, algorithmFlags); - if (!BCRYPT_SUCCESS(status)) - { - throw std::runtime_error("BCryptOpenAlgorithmProvider failed."); - } - DWORD objectLength = 0; - DWORD dataLength = 0; - status = BCryptGetProperty( - Handle, - BCRYPT_OBJECT_LENGTH, - reinterpret_cast(&objectLength), - sizeof(objectLength), - &dataLength, - 0); - if (!BCRYPT_SUCCESS(status)) - { - throw std::runtime_error("BCryptGetProperty failed."); - } - ContextSize = objectLength; - DWORD hashLength = 0; - status = BCryptGetProperty( - Handle, - BCRYPT_HASH_LENGTH, - reinterpret_cast(&hashLength), - sizeof(hashLength), - &dataLength, - 0); - if (!BCRYPT_SUCCESS(status)) - { - throw std::runtime_error("BCryptGetProperty failed."); - } - HashLength = hashLength; - } - - ~AlgorithmProviderInstance() { BCryptCloseAlgorithmProvider(Handle, 0); } - }; - - std::vector HmacSha256::Compute( - const std::vector& data, - const std::vector& key) - { - AZURE_ASSERT_MSG(data.size() <= ULONG_MAX, "Data size is too big."); - - static AlgorithmProviderInstance AlgorithmProvider(AlgorithmType::HmacSha256); - - std::string context; - context.resize(AlgorithmProvider.ContextSize); - - BCRYPT_HASH_HANDLE hashHandle; - NTSTATUS status = BCryptCreateHash( - AlgorithmProvider.Handle, - &hashHandle, - reinterpret_cast(&context[0]), - static_cast(context.size()), - reinterpret_cast(const_cast(&key[0])), - static_cast(key.size()), - 0); - if (!BCRYPT_SUCCESS(status)) - { - throw std::runtime_error("BCryptCreateHash failed."); - } - - status = BCryptHashData( - hashHandle, - reinterpret_cast(const_cast(data.data())), - static_cast(data.size()), - 0); - if (!BCRYPT_SUCCESS(status)) - { - throw std::runtime_error("BCryptHashData failed."); - } - - std::vector hash; - hash.resize(AlgorithmProvider.HashLength); - status = BCryptFinishHash( - hashHandle, reinterpret_cast(&hash[0]), static_cast(hash.size()), 0); - if (!BCRYPT_SUCCESS(status)) - { - throw std::runtime_error("BCryptFinishHash failed."); - } - - BCryptDestroyHash(hashHandle); - - return hash; - } - -#elif defined(AZ_PLATFORM_POSIX) - - std::vector HmacSha256::Compute( - const std::vector& data, - const std::vector& key) - { - uint8_t hash[EVP_MAX_MD_SIZE]; - unsigned int hashLength = 0; - HMAC( - EVP_sha256(), - key.data(), - static_cast(key.size()), - reinterpret_cast(data.data()), - data.size(), - reinterpret_cast(&hash[0]), - &hashLength); - - return std::vector(std::begin(hash), std::begin(hash) + hashLength); - } - -#endif -}}}}} // namespace Azure::Data::Tables::_detail::Cryptography diff --git a/sdk/tables/azure-data-tables/src/private/hmacsha256.hpp b/sdk/tables/azure-data-tables/src/private/hmacsha256.hpp deleted file mode 100644 index f34cdd04b..000000000 --- a/sdk/tables/azure-data-tables/src/private/hmacsha256.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include - -#include -#include -#include -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography { - class HmacSha256 final { - public: - static std::vector Compute( - const std::vector& data, - const std::vector& key); - }; -}}}}} // namespace Azure::Data::Tables::_detail::Cryptography diff --git a/sdk/tables/azure-data-tables/src/table_clients.cpp b/sdk/tables/azure-data-tables/src/table_clients.cpp index cfcdaa55d..d65290081 100644 --- a/sdk/tables/azure-data-tables/src/table_clients.cpp +++ b/sdk/tables/azure-data-tables/src/table_clients.cpp @@ -65,14 +65,6 @@ TableServiceClient::TableServiceClient( std::move(perOperationPolicies)); } -TableServiceClient::TableServiceClient( - const std::string& serviceUrl, - std::shared_ptr credential, - const TableClientOptions& options) - : TableServiceClient(std::string{serviceUrl + credential->GetSignature()}, options) -{ -} - TableClient TableServiceClient::GetTableClient( const std::string& tableName, TableClientOptions const& options) const @@ -291,19 +283,6 @@ TableClient::TableClient( std::move(perOperationPolicies)); } -TableClient::TableClient( - const std::string& serviceUrl, - std::shared_ptr credential, - const std::string& tableName, - const TableClientOptions& options) - : TableClient( - std::string{ - Azure::Core::Url(serviceUrl).GetAbsoluteUrl() + "/" + credential->GetSignature()}, - tableName, - options) -{ -} - Azure::Response TableServiceClient::CreateTable( std::string const& tableName, Core::Context const& context) diff --git a/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp b/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp deleted file mode 100644 index ec7ebe233..000000000 --- a/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#include "azure/data/tables/tables_sas_builder.hpp" - -#include "private/hmacsha256.hpp" -#include "private/url_encode.hpp" - -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace Sas { - namespace { - constexpr static const char* SasVersion = "2019-07-07"; - } - - void TablesSasBuilder::SetPermissions(TablesSasPermissions permissions) - { - Permissions.clear(); - // The order matters - if ((permissions & TablesSasPermissions::Read) == TablesSasPermissions::Read) - { - Permissions += "r"; - } - if ((permissions & TablesSasPermissions::Add) == TablesSasPermissions::Add) - { - Permissions += "a"; - } - if ((permissions & TablesSasPermissions::Update) == TablesSasPermissions::Update) - { - Permissions += "u"; - } - if ((permissions & TablesSasPermissions::Delete) == TablesSasPermissions::Delete) - { - Permissions += "d"; - } - } - - std::string TablesSasBuilder::GenerateSasToken( - const Azure::Data::Tables::Credentials::NamedKeyCredential& credential) - { - std::string canonicalName - = Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - GetCanonicalName(credential)); - - std::string protocol = _detail::SasProtocolToString(Protocol); - - std::string startsOnStr = StartsOn.HasValue() - ? StartsOn.Value().ToString( - Azure::DateTime::DateFormat::Rfc3339, Azure::DateTime::TimeFractionFormat::Truncate) - : ""; - std::string expiresOnStr = ExpiresOn.ToString( - Azure::DateTime::DateFormat::Rfc3339, Azure::DateTime::TimeFractionFormat::Truncate); - // the order here matters - std::string stringToSign = Permissions + "\n" + startsOnStr + "\n" + expiresOnStr + "\n" - + canonicalName + "\n" + Identifier + "\n" + (IPRange.HasValue() ? IPRange.Value() : "") - + "\n" + protocol + "\n" + SasVersion + "\n" + PartitionKeyStart + "\n" + RowKeyStart + "\n" - + PartitionKeyEnd + "\n" + RowKeyEnd; - - std::string signature = Azure::Core::Convert::Base64Encode( - Azure::Data::Tables::_detail::Cryptography::HmacSha256::Compute( - std::vector(stringToSign.begin(), stringToSign.end()), - Azure::Core::Convert::Base64Decode(credential.GetAccountKey()))); - - Azure::Core::Url builder; - - builder.AppendQueryParameter( - "sv", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(SasVersion)); - - builder.AppendQueryParameter( - "tn", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(TableName)); - - builder.AppendQueryParameter( - "spr", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(protocol)); - - if (!startsOnStr.empty()) - { - builder.AppendQueryParameter( - "st", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - startsOnStr)); - } - - if (!expiresOnStr.empty()) - { - builder.AppendQueryParameter( - "se", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - expiresOnStr)); - } - - if (IPRange.HasValue()) - { - builder.AppendQueryParameter( - "sip", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - IPRange.Value())); - } - - if (!Identifier.empty()) - { - builder.AppendQueryParameter( - "si", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - Identifier)); - } - - if (!Permissions.empty()) - { - builder.AppendQueryParameter( - "sp", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - Permissions)); - } - - builder.AppendQueryParameter( - "sig", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter(signature)); - - if (!PartitionKeyStart.empty()) - { - builder.AppendQueryParameter( - "spk", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - PartitionKeyStart)); - if (!PartitionKeyEnd.empty()) - { - builder.AppendQueryParameter( - "epk", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - PartitionKeyEnd)); - } - } - - if (!RowKeyStart.empty()) - { - builder.AppendQueryParameter( - "srk", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - RowKeyStart)); - if (!RowKeyEnd.empty()) - { - builder.AppendQueryParameter( - "erk", - Azure::Data::Tables::_detail::Cryptography::UrlUtils::UrlEncodeQueryParameter( - RowKeyEnd)); - } - } - - return builder.GetAbsoluteUrl(); - } -}}}} // namespace Azure::Data::Tables::Sas diff --git a/sdk/tables/azure-data-tables/test/ut/CMakeLists.txt b/sdk/tables/azure-data-tables/test/ut/CMakeLists.txt index 458d2cd02..9956a4d79 100644 --- a/sdk/tables/azure-data-tables/test/ut/CMakeLists.txt +++ b/sdk/tables/azure-data-tables/test/ut/CMakeLists.txt @@ -16,10 +16,7 @@ SetUpTestProxy("sdk/tables") add_executable ( azure-data-tables-test - enum_operators_test.hpp - enum_operators_test.cpp macro_guard.cpp - sas_test.cpp serializers_test.hpp serializers_test.cpp table_client_test.cpp diff --git a/sdk/tables/azure-data-tables/test/ut/enum_operators_test.cpp b/sdk/tables/azure-data-tables/test/ut/enum_operators_test.cpp deleted file mode 100644 index 605027c8f..000000000 --- a/sdk/tables/azure-data-tables/test/ut/enum_operators_test.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#include "enum_operators_test.hpp" - -using namespace Azure::Data::Tables::Sas; -using namespace Azure::Data::Tables; -namespace Azure { namespace Data { namespace Test { - TEST(EnumOperator, AndTest) - { - { - constexpr auto val = TestEnum::One & TestEnum::Two; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::One & TestEnum::One; - EXPECT_EQ(val, TestEnum::One); - } - { - auto val = TestEnum::Two & TestEnum::One; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::Two & TestEnum::Two; - EXPECT_EQ(val, TestEnum::Two); - } - { - auto val = TestEnum::One; - val &= TestEnum::Two; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::One; - val &= TestEnum::One; - EXPECT_EQ(val, TestEnum::One); - } - { - auto val = TestEnum::Two; - val &= TestEnum::One; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::Two; - val &= TestEnum::Two; - EXPECT_EQ(val, TestEnum::Two); - } - } - - TEST(EnumOperator, OrTest) - { - { - constexpr auto val = TestEnum::One | TestEnum::Two; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::One | TestEnum::One; - EXPECT_EQ(val, TestEnum::One); - } - { - auto val = TestEnum::Two | TestEnum::One; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::Two | TestEnum::Two; - EXPECT_EQ(val, TestEnum::Two); - } - { - auto val = TestEnum::One; - val |= TestEnum::Two; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::One; - val |= TestEnum::One; - EXPECT_EQ(val, TestEnum::One); - } - { - auto val = TestEnum::Two; - val |= TestEnum::One; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::Two; - val |= TestEnum::Two; - EXPECT_EQ(val, TestEnum::Two); - } - } - - TEST(EnumOperator, XorTest) - { - { - constexpr auto val = TestEnum::One ^ TestEnum::Two; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::One ^ TestEnum::One; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::Two ^ TestEnum::One; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::Two ^ TestEnum::Two; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::One; - val ^= TestEnum::Two; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::One; - val ^= TestEnum::One; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = TestEnum::Two; - val ^= TestEnum::One; - EXPECT_EQ(val, TestEnum::Three); - } - { - auto val = TestEnum::Two; - val ^= TestEnum::Two; - EXPECT_EQ(val, TestEnum::Zero); - } - } - - TEST(EnumOperator, ComplementTest) - { - { - constexpr auto val = ~TestEnum::Zero; - EXPECT_EQ(val, TestEnum::All); - } - { - auto val = ~TestEnum::All; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = ~~TestEnum::Zero; - EXPECT_EQ(val, TestEnum::Zero); - } - { - auto val = ~~TestEnum::One; - EXPECT_EQ(val, TestEnum::One); - } - } -}}} // namespace Azure::Data::Test diff --git a/sdk/tables/azure-data-tables/test/ut/enum_operators_test.hpp b/sdk/tables/azure-data-tables/test/ut/enum_operators_test.hpp deleted file mode 100644 index cda17c2e8..000000000 --- a/sdk/tables/azure-data-tables/test/ut/enum_operators_test.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// clang-format off -#include "azure/data/tables/account_sas_builder.hpp" -#include "azure/data/tables/tables_sas_builder.hpp" -#include "test/ut/test_base.hpp" - -namespace Azure { namespace Data { namespace Test { - enum class TestEnum - { - Zero = 0, - One = 1, - Two = 2, - Three = 3, - All = ~0 - }; - - class EnumOperator : public Azure::Core::Test::TestBase {}; -}}} // namespace Azure::Data::Test diff --git a/sdk/tables/azure-data-tables/test/ut/sas_test.cpp b/sdk/tables/azure-data-tables/test/ut/sas_test.cpp deleted file mode 100644 index 47e2853df..000000000 --- a/sdk/tables/azure-data-tables/test/ut/sas_test.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -#include "sas_test.hpp" - -#include -#include -#include -#include - -using namespace Azure::Data::Tables::Sas; -// cspell: words rwdlau raud bqft -namespace Azure { namespace Data { namespace Test { - TEST(SasTest, TableSasBuilderTestAllSet) - { - TablesSasBuilder sasBuilder; - sasBuilder.SetPermissions(TablesSasPermissions::All); - sasBuilder.Protocol = SasProtocol::HttpsAndHttp; - sasBuilder.StartsOn - = Azure::DateTime::Parse("2020-08-18T00:00:00Z", Azure::DateTime::DateFormat::Rfc3339); - sasBuilder.ExpiresOn - = Azure::DateTime::Parse("2022-08-18T00:00:00Z", Azure::DateTime::DateFormat::Rfc3339); - sasBuilder.Identifier = "myIdentifier"; - sasBuilder.IPRange = "iprange"; - sasBuilder.TableName = "myTableName"; - sasBuilder.RowKeyEnd = "myRowKeyEnd"; - sasBuilder.RowKeyStart = "myRowKeyStart"; - sasBuilder.PartitionKeyStart = "myStartPartitionKey"; - sasBuilder.PartitionKeyEnd = "myEndPartitionKey"; - std::string key = "accountKey"; - Azure::Data::Tables::Credentials::NamedKeyCredential cred( - "accountName", - Azure::Core::Convert::Base64Encode(std::vector(key.begin(), key.end()))); - auto sasToken = sasBuilder.GenerateSasToken(cred); - auto sasParts = SasTest::ParseQueryParameters(sasToken); - EXPECT_EQ(sasParts.at("si"), "myIdentifier"); - EXPECT_EQ(sasParts.at("sp"), "raud"); - EXPECT_EQ(sasParts.at("st"), "2020-08-18T00:00:00Z"); - EXPECT_EQ(sasParts.at("se"), "2022-08-18T00:00:00Z"); - EXPECT_EQ(sasParts.at("sip"), "iprange"); - EXPECT_EQ(sasParts.at("spr"), "https,http"); - EXPECT_FALSE(sasParts.at("sig").empty()); - EXPECT_EQ(sasParts.at("srk"), "myRowKeyStart"); - EXPECT_EQ(sasParts.at("erk"), "myRowKeyEnd"); - EXPECT_EQ(sasParts.at("spk"), "myStartPartitionKey"); - EXPECT_EQ(sasParts.at("?epk"), "myEndPartitionKey"); - } - TEST(SasTest, TableSasBuilderTestSomeSet) - { - TablesSasBuilder sasBuilder; - - sasBuilder.Protocol = SasProtocol::HttpsAndHttp; - - sasBuilder.ExpiresOn - = Azure::DateTime::Parse("2022-03-11T11:13:52Z", Azure::DateTime::DateFormat::Rfc3339); - sasBuilder.SetPermissions(TablesSasPermissions::Add); - sasBuilder.TableName = "someTableName"; - - std::string key = "*"; - Azure::Data::Tables::Credentials::NamedKeyCredential cred( - "someaccount", - Azure::Core::Convert::Base64Encode(std::vector(key.begin(), key.end()))); - auto sasToken = sasBuilder.GenerateSasToken(cred); - auto sasParts = SasTest::ParseQueryParameters(sasToken); - EXPECT_EQ(sasParts.at("?se"), "2022-03-11T11:13:52Z"); - EXPECT_EQ(sasParts.at("sp"), "a"); - EXPECT_EQ(sasParts.at("spr"), "https,http"); - EXPECT_EQ(sasParts.at("tn"), "someTableName"); - } - - TEST(SasTest, TableSasBuilderTestMin) - { - TablesSasBuilder sasBuilder; - sasBuilder.ExpiresOn - = Azure::DateTime::Parse("2022-08-18T00:00:00Z", Azure::DateTime::DateFormat::Rfc3339); - std::string key = "accountKey"; - Azure::Data::Tables::Credentials::NamedKeyCredential cred( - "accountName", - Azure::Core::Convert::Base64Encode(std::vector(key.begin(), key.end()))); - auto sasToken = sasBuilder.GenerateSasToken(cred); - auto sasParts = SasTest::ParseQueryParameters(sasToken); - EXPECT_FALSE(sasParts.at("sig").empty()); - } - - TEST(SasTest, AccountSasBuilderTestAllSet) - { - AccountSasBuilder sasBuilder; - sasBuilder.SetPermissions(AccountSasPermissions::All); - sasBuilder.Protocol = SasProtocol::HttpsAndHttp; - sasBuilder.StartsOn - = Azure::DateTime::Parse("2020-08-18T00:00:00Z", Azure::DateTime::DateFormat::Rfc3339); - sasBuilder.ExpiresOn - = Azure::DateTime::Parse("2022-08-18T00:00:00Z", Azure::DateTime::DateFormat::Rfc3339); - sasBuilder.IPRange = "iprange"; - sasBuilder.EncryptionScope = "myScope"; - sasBuilder.ResourceTypes = AccountSasResourceType::All; - sasBuilder.Services = AccountSasServices::All; - - std::string key = "accountKey"; - Azure::Data::Tables::Credentials::NamedKeyCredential cred( - "accountName", - Azure::Core::Convert::Base64Encode(std::vector(key.begin(), key.end()))); - auto sasToken = sasBuilder.GenerateSasToken(cred); - auto sasParts = SasTest::ParseQueryParameters(sasToken); - - EXPECT_EQ(sasParts.at("?se"), "2022-08-18T00:00:00Z"); - EXPECT_EQ(sasParts.at("ses"), "myScope"); - EXPECT_FALSE(sasParts.at("sig").empty()); - EXPECT_EQ(sasParts.at("sip"), "iprange"); - EXPECT_EQ(sasParts.at("sp"), "rwdlau"); - EXPECT_EQ(sasParts.at("spr"), "https,http"); - EXPECT_EQ(sasParts.at("srt"), "sco"); - EXPECT_EQ(sasParts.at("ss"), "t"); - EXPECT_EQ(sasParts.at("st"), "2020-08-18T00:00:00Z"); - EXPECT_EQ(sasParts.at("sv"), "2023-08-03"); - } - - TEST(SasTest, AccountSasBuilderTestMin) - { - AccountSasBuilder sasBuilder; - sasBuilder.SetPermissions(AccountSasPermissions::All); - sasBuilder.ExpiresOn - = Azure::DateTime::Parse("2022-08-18T00:00:00Z", Azure::DateTime::DateFormat::Rfc3339); - - std::string key = "accountKey"; - Azure::Data::Tables::Credentials::NamedKeyCredential cred( - "accountName", - Azure::Core::Convert::Base64Encode(std::vector(key.begin(), key.end()))); - auto sasToken = sasBuilder.GenerateSasToken(cred); - auto sasParts = SasTest::ParseQueryParameters(sasToken); - - EXPECT_FALSE(sasParts.at("sig").empty()); - } -}}} // namespace Azure::Data::Test diff --git a/sdk/tables/azure-data-tables/test/ut/sas_test.hpp b/sdk/tables/azure-data-tables/test/ut/sas_test.hpp deleted file mode 100644 index d502014d7..000000000 --- a/sdk/tables/azure-data-tables/test/ut/sas_test.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#include "azure/data/tables/account_sas_builder.hpp" -#include "azure/data/tables/tables_sas_builder.hpp" -#include "test/ut/test_base.hpp" - -namespace Azure { namespace Data { namespace Test { - - class SasTest : public Azure::Core::Test::TestBase { - public: - static std::map ParseQueryParameters(const std::string& query) - { - std::map result; - - auto parameters = Azure::Core::_internal::StringExtensions::Split(query, '&'); - for (const auto& p : parameters) - { - auto keyValue = Azure::Core::_internal::StringExtensions::Split(p, '='); - if (keyValue.size() == 2) - { - result[keyValue[0]] = keyValue[1]; - } - } - - return result; - } - }; -}}} // namespace Azure::Data::Test diff --git a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp index e4b771ea1..c906959e9 100644 --- a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp +++ b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp @@ -3,9 +3,6 @@ #include "table_client_test.hpp" -#include "azure/data/tables/account_sas_builder.hpp" -#include "azure/data/tables/tables_sas_builder.hpp" - #include #include @@ -64,33 +61,6 @@ namespace Azure { namespace Data { namespace Test { m_credential, tableClientOptions)); break; - case AuthType::SAS: - auto creds = std::make_shared( - GetAccountName(), GetAccountKey()); - Azure::Data::Tables::Sas::AccountSasBuilder sasBuilder; - sasBuilder.ExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60); - sasBuilder.ResourceTypes = Azure::Data::Tables::Sas::AccountSasResourceType::All; - sasBuilder.Services = Azure::Data::Tables::Sas::AccountSasServices::All; - sasBuilder.Protocol = Azure::Data::Tables::Sas::SasProtocol::HttpsOnly; - sasBuilder.SetPermissions(Azure::Data::Tables::Sas::AccountSasPermissions::All); - std::string serviceUrl = "https://" + GetAccountName() + ".table.core.windows.net/"; - auto sasCreds = std::make_shared( - sasBuilder.GenerateSasToken(*creds)); - m_tableServiceClient = std::make_shared( - Tables::TableServiceClient(serviceUrl, sasCreds, clientOptions)); - - Azure::Data::Tables::Sas::TablesSasBuilder tableSasBuilder; - tableSasBuilder.Protocol = Azure::Data::Tables::Sas::SasProtocol::HttpsOnly; - tableSasBuilder.StartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5); - tableSasBuilder.ExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60); - tableSasBuilder.SetPermissions(Azure::Data::Tables::Sas::TablesSasPermissions::All); - tableSasBuilder.TableName = m_tableName; - auto tableSasCreds - = std::make_shared( - tableSasBuilder.GenerateSasToken(*creds)); - m_tableClient = std::make_shared( - Tables::TableClient(serviceUrl, tableSasCreds, m_tableName, tableClientOptions)); - break; } } } @@ -674,9 +644,6 @@ namespace Azure { namespace Data { namespace Test { case AuthType::Key: stringValue = "key"; break; - case AuthType::SAS: - stringValue = "sas_LIVEONLY_"; - break; default: stringValue = "key"; break; @@ -684,9 +651,5 @@ namespace Azure { namespace Data { namespace Test { return stringValue; } } // namespace - INSTANTIATE_TEST_SUITE_P( - Tables, - TablesClientTest, - ::testing::Values(AuthType::Key, AuthType::SAS), - GetSuffix); + INSTANTIATE_TEST_SUITE_P(Tables, TablesClientTest, ::testing::Values(AuthType::Key), GetSuffix); }}} // namespace Azure::Data::Test diff --git a/sdk/tables/azure-data-tables/test/ut/table_client_test.hpp b/sdk/tables/azure-data-tables/test/ut/table_client_test.hpp index c996d5a7a..62e457134 100644 --- a/sdk/tables/azure-data-tables/test/ut/table_client_test.hpp +++ b/sdk/tables/azure-data-tables/test/ut/table_client_test.hpp @@ -10,8 +10,7 @@ namespace Azure { namespace Data { namespace Test { enum class AuthType { - Key = 0x0, - SAS = 0x1, + Key = 0x0 }; class TablesClientTest : public Azure::Storage::Test::StorageTest,