From 31c6816c3cdf3bab61af239cdf6c8ef5c024955c Mon Sep 17 00:00:00 2001 From: Joe maley Date: Mon, 24 Feb 2020 13:13:28 -0500 Subject: Azurite Auth Support --- include/storage_credential.h | 5 +++-- src/storage_credential.cpp | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/storage_credential.h b/include/storage_credential.h index b0359f4..bf9943f 100644 --- a/include/storage_credential.h +++ b/include/storage_credential.h @@ -26,9 +26,9 @@ namespace azure { namespace storage_lite { class shared_key_credential final : public storage_credential { public: - AZURE_STORAGE_API shared_key_credential(const std::string &account_name, const std::string &account_key); + AZURE_STORAGE_API shared_key_credential(const std::string &account_name, const std::string &account_key, bool under_test = false); - AZURE_STORAGE_API shared_key_credential(const std::string &account_name, const std::vector &account_key); + AZURE_STORAGE_API shared_key_credential(const std::string &account_name, const std::vector &account_key, bool under_test = false); AZURE_STORAGE_API void sign_request(const storage_request_base &r, http_base &h, const storage_url &url, const storage_headers &headers) const override; @@ -47,6 +47,7 @@ namespace azure { namespace storage_lite { private: std::string m_account_name; std::vector m_account_key; + bool m_under_test; }; class shared_access_signature_credential final : public storage_credential diff --git a/src/storage_credential.cpp b/src/storage_credential.cpp index 0aaa730..fab23c3 100644 --- a/src/storage_credential.cpp +++ b/src/storage_credential.cpp @@ -7,13 +7,15 @@ namespace azure { namespace storage_lite { - shared_key_credential::shared_key_credential(const std::string &account_name, const std::string &account_key) + shared_key_credential::shared_key_credential(const std::string &account_name, const std::string &account_key, const bool under_test) : m_account_name(account_name), - m_account_key(from_base64(account_key)) {} + m_account_key(from_base64(account_key)), + m_under_test(under_test) {} - shared_key_credential::shared_key_credential(const std::string &account_name, const std::vector &account_key) + shared_key_credential::shared_key_credential(const std::string &account_name, const std::vector &account_key, const bool under_test) : m_account_name(account_name), - m_account_key(account_key) {} + m_account_key(account_key), + m_under_test(under_test) {} void shared_key_credential::sign_request(const storage_request_base &, http_base &h, const storage_url &url, const storage_headers &headers) const { @@ -45,7 +47,14 @@ namespace azure { namespace storage_lite { } // Canonicalized resource - string_to_sign.append("/").append(m_account_name).append(url.get_encoded_path()); + string_to_sign.append("/").append(m_account_name); + if (m_under_test) { + // For the Azurite storage emulator, we must append the the + // account name twice. + // https://github.com/Azure/azure-storage-cpplite/issues/66 + string_to_sign.append("/").append(m_account_name); + } + string_to_sign.append(url.get_encoded_path()); for (const auto &name : url.get_query()) { string_to_sign.append("\n").append(to_lowercase(name.first)); bool first_value = true; -- 2.17.1