TEST(S3RESTfulService, GetWithWrongHeader) { HTTPHeaders headers; map<string, string> params; S3RESTfulService service; string url = "https://www.bing.com/"; headers.Add(HOST, url); headers.Add(CONTENTTYPE, "plain/text"); Response resp = service.get(url, headers, params); EXPECT_EQ(RESPONSE_ERROR, resp.getStatus()); }
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; }