add test cases for base64 encode/decode, hash wrapper (#431)
This commit is contained in:
parent
65bd5c6bf4
commit
2027d5102f
@ -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})
|
||||
|
||||
|
||||
35
sdk/storage/test/common/crypt_functions_test.cpp
Normal file
35
sdk/storage/test/common/crypt_functions_test.cpp
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user