public void TestCanonicalizeResourcePath() { Assert.AreEqual("/", AWSSDKUtils.CanonicalizeResourcePath(null, null)); Assert.AreEqual("/", AWSSDKUtils.CanonicalizeResourcePath(null, string.Empty)); Assert.AreEqual("/", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://ec2.us-west-1.amazonaws.com"), null)); Assert.AreEqual("/", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://ec2.us-west-1.amazonaws.com"), string.Empty)); Assert.AreEqual("/custompath", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://customhost/custompath"), null)); Assert.AreEqual("/custompath", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://customhost/custompath"), string.Empty)); Assert.AreEqual( "/vx_folder/1.0%5Cdatafiles%5Cfile.json", AWSSDKUtils.CanonicalizeResourcePath(null, @"/vx_folder/1.0\datafiles\file.json")); Assert.AreEqual( "/vx_folder/1.0%5Cdatafiles%5Cfile.json", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://s3-eu-west-1.amazonaws.com/"), @"/vx_folder/1.0\datafiles\file.json")); Assert.AreEqual( "/custompath/vx_folder/1.0%5Cdatafiles%5Cfile.json", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://customhost/custompath"), @"/vx_folder/1.0\datafiles\file.json")); }
protected static string CanonicalizeRequest(Uri endpoint, string resourcePath, string httpMethod, IDictionary <string, string> sortedHeaders, string canonicalQueryString, string precomputedBodyHash) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("{0}\n", httpMethod); stringBuilder.AppendFormat("{0}\n", AWSSDKUtils.CanonicalizeResourcePath(endpoint, resourcePath)); stringBuilder.AppendFormat("{0}\n", canonicalQueryString); stringBuilder.AppendFormat("{0}\n", CanonicalizeHeaders(sortedHeaders)); stringBuilder.AppendFormat("{0}\n", CanonicalizeHeaderNames(sortedHeaders)); string value; if (precomputedBodyHash != null) { stringBuilder.Append(precomputedBodyHash); } else if (sortedHeaders.TryGetValue("X-Amz-Content-SHA256", out value)) { stringBuilder.Append(value); } return(stringBuilder.ToString()); }
public void TestCanonicalizeResourcePathDoubleEncoded() { Assert.AreEqual("/", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://ec2.us-west-1.amazonaws.com"), null, true)); Assert.AreEqual("/", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://ec2.us-west-1.amazonaws.com"), string.Empty, true)); Assert.AreEqual("/custompath", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://customhost/custompath"), null, true)); Assert.AreEqual("/custompath", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://customhost/custompath"), string.Empty, true)); // exception because the URI is necessary to decide whether or not to pre URL encode AssertExtensions.ExpectException(() => { AWSSDKUtils.CanonicalizeResourcePath(null, "doesn't matter", true); }, typeof(ArgumentNullException), "A non-null endpoint is necessary to decide whether or not to pre URL encode.\r\nParameter name: endpoint"); // should be single URL encoded because it's S3 Assert.AreEqual( "/vx_folder/1.0%5Cdatafiles%5Cfile.json", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://s3-eu-west-1.amazonaws.com/"), @"/vx_folder/1.0\datafiles\file.json", true)); // should be double URL encoded because it's not S3 Assert.AreEqual( "/custompath/vx_folder/1.0%255Cdatafiles%255Cfile.json", AWSSDKUtils.CanonicalizeResourcePath(new Uri("https://customhost/custompath"), @"/vx_folder/1.0\datafiles\file.json", true)); }