TEST(Common, SignRequestV4) { S3Credential cred = {"keyid/foo", "secret/bar"}; HTTPHeaders *h = new HTTPHeaders(); ASSERT_NE((void *)NULL, h); ASSERT_TRUE(h->Add(HOST, "iam.amazonaws.com")); ASSERT_TRUE(h->Add(X_AMZ_DATE, "20150830T123600Z")); ASSERT_TRUE(h->Add(X_AMZ_CONTENT_SHA256, "UNSIGNED-PAYLOAD")); SignRequestV4("GET", h, "us-east-1", "/where/ever", "?parameter1=whatever1¶meter2=whatever2", cred); EXPECT_STREQ( "AWS4-HMAC-SHA256 " "Credential=keyid/foo/20150830/us-east-1/s3/" "aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date," "Signature=" "9f500a13e81c2dc6cb47551e416b2734e401d7b7b8f7ae99b09bccc22b81132d", h->Get(AUTHORIZATION)); delete h; }
TEST(Common, SignRequestV4) { S3Credential cred = {"keyid/foo", "secret/bar", ""}; HTTPHeaders *h = new HTTPHeaders(); ASSERT_NE((void *)NULL, h); ASSERT_TRUE(h->Add(HOST, "iam.amazonaws.com")); ASSERT_TRUE(h->Add(X_AMZ_DATE, "20150830T123600Z")); ASSERT_TRUE(h->Add(X_AMZ_CONTENT_SHA256, "UNSIGNED-PAYLOAD")); SignRequestV4("GET", h, "us-east-1", "/where/ever", "parameter1=whatever1¶meter2=whatever2", cred); EXPECT_STREQ( "AWS4-HMAC-SHA256 " "Credential=keyid/foo/20150830/us-east-1/s3/" "aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date," "Signature=" "bb2410787ac51cc7c41b679378d2586a557188ce2017569f5fc94a9b9bb901f8", h->Get(AUTHORIZATION)); delete h; }
Response mockGet(const string& url, HTTPHeaders& headers) { string range = headers.Get(RANGE); size_t index = range.find("="); string rangeNumber = range.substr(index + 1); index = rangeNumber.find("-"); // stoi is not available in C++98, use sscanf as workaround. int begin, end; if (index > 0) { sscanf(rangeNumber.substr(0, index).c_str(), "%d", &begin); } else { begin = 0; } if (rangeNumber.empty()) { end = data.size(); } else { sscanf(rangeNumber.substr(index + 1).c_str(), "%d", &end); } vector<uint8_t> responseData(data.begin() + begin, data.begin() + end + 1); return Response(RESPONSE_OK, responseData); }