diff --git a/sdk/src/OssClientImpl.cc b/sdk/src/OssClientImpl.cc index 6145e86..bc7e247 100644 --- a/sdk/src/OssClientImpl.cc +++ b/sdk/src/OssClientImpl.cc @@ -26,6 +26,7 @@ #include "utils/SignUtils.h" #include "utils/ThreadExecutor.h" #include "signer/Signer.h" +#include "signer/HmacSha1Signer.h" #include "OssClientImpl.h" #include "utils/LogUtils.h" #include "utils/FileSystemUtils.h" @@ -173,7 +174,7 @@ void OssClientImpl::addSignInfo(const std::shared_ptr &httpRequest, } if (httpRequest->hasHeader("x-oss-date")) { - t = ToUnixTime(httpRequest->Header(Http::DATE), "%a, %d %b %Y %H:%M:%S GMT"); + t = ToUnixTime(httpRequest->Header("x-oss-date"), "%a, %d %b %Y %H:%M:%S GMT"); } SignerParam signerParam(std::move(region), std::move(product), @@ -1716,7 +1717,7 @@ StringOutcome OssClientImpl::GenerateRTMPSignedUrl(const GenerateRTMPSignedUrlRe SignUtils signUtils(signer_->version()); auto resource = std::string().append("/").append(request.Bucket()).append("/").append(request.ChannelName()); signUtils.build(expireStr, resource, parameters); - auto signature = signer_->generate(signUtils.CanonicalString(), credentials.AccessKeySecret()); + auto signature = HmacSha1Signer::generate(signUtils.CanonicalString(), credentials.AccessKeySecret()); parameters["Expires"] = expireStr; parameters["OSSAccessKeyId"] = credentials.AccessKeyId(); parameters["Signature"] = signature; diff --git a/sdk/src/signer/HmacSha1Signer.cc b/sdk/src/signer/HmacSha1Signer.cc new file mode 100644 index 0000000..42e09c2 --- /dev/null +++ b/sdk/src/signer/HmacSha1Signer.cc @@ -0,0 +1,101 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "HmacSha1Signer.h" +#if 0//def _WIN32 +#include +#include +#else +#include +#ifdef OPENSSL_IS_BORINGSSL +#include +#endif +#endif + +using namespace AlibabaCloud::OSS; + +HmacSha1Signer::HmacSha1Signer() +{ +} + +HmacSha1Signer::~HmacSha1Signer() +{ +} + +std::string HmacSha1Signer::generate(const std::string & src, const std::string & secret) +{ + if (src.empty()) + return std::string(); + +#if 0//def _WIN32 + typedef struct _my_blob { + BLOBHEADER hdr; + DWORD dwKeySize; + BYTE rgbKeyData[]; + }my_blob; + + DWORD kbLen = sizeof(my_blob) + secret.size(); + my_blob * kb = (my_blob *)LocalAlloc(LPTR, kbLen); + kb->hdr.bType = PLAINTEXTKEYBLOB; + kb->hdr.bVersion = CUR_BLOB_VERSION; + kb->hdr.reserved = 0; + kb->hdr.aiKeyAlg = CALG_RC2; + kb->dwKeySize = secret.size(); + memcpy(&kb->rgbKeyData, secret.c_str(), secret.size()); + + HCRYPTPROV hProv = 0; + HCRYPTKEY hKey = 0; + HCRYPTHASH hHmacHash = 0; + BYTE pbHash[32]; + DWORD dwDataLen = 32; + HMAC_INFO HmacInfo; + ZeroMemory(&HmacInfo, sizeof(HmacInfo)); + HmacInfo.HashAlgid = CALG_SHA1; + + CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_NEWKEYSET); + CryptImportKey(hProv, (BYTE*)kb, kbLen, 0, CRYPT_IPSEC_HMAC_KEY, &hKey); + CryptCreateHash(hProv, CALG_HMAC, hKey, 0, &hHmacHash); + CryptSetHashParam(hHmacHash, HP_HMAC_INFO, (BYTE*)&HmacInfo, 0); + CryptHashData(hHmacHash, (BYTE*)(src.c_str()), src.size(), 0); + CryptGetHashParam(hHmacHash, HP_HASHVAL, pbHash, &dwDataLen, 0); + + LocalFree(kb); + CryptDestroyHash(hHmacHash); + CryptDestroyKey(hKey); + CryptReleaseContext(hProv, 0); + + DWORD dlen = 0; + CryptBinaryToString(pbHash, dwDataLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &dlen); + char* dest = new char[dlen]; + CryptBinaryToString(pbHash, dwDataLen, CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, dest, &dlen); + + std::string ret = std::string(dest, dlen); + delete[] dest; + return ret; +#else + unsigned char md[32]; + unsigned int mdLen = 32; + + if (HMAC(EVP_sha1(), secret.c_str(), static_cast(secret.size()), + reinterpret_cast(src.c_str()), src.size(), + md, &mdLen) == nullptr) + return std::string(); + + char encodedData[100]; + EVP_EncodeBlock(reinterpret_cast(encodedData), md, mdLen); + return encodedData; +#endif +} \ No newline at end of file diff --git a/sdk/src/signer/HmacSha1Signer.h b/sdk/src/signer/HmacSha1Signer.h new file mode 100644 index 0000000..2c3f417 --- /dev/null +++ b/sdk/src/signer/HmacSha1Signer.h @@ -0,0 +1,36 @@ +/* + * Copyright 2009-2017 Alibaba Cloud All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "Signer.h" + + +namespace AlibabaCloud +{ +namespace OSS +{ + + class HmacSha1Signer + { + public: + HmacSha1Signer(); + ~HmacSha1Signer(); + + static std::string generate(const std::string &src, const std::string &secret); + }; +} +} diff --git a/sdk/src/signer/SignerV1.cc b/sdk/src/signer/SignerV1.cc index 5acb384..44e5bd6 100644 --- a/sdk/src/signer/SignerV1.cc +++ b/sdk/src/signer/SignerV1.cc @@ -16,13 +16,10 @@ #include #include "Signer.h" +#include "HmacSha1Signer.h" #include "../utils/SignUtils.h" #include "../utils/Utils.h" #include "../utils/LogUtils.h" -#include -#ifdef OPENSSL_IS_BORINGSSL -#include -#endif using namespace AlibabaCloud::OSS; @@ -56,20 +53,7 @@ static std::string buildResource(const std::string &bucket, const std::string &k std::string SignerV1::generate(const std::string & src, const std::string & secret) const { - if (src.empty()) - return std::string(); - - unsigned char md[32]; - unsigned int mdLen = 32; - - if (HMAC(EVP_sha1(), secret.c_str(), static_cast(secret.size()), - reinterpret_cast(src.c_str()), src.size(), - md, &mdLen) == nullptr) - return std::string(); - - char encodedData[100]; - EVP_EncodeBlock(reinterpret_cast(encodedData), md, mdLen); - return encodedData; + return HmacSha1Signer::generate(src, secret); } void SignerV1::sign(const std::shared_ptr &httpRequest, ParameterCollection ¶meters, diff --git a/sdk/src/signer/SignerV4.cc b/sdk/src/signer/SignerV4.cc index 4614ee0..05512eb 100644 --- a/sdk/src/signer/SignerV4.cc +++ b/sdk/src/signer/SignerV4.cc @@ -196,6 +196,9 @@ static std::string buildCanonicalReuqest(const std::shared_ptr &htt for (const auto &header : httpRequest->Headers()) { std::string lowerKey = ToLower(header.first.c_str()); std::string value = Trim(header.second.c_str()); + if (value.empty()) { + continue; + } if (lowerKey == "content-type" || lowerKey == "content-md5" || lowerKey.compare(0, 6, "x-oss-") == 0) { @@ -288,6 +291,10 @@ void SignerV4::sign(const std::shared_ptr &httpRequest, ParameterCo httpRequest->addHeader(Http::DATE, ToGmtTime(requestTime)); httpRequest->addHeader("x-oss-date", datetime); + if (!httpRequest->hasHeader("x-oss-content-sha256")) { + httpRequest->addHeader("x-oss-content-sha256", "UNSIGNED-PAYLOAD"); + } + auto additionalHeaders = getCommonAdditionalHeaders(httpRequest->Headers(), signerParam.AdditionalHeaders()); auto canonicalReuqest = buildCanonicalReuqest(httpRequest, parameters, signerParam, additionalHeaders); diff --git a/test/src/Bucket/BucketAclSettingsTest.cc b/test/src/Bucket/BucketAclSettingsTest.cc index 6cdbc50..d72c4a6 100644 --- a/test/src/Bucket/BucketAclSettingsTest.cc +++ b/test/src/Bucket/BucketAclSettingsTest.cc @@ -35,7 +35,7 @@ class BucketAclSettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketaclsettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketBasicOperationTest.cc b/test/src/Bucket/BucketBasicOperationTest.cc index 872580b..a43311f 100644 --- a/test/src/Bucket/BucketBasicOperationTest.cc +++ b/test/src/Bucket/BucketBasicOperationTest.cc @@ -35,7 +35,7 @@ class BucketBasicOperationTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); } // Tears down the stuff shared by all tests in this test case. diff --git a/test/src/Bucket/BucketCorsSettingsTest.cc b/test/src/Bucket/BucketCorsSettingsTest.cc index b2e5ac1..ff3bf73 100644 --- a/test/src/Bucket/BucketCorsSettingsTest.cc +++ b/test/src/Bucket/BucketCorsSettingsTest.cc @@ -39,7 +39,7 @@ class BucketCorsSettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketcorssettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketEncryptionTest.cc b/test/src/Bucket/BucketEncryptionTest.cc index 9a92150..dda85d1 100644 --- a/test/src/Bucket/BucketEncryptionTest.cc +++ b/test/src/Bucket/BucketEncryptionTest.cc @@ -35,7 +35,7 @@ namespace OSS { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketencryption"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketInventoryConfigurationTest.cc b/test/src/Bucket/BucketInventoryConfigurationTest.cc index 5198866..88842f3 100644 --- a/test/src/Bucket/BucketInventoryConfigurationTest.cc +++ b/test/src/Bucket/BucketInventoryConfigurationTest.cc @@ -35,7 +35,7 @@ class BucketInventoryConfigurationTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-inventory"); DstBucketName = TestUtils::GetBucketName("cpp-sdk-inventory-dst"); Client->CreateBucket(CreateBucketRequest(BucketName)); diff --git a/test/src/Bucket/BucketLifecycleSettingsTest.cc b/test/src/Bucket/BucketLifecycleSettingsTest.cc index 017e6ea..0bb6750 100644 --- a/test/src/Bucket/BucketLifecycleSettingsTest.cc +++ b/test/src/Bucket/BucketLifecycleSettingsTest.cc @@ -36,7 +36,7 @@ class BucketLifecycleSettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketlifecyclesettings"); Client->CreateBucket(BucketName); } @@ -959,7 +959,7 @@ TEST_F(BucketLifecycleSettingsTest, SetAndGetLifecycleRuleWithVersioningTest) auto bucketName = BucketName; bucketName.append("-lc-version"); - auto client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + auto client = TestUtils::GetOssClientDefault(); auto cOutcome = client->CreateBucket(bucketName); EXPECT_EQ(cOutcome.isSuccess(), true); diff --git a/test/src/Bucket/BucketLoggingSettingsTest.cc b/test/src/Bucket/BucketLoggingSettingsTest.cc index 26d632a..7489245 100644 --- a/test/src/Bucket/BucketLoggingSettingsTest.cc +++ b/test/src/Bucket/BucketLoggingSettingsTest.cc @@ -35,7 +35,7 @@ class BucketLoggingSettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketloggingsettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketPolicySettingsTest.cc b/test/src/Bucket/BucketPolicySettingsTest.cc index 2eacd71..8b7d7a9 100644 --- a/test/src/Bucket/BucketPolicySettingsTest.cc +++ b/test/src/Bucket/BucketPolicySettingsTest.cc @@ -35,7 +35,7 @@ class BucketPolicySettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketpolicysettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketQosInfoTest.cc b/test/src/Bucket/BucketQosInfoTest.cc index 858bfc4..c23764c 100644 --- a/test/src/Bucket/BucketQosInfoTest.cc +++ b/test/src/Bucket/BucketQosInfoTest.cc @@ -36,7 +36,7 @@ namespace OSS // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketqosinfo"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketRefersSettingsTest.cc b/test/src/Bucket/BucketRefersSettingsTest.cc index 8a9f40e..e682f03 100644 --- a/test/src/Bucket/BucketRefersSettingsTest.cc +++ b/test/src/Bucket/BucketRefersSettingsTest.cc @@ -35,7 +35,7 @@ class BucketRefersSettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketreferssettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketRequestPaymentTest.cc b/test/src/Bucket/BucketRequestPaymentTest.cc index f4fac52..ed90b43 100644 --- a/test/src/Bucket/BucketRequestPaymentTest.cc +++ b/test/src/Bucket/BucketRequestPaymentTest.cc @@ -46,7 +46,7 @@ class BucketRequestPaymentTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName1 = TestUtils::GetBucketName("cpp-sdk-objectcopy1"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName1)); diff --git a/test/src/Bucket/BucketStorageCapacityTest.cc b/test/src/Bucket/BucketStorageCapacityTest.cc index 291994e..928cffa 100644 --- a/test/src/Bucket/BucketStorageCapacityTest.cc +++ b/test/src/Bucket/BucketStorageCapacityTest.cc @@ -35,7 +35,7 @@ class BucketStorageCapacityTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketstoragecapacity"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketTaggingtTest.cc b/test/src/Bucket/BucketTaggingtTest.cc index 165be09..e41af8a 100644 --- a/test/src/Bucket/BucketTaggingtTest.cc +++ b/test/src/Bucket/BucketTaggingtTest.cc @@ -37,7 +37,7 @@ namespace OSS // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-buckettagging"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketVersioningTest.cc b/test/src/Bucket/BucketVersioningTest.cc index a966b8f..c3d1116 100644 --- a/test/src/Bucket/BucketVersioningTest.cc +++ b/test/src/Bucket/BucketVersioningTest.cc @@ -35,7 +35,7 @@ namespace OSS { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-versioning"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketWebsiteSettingsTest.cc b/test/src/Bucket/BucketWebsiteSettingsTest.cc index a5ab647..661577b 100644 --- a/test/src/Bucket/BucketWebsiteSettingsTest.cc +++ b/test/src/Bucket/BucketWebsiteSettingsTest.cc @@ -35,7 +35,7 @@ class BucketWebsiteSettingsTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketwebsitesettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Bucket/BucketWormSettings.cc b/test/src/Bucket/BucketWormSettings.cc index fbc2994..c0e5abd 100644 --- a/test/src/Bucket/BucketWormSettings.cc +++ b/test/src/Bucket/BucketWormSettings.cc @@ -35,7 +35,7 @@ class BucketWormSettings : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-bucketwormsettings"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Config.cc b/test/src/Config.cc index 43d85b7..d8df941 100644 --- a/test/src/Config.cc +++ b/test/src/Config.cc @@ -30,6 +30,7 @@ static std::string dataPath_; std::string Config::AccessKeyId = ""; std::string Config::AccessKeySecret = ""; std::string Config::Endpoint = ""; +std::string Config::Region = ""; std::string Config::SecondEndpoint = ""; std::string Config::CallbackServer = ""; std::string Config::CfgFilePath = "oss.ini"; @@ -113,6 +114,9 @@ static void LoadCfgFromFile() else if (!strncmp(buffer, "Endpoint", 8)) { Config::Endpoint = TrimQuotes(Trim(ptr + 1).c_str()); } + else if (!strncmp(buffer, "Region", 6)) { + Config::Region = TrimQuotes(Trim(ptr + 1).c_str()); + } else if (!strncmp(buffer, "SecondEndpoint", 14)) { Config::SecondEndpoint = TrimQuotes(Trim(ptr + 1).c_str()); } @@ -159,6 +163,11 @@ static void LoadCfgFromEnv() Config::Endpoint = TrimQuotes(Trim(value).c_str()); } + value = std::getenv("TEST_OSS_REGION"); + if (value) { + Config::Region = TrimQuotes(Trim(value).c_str()); + } + value = std::getenv("TEST_OSS_CALLBACKSERVER"); if (value) { Config::CallbackServer = TrimQuotes(Trim(value).c_str()); diff --git a/test/src/Config.h b/test/src/Config.h index d0bbedb..8ed7260 100644 --- a/test/src/Config.h +++ b/test/src/Config.h @@ -25,6 +25,7 @@ class Config static std::string AccessKeyId; static std::string AccessKeySecret; static std::string Endpoint; + static std::string Region; static std::string SecondEndpoint; static std::string CallbackServer; static std::string CfgFilePath; diff --git a/test/src/LiveChannel/DeleteLiveChannelTest.cc b/test/src/LiveChannel/DeleteLiveChannelTest.cc index 46bf553..d89a7bd 100644 --- a/test/src/LiveChannel/DeleteLiveChannelTest.cc +++ b/test/src/LiveChannel/DeleteLiveChannelTest.cc @@ -42,7 +42,7 @@ class DeleteLiveChannelTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-delete-live-channel"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/LiveChannel/GenerateRTMPSignatrueUrlTest.cc b/test/src/LiveChannel/GenerateRTMPSignatrueUrlTest.cc index cce4a4b..6484740 100644 --- a/test/src/LiveChannel/GenerateRTMPSignatrueUrlTest.cc +++ b/test/src/LiveChannel/GenerateRTMPSignatrueUrlTest.cc @@ -42,7 +42,7 @@ class GenerateRTMPSignatureUrlTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-delete-live-channel"); } @@ -92,6 +92,39 @@ TEST_F(GenerateRTMPSignatureUrlTest, GenerateRTMPSignatureUrlUT) EXPECT_TRUE(signedURL.find("playlistName") != std::string::npos); } +TEST_F(GenerateRTMPSignatureUrlTest, GenerateRTMPSignatureUrlUT2) +{ + // v1 + auto conf = ClientConfiguration(); + auto client = std::make_shared(Config::Endpoint, "ak", "sk", conf); + + GenerateRTMPSignedUrlRequest request("cpp-sdk-live-channel-bucket", "channel", "", 0); + request.setPlayList("test.m3u8"); + + time_t tExpire = (time_t)1706289617; + request.setExpires(tExpire); + EXPECT_EQ(request.Expires(), (uint64_t)tExpire); + + auto generateOutcome = client->GenerateRTMPSignedUrl(request); + EXPECT_EQ(generateOutcome.isSuccess(), true); + EXPECT_EQ(generateOutcome.result().empty(), false); + + std::string path = "/live/channel?Expires=1706289617&OSSAccessKeyId=ak&Signature=Y1LCM2PzyECssQhTdi%2BGKra7iXE%3D&playlistName=test.m3u8"; + std::string signedURL = generateOutcome.result(); + EXPECT_TRUE(signedURL.find(path) != std::string::npos); + + // v4 + auto conf1 = ClientConfiguration(); + conf1.signatureVersion = SignatureVersionType::V4; + auto client1 = std::make_shared(Config::Endpoint, "ak", "sk", conf1); + + auto generateOutcome1 = client1->GenerateRTMPSignedUrl(request); + EXPECT_EQ(generateOutcome1.isSuccess(), true); + EXPECT_EQ(generateOutcome1.result().empty(), false); + std::string signedURL1 = generateOutcome1.result(); + EXPECT_TRUE(signedURL1.find(path) != std::string::npos); +} + TEST_F(GenerateRTMPSignatureUrlTest, GenerateRTMPSignatureUrlInvalidBucketTest) { GenerateRTMPSignedUrlRequest request("Invalid-bucket-test", "channel-name", "playlist.m3u8", 1000); diff --git a/test/src/LiveChannel/GetLiveChannelHistoryTest.cc b/test/src/LiveChannel/GetLiveChannelHistoryTest.cc index 9389c49..adfd4ed 100644 --- a/test/src/LiveChannel/GetLiveChannelHistoryTest.cc +++ b/test/src/LiveChannel/GetLiveChannelHistoryTest.cc @@ -42,7 +42,7 @@ class GetLiveChannelHistoryTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-get-live-channel-history"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/LiveChannel/ListLiveChannelTest.cc b/test/src/LiveChannel/ListLiveChannelTest.cc index 46ae0a2..28317cf 100644 --- a/test/src/LiveChannel/ListLiveChannelTest.cc +++ b/test/src/LiveChannel/ListLiveChannelTest.cc @@ -42,7 +42,7 @@ class ListLiveChannelTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-list-live-channel"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/LiveChannel/PostAndGetVodPlayListTest.cc b/test/src/LiveChannel/PostAndGetVodPlayListTest.cc index 8a30c06..0e13352 100644 --- a/test/src/LiveChannel/PostAndGetVodPlayListTest.cc +++ b/test/src/LiveChannel/PostAndGetVodPlayListTest.cc @@ -43,7 +43,7 @@ class PostAndGetVodPlayListTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-post-and-get-vod-play-list"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/LiveChannel/PutAndGetLiveChannelStatusTest.cc b/test/src/LiveChannel/PutAndGetLiveChannelStatusTest.cc index 26e0a51..02a474e 100644 --- a/test/src/LiveChannel/PutAndGetLiveChannelStatusTest.cc +++ b/test/src/LiveChannel/PutAndGetLiveChannelStatusTest.cc @@ -42,7 +42,7 @@ class PutAndGetLiveChannelStatusTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-delete-live-channel"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/LiveChannel/PutAndGetLiveChannelTest.cc b/test/src/LiveChannel/PutAndGetLiveChannelTest.cc index 9be3ece..e99ac79 100644 --- a/test/src/LiveChannel/PutAndGetLiveChannelTest.cc +++ b/test/src/LiveChannel/PutAndGetLiveChannelTest.cc @@ -42,7 +42,7 @@ class PutAndGetLiveChannelTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-put-and-get-live-channel"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/MultipartUpload/CallableTest.cc b/test/src/MultipartUpload/CallableTest.cc index a90885d..f50aeca 100644 --- a/test/src/MultipartUpload/CallableTest.cc +++ b/test/src/MultipartUpload/CallableTest.cc @@ -37,7 +37,7 @@ class CallableTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-callable"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/MultipartUpload/MultipartUploadTest.cc b/test/src/MultipartUpload/MultipartUploadTest.cc index 5756ec5..1ea894f 100644 --- a/test/src/MultipartUpload/MultipartUploadTest.cc +++ b/test/src/MultipartUpload/MultipartUploadTest.cc @@ -37,7 +37,7 @@ class MultipartUploadTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-multipartupload"); Client->CreateBucket(CreateBucketRequest(BucketName)); TestFile = TestUtils::GetTargetFileName("cpp-sdk-multipartupload"); diff --git a/test/src/MultipartUpload/ObjectAsyncTest.cc b/test/src/MultipartUpload/ObjectAsyncTest.cc index 15946af..2048980 100644 --- a/test/src/MultipartUpload/ObjectAsyncTest.cc +++ b/test/src/MultipartUpload/ObjectAsyncTest.cc @@ -40,7 +40,7 @@ class ObjectAsyncTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-multipartupload"); Client->CreateBucket(CreateBucketRequest(BucketName)); TestFile = TestUtils::GetTargetFileName("cpp-sdk-multipartupload"); diff --git a/test/src/MultipartUpload/ResumableObjectTest.cc b/test/src/MultipartUpload/ResumableObjectTest.cc index 7091376..adf8b94 100644 --- a/test/src/MultipartUpload/ResumableObjectTest.cc +++ b/test/src/MultipartUpload/ResumableObjectTest.cc @@ -43,7 +43,7 @@ class ResumableObjectTest : public::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-resumableobject"); Client->CreateBucket(CreateBucketRequest(BucketName)); UploadPartFailedFlag = 1 << 30; diff --git a/test/src/Object/ObjectAclTest.cc b/test/src/Object/ObjectAclTest.cc index 1e44b47..f4a2d4e 100644 --- a/test/src/Object/ObjectAclTest.cc +++ b/test/src/Object/ObjectAclTest.cc @@ -42,7 +42,7 @@ class ObjectAclTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectacl"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/Object/ObjectAppendTest.cc b/test/src/Object/ObjectAppendTest.cc index c0c84a6..412d872 100644 --- a/test/src/Object/ObjectAppendTest.cc +++ b/test/src/Object/ObjectAppendTest.cc @@ -38,7 +38,7 @@ class ObjectAppendTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectappend"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/Object/ObjectBasicOperationTest.cc b/test/src/Object/ObjectBasicOperationTest.cc index 208baed..1924860 100644 --- a/test/src/Object/ObjectBasicOperationTest.cc +++ b/test/src/Object/ObjectBasicOperationTest.cc @@ -38,7 +38,7 @@ class ObjectBasicOperationTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectbasicoperation"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Object/ObjectCopyTest.cc b/test/src/Object/ObjectCopyTest.cc index 7705d08..065320c 100644 --- a/test/src/Object/ObjectCopyTest.cc +++ b/test/src/Object/ObjectCopyTest.cc @@ -38,7 +38,7 @@ class ObjectCopyTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); ListBucketsRequest request; request.setPrefix("cpp-sdk-objectcopy"); diff --git a/test/src/Object/ObjectEncodingTypeTest.cc b/test/src/Object/ObjectEncodingTypeTest.cc index 71de121..2fd4fe9 100644 --- a/test/src/Object/ObjectEncodingTypeTest.cc +++ b/test/src/Object/ObjectEncodingTypeTest.cc @@ -36,7 +36,7 @@ class ObjectEncodingTypeTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectencodingtype"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Object/ObjectHashCheckTest.cc b/test/src/Object/ObjectHashCheckTest.cc index 25efa62..b57a485 100644 --- a/test/src/Object/ObjectHashCheckTest.cc +++ b/test/src/Object/ObjectHashCheckTest.cc @@ -36,7 +36,7 @@ class ObjectHashCheckTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objecthashcheck"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Object/ObjectProcessTest.cc b/test/src/Object/ObjectProcessTest.cc index 7313356..d60245d 100644 --- a/test/src/Object/ObjectProcessTest.cc +++ b/test/src/Object/ObjectProcessTest.cc @@ -37,7 +37,7 @@ class ObjectProcessTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectprocess"); ImageFilePath = Config::GetDataPath(); ImageFilePath.append("example.jpg"); @@ -205,7 +205,7 @@ TEST_F(ObjectProcessTest, ProcessObjectRequestTest) std::istreambuf_iterator isb(*gOutcome.result().Content()), end; std::string json_str = std::string(isb, end); - std::cout << json_str << std::endl; + //std::cout << json_str << std::endl; EXPECT_TRUE(json_str.find(key1) != std::string::npos); std::string imageInfo = GetOssImageObjectInfo(BucketName, key1); @@ -222,7 +222,7 @@ TEST_F(ObjectProcessTest, ProcessObjectRequestTest) std::istreambuf_iterator isb1(*gOutcome.result().Content()), end1; json_str = std::string(isb1, end1); - std::cout << json_str << std::endl; + //std::cout << json_str << std::endl; EXPECT_TRUE(json_str.find(key2) != std::string::npos); imageInfo = GetOssImageObjectInfo(BucketName, key2); EXPECT_TRUE(CompareImageInfo(imageInfo, ImageInfo)); diff --git a/test/src/Object/ObjectProgressTest .cc b/test/src/Object/ObjectProgressTest .cc index 2eafde5..5319fe6 100644 --- a/test/src/Object/ObjectProgressTest .cc +++ b/test/src/Object/ObjectProgressTest .cc @@ -36,7 +36,7 @@ class ObjectProgressTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectprogress"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Object/ObjectRequestPaymentTest.cc b/test/src/Object/ObjectRequestPaymentTest.cc index 241324b..3b160d8 100644 --- a/test/src/Object/ObjectRequestPaymentTest.cc +++ b/test/src/Object/ObjectRequestPaymentTest.cc @@ -45,7 +45,7 @@ class ObjectRequestPaymentTest : public ::testing::Test // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); PayerClient = std::make_shared(Config::Endpoint, Config::PayerAccessKeyId, Config::PayerAccessKeySecret, ClientConfiguration()); BucketName = TestUtils::GetBucketName("cpp-sdk-objectcopy1"); @@ -1314,7 +1314,7 @@ TEST_F(ObjectRequestPaymentTest, ProcessObjectRequestTest) std::istreambuf_iterator isb(*gOutcome.result().Content()), end; std::string json_str = std::string(isb, end); - std::cout << json_str << std::endl; + //std::cout << json_str << std::endl; EXPECT_TRUE(json_str.find(key1) != std::string::npos); std::string imageInfo = GetOssImageObjectInfo(BucketName, key1); diff --git a/test/src/Object/ObjectRestoreTest.cc b/test/src/Object/ObjectRestoreTest.cc index 0f45588..2660b18 100644 --- a/test/src/Object/ObjectRestoreTest.cc +++ b/test/src/Object/ObjectRestoreTest.cc @@ -38,7 +38,7 @@ class ObjectRestoreTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectrestore-standard"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); diff --git a/test/src/Object/ObjectSignedUrlTest.cc b/test/src/Object/ObjectSignedUrlTest.cc index 0f2ca2b..f3e870a 100644 --- a/test/src/Object/ObjectSignedUrlTest.cc +++ b/test/src/Object/ObjectSignedUrlTest.cc @@ -38,7 +38,7 @@ class ObjectSignedUrlTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectsignedurl"); Client->CreateBucket(CreateBucketRequest(BucketName)); } @@ -139,7 +139,13 @@ TEST_F(ObjectSignedUrlTest, GetPreSignedUriDefaultNegativeTest) auto gOutcome = Client->GetObjectByUrl(urlOutcome.result()); EXPECT_EQ(gOutcome.isSuccess(), false); - EXPECT_STREQ(gOutcome.error().Code().c_str(), "AccessDenied"); + // v1 + auto url = urlOutcome.result(); + if (url.find("x-oss-date=") == url.npos) { + EXPECT_STREQ(gOutcome.error().Code().c_str(), "AccessDenied"); + } else { + EXPECT_STREQ(gOutcome.error().Code().c_str(), "AuthorizationArgumentError"); + } } TEST_F(ObjectSignedUrlTest, GetPreSignedUriDefaultPositiveTest) @@ -429,7 +435,12 @@ TEST_F(ObjectSignedUrlTest, PutPreSignedUriDefaultNegativeTest) auto pOutcome = Client->PutObjectByUrl(urlOutcome.result(), content); EXPECT_EQ(pOutcome.isSuccess(), false); - EXPECT_STREQ(pOutcome.error().Code().c_str(), "AccessDenied"); + auto url = urlOutcome.result(); + if (url.find("x-oss-date=") == url.npos) { + EXPECT_STREQ(pOutcome.error().Code().c_str(), "AccessDenied"); + } else { + EXPECT_STREQ(pOutcome.error().Code().c_str(), "AuthorizationArgumentError"); + } } TEST_F(ObjectSignedUrlTest, PutObjectWithPreSignedUriWithParameter) diff --git a/test/src/Object/ObjectSymlinkTest.cc b/test/src/Object/ObjectSymlinkTest.cc index 76519a8..4ac4bbd 100644 --- a/test/src/Object/ObjectSymlinkTest.cc +++ b/test/src/Object/ObjectSymlinkTest.cc @@ -38,7 +38,7 @@ class ObjectSymlinkTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectsymlink"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/Object/ObjectTaggingTest.cc b/test/src/Object/ObjectTaggingTest.cc index 2a78b2b..4fbde74 100644 --- a/test/src/Object/ObjectTaggingTest.cc +++ b/test/src/Object/ObjectTaggingTest.cc @@ -41,7 +41,7 @@ class ObjectTaggingTest : public ::testing::Test static void SetUpTestCase() { ClientConfiguration conf; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objecttagging"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/Object/ObjectTrafficLimitTest.cc b/test/src/Object/ObjectTrafficLimitTest.cc index 97556eb..57c815b 100644 --- a/test/src/Object/ObjectTrafficLimitTest.cc +++ b/test/src/Object/ObjectTrafficLimitTest.cc @@ -38,7 +38,7 @@ class ObjectTrafficLimitTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-object-traffic-limit"); auto outcome1 = Client->CreateBucket(CreateBucketRequest(BucketName)); BucketName1 = TestUtils::GetBucketName("cpp-sdk-object-copy-object"); diff --git a/test/src/Object/ObjectVersioningTest.cc b/test/src/Object/ObjectVersioningTest.cc index 70103ea..e84f6c8 100644 --- a/test/src/Object/ObjectVersioningTest.cc +++ b/test/src/Object/ObjectVersioningTest.cc @@ -37,7 +37,7 @@ class ObjectVersioningTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-objectversioning"); Client->CreateBucket(CreateBucketRequest(BucketName)); } @@ -1497,7 +1497,7 @@ TEST_F(ObjectVersioningTest, ProcessObjectWithVersioningEnableTest) TEST_F(ObjectVersioningTest, ObjectOperationWithoutVersioningTest) { - auto client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + auto client = TestUtils::GetOssClientDefault(); auto bucketName = BucketName; bucketName.append("-no"); client->CreateBucket(CreateBucketRequest(bucketName)); diff --git a/test/src/Object/SelectObjectTest.cc b/test/src/Object/SelectObjectTest.cc index c7efae4..92eb4d7 100644 --- a/test/src/Object/SelectObjectTest.cc +++ b/test/src/Object/SelectObjectTest.cc @@ -42,7 +42,7 @@ class SelectObjectTest : public ::testing::Test { ClientConfiguration conf; conf.enableCrc64 = false; - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-selectobject"); CreateBucketOutcome outCome = Client->CreateBucket(CreateBucketRequest(BucketName)); EXPECT_EQ(outCome.isSuccess(), true); diff --git a/test/src/Other/Crc64Test.cc b/test/src/Other/Crc64Test.cc index 2264b57..d8195f4 100644 --- a/test/src/Other/Crc64Test.cc +++ b/test/src/Other/Crc64Test.cc @@ -35,7 +35,7 @@ class Crc64Test : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-crctest"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Other/EndpointTest.cc b/test/src/Other/EndpointTest.cc index 3d6624a..3092f01 100644 --- a/test/src/Other/EndpointTest.cc +++ b/test/src/Other/EndpointTest.cc @@ -36,7 +36,7 @@ class EndpointTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-endpoint"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Other/HttpClientTest.cc b/test/src/Other/HttpClientTest.cc index 1b02bc7..a2795a1 100644 --- a/test/src/Other/HttpClientTest.cc +++ b/test/src/Other/HttpClientTest.cc @@ -51,7 +51,7 @@ class HttpClientTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-httpclienttest"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Other/LogTest.cc b/test/src/Other/LogTest.cc index da2c439..3e6a7a7 100644 --- a/test/src/Other/LogTest.cc +++ b/test/src/Other/LogTest.cc @@ -45,7 +45,7 @@ class LogTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); } // Tears down the stuff shared by all tests in this test case. diff --git a/test/src/Other/RateLimiterTest.cc b/test/src/Other/RateLimiterTest.cc index a7431ca..f98c7c1 100644 --- a/test/src/Other/RateLimiterTest.cc +++ b/test/src/Other/RateLimiterTest.cc @@ -40,7 +40,7 @@ class RateLimiterTest : public ::testing::Test { // Sets up the stuff shared by all tests in this test case. static void SetUpTestCase() { - Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + Client = TestUtils::GetOssClientDefault(); BucketName = TestUtils::GetBucketName("cpp-sdk-ratelimitertest"); Client->CreateBucket(CreateBucketRequest(BucketName)); } diff --git a/test/src/Other/UtilsFunctionTest.cc b/test/src/Other/UtilsFunctionTest.cc index c03bf7f..68a16e0 100644 --- a/test/src/Other/UtilsFunctionTest.cc +++ b/test/src/Other/UtilsFunctionTest.cc @@ -702,7 +702,7 @@ TEST_F(UtilsFunctionTest, UploadAndDownloadObject) // create client and bucket auto BucketName = TestUtils::GetBucketName("utils-function-bucket-test"); auto key = TestUtils::GetObjectKey("utils-function-object-test"); - std::shared_ptr Client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration()); + std::shared_ptr Client = TestUtils::GetOssClientDefault(); TestUtils::EnsureBucketExist(*Client, BucketName); // create local file diff --git a/test/src/Utils.cc b/test/src/Utils.cc index c2e8875..73b00ee 100644 --- a/test/src/Utils.cc +++ b/test/src/Utils.cc @@ -36,6 +36,7 @@ #include #include #include +#include "Config.h" #ifdef GetObject #undef GetObject @@ -106,6 +107,14 @@ std::string TestUtils::GetTargetFileName(const std::string &prefix) return ss.str(); } +std::shared_ptr TestUtils::GetOssClientDefault() +{ + auto conf = ClientConfiguration(); + conf.signatureVersion = SignatureVersionType::V1; + auto client = std::make_shared(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, conf); + client->SetRegion(Config::Region); + return client; +} bool TestUtils::BucketExists(const OssClient &client, const std::string &bucketName) { diff --git a/test/src/Utils.h b/test/src/Utils.h index e974f35..51845ba 100644 --- a/test/src/Utils.h +++ b/test/src/Utils.h @@ -32,6 +32,7 @@ class TestUtils static std::string GetObjectKey(const std::string& prefix); static std::string GetTargetFileName(const std::string& prefix); + static std::shared_ptr GetOssClientDefault(); static bool BucketExists(const OssClient &client, const std::string &prefix); static void EnsureBucketExist(const OssClient &client, const std::string &bucketName); static bool ObjectExists(const OssClient& client, const std::string& bucketName, const std::string& keyName);