Skip to content

Commit d4cc101

Browse files
committed
update testcase.
1 parent f797825 commit d4cc101

File tree

6 files changed

+823
-815
lines changed

6 files changed

+823
-815
lines changed

test/src/Bucket/BucketInventoryConfigurationTest.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ class BucketInventoryConfigurationTest : public ::testing::Test {
3535
// Sets up the stuff shared by all tests in this test case.
3636
static void SetUpTestCase()
3737
{
38-
std::string endpoint = "http://oss-ap-southeast-2.aliyuncs.com";
39-
Client = std::make_shared<OssClient>(endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration());
38+
Client = std::make_shared<OssClient>(Config::Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration());
4039
BucketName = TestUtils::GetBucketName("cpp-sdk-inventory");
4140
DstBucketName = TestUtils::GetBucketName("cpp-sdk-inventory-dst");
4241
Client->CreateBucket(CreateBucketRequest(BucketName));
4342
Client->CreateBucket(CreateBucketRequest(DstBucketName));
44-
43+
auto content = TestUtils::GetRandomStream(10);
44+
PutObjectRequest request(BucketName, "kms-key", content);
45+
request.MetaData().addHeader("x-oss-server-side-encryption", "KMS");
46+
auto outcome = Client->PutObject(request);
47+
auto metaOutcome = Client->HeadObject(BucketName, "kms-key");
48+
KmsKeyId = metaOutcome.result().HttpMetaData()["x-oss-server-side-encryption-key-id"];
4549
}
4650

4751
// Tears down the stuff shared by all tests in this test case.
@@ -65,11 +69,13 @@ class BucketInventoryConfigurationTest : public ::testing::Test {
6569
static std::shared_ptr<OssClient> Client;
6670
static std::string BucketName;
6771
static std::string DstBucketName;
72+
static std::string KmsKeyId;
6873
};
6974

7075
std::shared_ptr<OssClient> BucketInventoryConfigurationTest::Client = nullptr;
7176
std::string BucketInventoryConfigurationTest::BucketName = "";
7277
std::string BucketInventoryConfigurationTest::DstBucketName = "";
78+
std::string BucketInventoryConfigurationTest::KmsKeyId = "";
7379

7480
TEST_F(BucketInventoryConfigurationTest, BucketInventoryConfigurationAllTest)
7581
{
@@ -84,7 +90,7 @@ TEST_F(BucketInventoryConfigurationTest, BucketInventoryConfigurationAllTest)
8490
dest.setRoleArn(Config::RamRoleArn);
8591
dest.setBucket(DstBucketName);
8692
dest.setPrefix("prefix1");
87-
dest.setEncryption(InventoryEncryption(InventorySSEKMS("keyId")));
93+
dest.setEncryption(InventoryEncryption(InventorySSEKMS(KmsKeyId)));
8894
conf.setDestination(dest);
8995

9096
conf.setSchedule(InventoryFrequency::Daily);
@@ -110,7 +116,7 @@ TEST_F(BucketInventoryConfigurationTest, BucketInventoryConfigurationAllTest)
110116
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Bucket(), DstBucketName);
111117
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Prefix(), "prefix1");
112118
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Encryption().hasSSEKMS(), true);
113-
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId(), "keyId");
119+
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId(), KmsKeyId);
114120
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Schedule(), InventoryFrequency::Daily);
115121
EXPECT_EQ(getOutcome.result().InventoryConfiguration().IncludedObjectVersions(), InventoryIncludedObjectVersions::All);
116122
EXPECT_EQ(getOutcome.result().InventoryConfiguration().OptionalFields().size(), 6U);
@@ -182,7 +188,7 @@ TEST_F(BucketInventoryConfigurationTest, BucketInventoryConfigurationWithoutFilt
182188
dest.setRoleArn(Config::RamRoleArn);
183189
dest.setBucket(DstBucketName);
184190
dest.setPrefix("prefix1");
185-
dest.setEncryption(InventoryEncryption(InventorySSEKMS("keyId")));
191+
dest.setEncryption(InventoryEncryption(InventorySSEKMS(KmsKeyId)));
186192
conf.setDestination(dest);
187193

188194
conf.setSchedule(InventoryFrequency::Daily);
@@ -208,7 +214,7 @@ TEST_F(BucketInventoryConfigurationTest, BucketInventoryConfigurationWithoutFilt
208214
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Bucket(), DstBucketName);
209215
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Prefix(), "prefix1");
210216
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Encryption().hasSSEKMS(), true);
211-
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId(), "keyId");
217+
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId(), KmsKeyId);
212218
EXPECT_EQ(getOutcome.result().InventoryConfiguration().Schedule(), InventoryFrequency::Daily);
213219
EXPECT_EQ(getOutcome.result().InventoryConfiguration().IncludedObjectVersions(), InventoryIncludedObjectVersions::All);
214220
EXPECT_EQ(getOutcome.result().InventoryConfiguration().OptionalFields().size(), 6U);
@@ -329,7 +335,7 @@ TEST_F(BucketInventoryConfigurationTest, ListBucketInventoryConfigurationTest)
329335
dest.setRoleArn(Config::RamRoleArn);
330336
dest.setBucket(DstBucketName);
331337
dest.setPrefix("prefix1");
332-
dest.setEncryption(InventoryEncryption(InventorySSEKMS("keyId")));
338+
dest.setEncryption(InventoryEncryption(InventorySSEKMS(KmsKeyId)));
333339
conf.setDestination(dest);
334340

335341
conf.setSchedule(InventoryFrequency::Daily);
@@ -366,7 +372,7 @@ TEST_F(BucketInventoryConfigurationTest, ListBucketInventoryConfigurationTest)
366372
EXPECT_EQ(conf.Destination().OSSBucketDestination().Bucket(), DstBucketName);
367373
EXPECT_EQ(conf.Destination().OSSBucketDestination().Prefix(), "prefix1");
368374
EXPECT_EQ(conf.Destination().OSSBucketDestination().Encryption().hasSSEKMS(), true);
369-
EXPECT_EQ(conf.Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId(), "keyId");
375+
EXPECT_EQ(conf.Destination().OSSBucketDestination().Encryption().SSEKMS().KeyId(), KmsKeyId);
370376
EXPECT_EQ(conf.Schedule(), InventoryFrequency::Daily);
371377
EXPECT_EQ(conf.IncludedObjectVersions(), InventoryIncludedObjectVersions::All);
372378
EXPECT_EQ(conf.OptionalFields().size(), ((j % 7)? 6U : 1U));
@@ -420,14 +426,14 @@ TEST_F(BucketInventoryConfigurationTest, BucketInventoryConfigurationNegativeTes
420426
EXPECT_EQ(getOutcome.isSuccess(), false);
421427
EXPECT_EQ(getOutcome.error().Code(), "NoSuchInventory");
422428

423-
auto delOutcome = Client->DeleteBucketInventoryConfiguration(DeleteBucketInventoryConfigurationRequest("not-exist-bucket", "not-exist-report-id"));
429+
auto delOutcome = Client->DeleteBucketInventoryConfiguration(DeleteBucketInventoryConfigurationRequest(BucketName + "-not-exist-bucket", "not-exist-report-id"));
424430
EXPECT_EQ(delOutcome.isSuccess(), false);
425431
EXPECT_EQ(delOutcome.error().Code(), "NoSuchBucket");
426432

427433
delOutcome = Client->DeleteBucketInventoryConfiguration(DeleteBucketInventoryConfigurationRequest(BucketName, "not-exist-report-id"));
428434
EXPECT_EQ(delOutcome.isSuccess(), true);
429435

430-
auto listOutcome = Client->ListBucketInventoryConfigurations(ListBucketInventoryConfigurationsRequest("not-exist-bucket"));
436+
auto listOutcome = Client->ListBucketInventoryConfigurations(ListBucketInventoryConfigurationsRequest(BucketName + "-not-exist-bucket"));
431437
EXPECT_EQ(listOutcome.isSuccess(), false);
432438
EXPECT_EQ(listOutcome.error().Code(), "NoSuchBucket");
433439
}

test/src/Bucket/BucketLifecycleSettingsTest.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ TEST_F(BucketLifecycleSettingsTest, LifecycleAdvancedSettingTest)
297297
rule.setID("StandardExpireRule-104");
298298
rule.setPrefix("test");
299299
rule.setStatus(RuleStatus::Enabled);
300-
rule.Expiration().setCreatedBeforeDate(TestUtils::GetUTCString(400, true));
300+
rule.Expiration().setCreatedBeforeDate(TestUtils::GetUTCString(-400, true));
301301
rule.AbortMultipartUpload().setCreatedBeforeDate(TestUtils::GetUTCString(400, true));
302302

303303
transition = LifeCycleTransition();
304-
transition.Expiration().setCreatedBeforeDate(TestUtils::GetUTCString(180, true));
304+
transition.Expiration().setCreatedBeforeDate(TestUtils::GetUTCString(-180, true));
305305
transition.setStorageClass(StorageClass::IA);
306306
rule.addTransition(transition);
307307

308-
transition.Expiration().setCreatedBeforeDate(TestUtils::GetUTCString(365, true));
308+
transition.Expiration().setCreatedBeforeDate(TestUtils::GetUTCString(-365, true));
309309
transition.setStorageClass(StorageClass::Archive);
310310
rule.addTransition(transition);
311311
EXPECT_TRUE(TestRule(rule));

test/src/Encryption/CryptoResumableObjectTest.cc

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
#include <gtest/gtest.h>
18-
#include <alibabacloud/oss/OssEncryptionClient.h>
18+
#include <alibabacloud/oss/OssEncryptionClient.h>
1919
#include <alibabacloud/oss/Const.h>
2020
#include "../Config.h"
2121
#include "../Utils.h"
@@ -41,39 +41,39 @@ class CryptoResumableObjectTest : public::testing::Test {
4141
// Sets up the stuff shared by all tests in this test case.
4242
static void SetUpTestCase()
4343
{
44-
PublicKey =
44+
PublicKey =
4545
"-----BEGIN RSA PUBLIC KEY-----\n"
4646
"MIGJAoGBALpUiB+w+r3v2Fgw0SgMbWl8bnzUVc3t3YbA89H13lrw7v6RUbL8+HGl\n"
4747
"s5YGoqD4lObG/sCQyaWd0B/XzOhjlSc1b53nyZhms84MGJ6nF2NQP+1gjY1ByDMK\n"
4848
"zeyVFFFvl9prlr6XpuJQlY0F/W4pbjLsk8Px4Qix5AoJbShElUu1AgMBAAE=\n"
49-
"-----END RSA PUBLIC KEY-----";
50-
51-
PrivateKey =
52-
"-----BEGIN RSA PRIVATE KEY-----\n"
53-
"MIICXgIBAAKBgQC6VIgfsPq979hYMNEoDG1pfG581FXN7d2GwPPR9d5a8O7+kVGy\n"
54-
"/PhxpbOWBqKg+JTmxv7AkMmlndAf18zoY5UnNW+d58mYZrPODBiepxdjUD/tYI2N\n"
55-
"QcgzCs3slRRRb5faa5a+l6biUJWNBf1uKW4y7JPD8eEIseQKCW0oRJVLtQIDAQAB\n"
56-
"AoGBAJrzWRAhuSLipeMRFZ5cV1B1rdwZKBHMUYCSTTC5amPuIJGKf4p9XI4F4kZM\n"
57-
"1klO72TK72dsAIS9rCoO59QJnCpG4CvLYlJ37wA2UbhQ1rBH5dpBD/tv3CUyfdtI\n"
58-
"9CLUsZR3DGBWXYwGG0KGMYPExe5Hq3PUH9+QmuO+lXqJO4IBAkEA6iLee6oBzu6v\n"
59-
"90zrr4YA9NNr+JvtplpISOiL/XzsU6WmdXjzsFLSsZCeaJKsfdzijYEceXY7zUNa\n"
60-
"0/qQh2BKoQJBAMu61rQ5wKtql2oR4ePTSm00/iHoIfdFnBNU+b8uuPXlfwU80OwJ\n"
61-
"Gbs0xBHe+dt4uT53QLci4KgnNkHS5lu4XJUCQQCisCvrvcuX4B6BNf+mbPSJKcci\n"
62-
"biaJqr4DeyKatoz36mhpw+uAH2yrWRPZEeGtayg4rvf8Jf2TuTOJi9eVWYFBAkEA\n"
63-
"uIPzyS81TQsxL6QajpjjI52HPXZcrPOis++Wco0Cf9LnA/tczSpA38iefAETEq94\n"
64-
"NxcSycsQ5br97QfyEsgbMQJANTZ/HyMowmDPIC+n9ExdLSrf4JydARSfntFbPsy1\n"
65-
"4oC6ciKpRdtAtAtiU8s9eAUSWi7xoaPJzjAHWbmGSHHckg==\n"
66-
"-----END RSA PRIVATE KEY-----";
67-
68-
Description["comment"] = "rsa test";
69-
Description["provider"] = "aliclould";
49+
"-----END RSA PUBLIC KEY-----";
50+
51+
PrivateKey =
52+
"-----BEGIN RSA PRIVATE KEY-----\n"
53+
"MIICXgIBAAKBgQC6VIgfsPq979hYMNEoDG1pfG581FXN7d2GwPPR9d5a8O7+kVGy\n"
54+
"/PhxpbOWBqKg+JTmxv7AkMmlndAf18zoY5UnNW+d58mYZrPODBiepxdjUD/tYI2N\n"
55+
"QcgzCs3slRRRb5faa5a+l6biUJWNBf1uKW4y7JPD8eEIseQKCW0oRJVLtQIDAQAB\n"
56+
"AoGBAJrzWRAhuSLipeMRFZ5cV1B1rdwZKBHMUYCSTTC5amPuIJGKf4p9XI4F4kZM\n"
57+
"1klO72TK72dsAIS9rCoO59QJnCpG4CvLYlJ37wA2UbhQ1rBH5dpBD/tv3CUyfdtI\n"
58+
"9CLUsZR3DGBWXYwGG0KGMYPExe5Hq3PUH9+QmuO+lXqJO4IBAkEA6iLee6oBzu6v\n"
59+
"90zrr4YA9NNr+JvtplpISOiL/XzsU6WmdXjzsFLSsZCeaJKsfdzijYEceXY7zUNa\n"
60+
"0/qQh2BKoQJBAMu61rQ5wKtql2oR4ePTSm00/iHoIfdFnBNU+b8uuPXlfwU80OwJ\n"
61+
"Gbs0xBHe+dt4uT53QLci4KgnNkHS5lu4XJUCQQCisCvrvcuX4B6BNf+mbPSJKcci\n"
62+
"biaJqr4DeyKatoz36mhpw+uAH2yrWRPZEeGtayg4rvf8Jf2TuTOJi9eVWYFBAkEA\n"
63+
"uIPzyS81TQsxL6QajpjjI52HPXZcrPOis++Wco0Cf9LnA/tczSpA38iefAETEq94\n"
64+
"NxcSycsQ5br97QfyEsgbMQJANTZ/HyMowmDPIC+n9ExdLSrf4JydARSfntFbPsy1\n"
65+
"4oC6ciKpRdtAtAtiU8s9eAUSWi7xoaPJzjAHWbmGSHHckg==\n"
66+
"-----END RSA PRIVATE KEY-----";
67+
68+
Description["comment"] = "rsa test";
69+
Description["provider"] = "aliclould";
7070
Endpoint = Config::Endpoint;
71-
Client = std::make_shared<OssEncryptionClient>(Endpoint, Config::AccessKeyId, Config::AccessKeySecret,
72-
ClientConfiguration(), std::make_shared<SimpleRSAEncryptionMaterials>(PublicKey, PrivateKey, Description),
73-
CryptoConfiguration());
74-
75-
UnEncryptionClient = std::make_shared<OssClient>(Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration());
76-
71+
Client = std::make_shared<OssEncryptionClient>(Endpoint, Config::AccessKeyId, Config::AccessKeySecret,
72+
ClientConfiguration(), std::make_shared<SimpleRSAEncryptionMaterials>(PublicKey, PrivateKey, Description),
73+
CryptoConfiguration());
74+
75+
UnEncryptionClient = std::make_shared<OssClient>(Endpoint, Config::AccessKeyId, Config::AccessKeySecret, ClientConfiguration());
76+
7777
BucketName = TestUtils::GetBucketName("cpp-sdk-crypto-resumableobject");
7878
Client->CreateBucket(CreateBucketRequest(BucketName));
7979
UploadPartFailedFlag = 1 << 30;
@@ -1049,8 +1049,8 @@ TEST_F(CryptoResumableObjectTest, UnnormalResumableDownloadWithNotExitsCheckpoin
10491049
auto outcome = Client->ResumableDownloadObject(request);
10501050
std::shared_ptr<std::iostream> content = nullptr;
10511051
outcome.result().setContent(content);
1052-
EXPECT_EQ(outcome.isSuccess(), true);
1053-
//EXPECT_EQ(outcome.error().Code(), "ValidateError");
1052+
EXPECT_EQ(outcome.error().Code(), "ValidateError");
1053+
EXPECT_EQ(outcome.isSuccess(), false);
10541054

10551055
RemoveFile(targetFile.append(".temp"));
10561056
RemoveFile(tmpFile);
@@ -1660,8 +1660,8 @@ TEST_F(CryptoResumableObjectTest, NormalResumableDwoanloadWithoutCRCCheckTest)
16601660
// download
16611661
ClientConfiguration conf;
16621662
conf.enableCrc64 = false;
1663-
auto client = std::make_shared<OssEncryptionClient>(Endpoint, Config::AccessKeyId, Config::AccessKeySecret,
1664-
ClientConfiguration(), std::make_shared<SimpleRSAEncryptionMaterials>(PublicKey, PrivateKey, Description),
1663+
auto client = std::make_shared<OssEncryptionClient>(Endpoint, Config::AccessKeyId, Config::AccessKeySecret,
1664+
ClientConfiguration(), std::make_shared<SimpleRSAEncryptionMaterials>(PublicKey, PrivateKey, Description),
16651665
CryptoConfiguration());
16661666

16671667
DownloadObjectRequest request(BucketName, sourceKey, targetKey);

test/src/Object/ObjectProcessTest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ObjectProcessTest : public ::testing::Test {
4242
ImageFilePath = Config::GetDataPath();
4343
ImageFilePath.append("example.jpg");
4444
Process = "image/resize,m_fixed,w_100,h_100";
45-
ImageInfo = "{\n \"FileSize\": {\"value\": \"3267\"},\n \"Format\": {\"value\": \"jpg\"},\n \"ImageHeight\": {\"value\": \"100\"},\n \"ImageWidth\": {\"value\": \"100\"},\n \"ResolutionUnit\": {\"value\": \"1\"},\n \"XResolution\": {\"value\": \"1/1\"},\n \"YResolution\": {\"value\": \"1/1\"}}";
45+
ImageInfo = "{\n \"FileSize\": {\"value\": \"3267\"},\n \"Format\": {\"value\": \"jpg\"},\n \"FrameCount\": {\"value\": \"1\"},\n \"ImageHeight\": {\"value\": \"100\"},\n \"ImageWidth\": {\"value\": \"100\"},\n \"ResolutionUnit\": {\"value\": \"1\"},\n \"XResolution\": {\"value\": \"1/1\"},\n \"YResolution\": {\"value\": \"1/1\"}}";
4646

4747
Client->CreateBucket(CreateBucketRequest(BucketName));
4848
}

test/src/Object/ObjectRequestPaymentTest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ TEST_F(ObjectRequestPaymentTest, ProcessObjectRequestTest)
12861286
std::string ImageFilePath = Config::GetDataPath();
12871287
ImageFilePath.append("example.jpg");
12881288
std::string Process = "image/resize,m_fixed,w_100,h_100";
1289-
std::string ImageInfo = "{\n \"FileSize\": {\"value\": \"3267\"},\n \"Format\": {\"value\": \"jpg\"},\n \"ImageHeight\": {\"value\": \"100\"},\n \"ImageWidth\": {\"value\": \"100\"},\n \"ResolutionUnit\": {\"value\": \"1\"},\n \"XResolution\": {\"value\": \"1/1\"},\n \"YResolution\": {\"value\": \"1/1\"}}";
1289+
std::string ImageInfo = "{\n \"FileSize\": {\"value\": \"3267\"},\n \"Format\": {\"value\": \"jpg\"},\n \"FrameCount\": {\"value\": \"1\"},\n \"ImageHeight\": {\"value\": \"100\"},\n \"ImageWidth\": {\"value\": \"100\"},\n \"ResolutionUnit\": {\"value\": \"1\"},\n \"XResolution\": {\"value\": \"1/1\"},\n \"YResolution\": {\"value\": \"1/1\"}}";
12901290

12911291
std::string key = TestUtils::GetObjectKey("ImageProcessBysetProcessAndSavetoTest");
12921292
std::string key1 = key;
@@ -1558,7 +1558,7 @@ TEST_F(ObjectRequestPaymentTest, SignUrlTest)
15581558
gOutcome = PayerClient->GeneratePresignedUrl(gRequest);
15591559
gurlOutcome = PayerClient->GetObjectByUrl(gOutcome.result());
15601560
EXPECT_EQ(gurlOutcome.isSuccess(), true);
1561-
std::istreambuf_iterator<char> isb(*gurlOutcome.result().Content().get()), end;
1561+
std::istreambuf_iterator<char> isb(*gurlOutcome.result().Content().get()), end;
15621562
std::string str(isb, end);
15631563
EXPECT_EQ(str, "hello world");
15641564
}

0 commit comments

Comments
 (0)