From 2027d5102f8fa9f07dd3f5d95ab34372e32a004d Mon Sep 17 00:00:00 2001 From: JinmingHu Date: Wed, 12 Aug 2020 10:13:16 +0800 Subject: [PATCH] add test cases for base64 encode/decode, hash wrapper (#431) --- sdk/storage/test/CMakeLists.txt | 63 ++++++++++--------- .../test/common/crypt_functions_test.cpp | 35 +++++++++++ 2 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 sdk/storage/test/common/crypt_functions_test.cpp diff --git a/sdk/storage/test/CMakeLists.txt b/sdk/storage/test/CMakeLists.txt index 6f75ad532..95118582b 100644 --- a/sdk/storage/test/CMakeLists.txt +++ b/sdk/storage/test/CMakeLists.txt @@ -4,37 +4,38 @@ cmake_minimum_required (VERSION 3.15) add_executable ( - azure-storage-test - test_base.hpp - test_base.cpp - blobs/blob_service_client_test.cpp - blobs/blob_container_client_test.hpp - blobs/blob_container_client_test.cpp - blobs/block_blob_client_test.hpp - blobs/block_blob_client_test.cpp - blobs/append_blob_client_test.hpp - blobs/append_blob_client_test.cpp - blobs/page_blob_client_test.hpp - blobs/page_blob_client_test.cpp - blobs/blob_sas_test.cpp - blobs/performance_benchmark.cpp - blobs/large_scale_test.cpp - datalake/datalake_service_client_test.hpp - datalake/datalake_service_client_test.cpp - datalake/datalake_file_system_client_test.hpp - datalake/datalake_file_system_client_test.cpp - datalake/datalake_path_client_test.hpp - datalake/datalake_path_client_test.cpp - datalake/datalake_file_client_test.hpp - datalake/datalake_file_client_test.cpp - datalake/datalake_directory_client_test.hpp - datalake/datalake_directory_client_test.cpp - common/bearer_token_test.cpp - shares/share_service_client_test.hpp - shares/share_service_client_test.cpp - shares/share_client_test.cpp - shares/share_client_test.hpp - ) + azure-storage-test + test_base.hpp + test_base.cpp + common/bearer_token_test.cpp + common/crypt_functions_test.cpp + blobs/blob_service_client_test.cpp + blobs/blob_container_client_test.hpp + blobs/blob_container_client_test.cpp + blobs/block_blob_client_test.hpp + blobs/block_blob_client_test.cpp + blobs/append_blob_client_test.hpp + blobs/append_blob_client_test.cpp + blobs/page_blob_client_test.hpp + blobs/page_blob_client_test.cpp + blobs/blob_sas_test.cpp + blobs/performance_benchmark.cpp + blobs/large_scale_test.cpp + datalake/datalake_service_client_test.hpp + datalake/datalake_service_client_test.cpp + datalake/datalake_file_system_client_test.hpp + datalake/datalake_file_system_client_test.cpp + datalake/datalake_path_client_test.hpp + datalake/datalake_path_client_test.cpp + datalake/datalake_file_client_test.hpp + datalake/datalake_file_client_test.cpp + datalake/datalake_directory_client_test.hpp + datalake/datalake_directory_client_test.cpp + shares/share_service_client_test.hpp + shares/share_service_client_test.cpp + shares/share_client_test.cpp + shares/share_client_test.hpp +) target_include_directories(azure-storage-test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/sdk/storage/test/common/crypt_functions_test.cpp b/sdk/storage/test/common/crypt_functions_test.cpp new file mode 100644 index 000000000..e94af151b --- /dev/null +++ b/sdk/storage/test/common/crypt_functions_test.cpp @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include "common/crypt.hpp" +#include "test_base.hpp" + +namespace Azure { namespace Storage { namespace Test { + + TEST(CryptFunctionsTest, Base64) + { + for (std::size_t len : {0, 10, 100, 1000, 10000}) + { + std::string data; + data.resize(len); + RandomBuffer(&data[0], data.length()); + EXPECT_EQ(Base64Decode(Base64Encode(data)), data); + } + } + + TEST(CryptFunctionsTest, Sha256) + { + EXPECT_EQ(Base64Encode(Sha256("")), "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU="); + EXPECT_EQ(Base64Encode(Sha256("Hello Azure!")), "Mjzwx2mqGHb9FSgjm33ShNmXYndkgvwA6tQmEiskOHg="); + } + + TEST(CryptFunctionsTest, HmacSha256) + { + std::string key = "8CwtGFF1mGR4bPEP9eZ0x1fxKiQ3Ca5N"; + EXPECT_EQ(Base64Encode(Hmac_Sha256("", key)), "fFy2T+EuCvAgouw/vB/RAJ75z7jwTj+uiURebkFKF5M="); + EXPECT_EQ( + Base64Encode(Hmac_Sha256("Hello Azure!", key)), + "+SBESxQVhI53mSEdZJcCBpdBkaqwzfPaVYZMAf5LP3c="); + } + +}}} // namespace Azure::Storage::Test