public async Task CanonicalRequestBuilderTest() { var signer = new AwsSigner(); var request = Helpers.CreateExampleRequest(); request.Headers.Add("DifficultContent", "This & That + Something = the rest"); var canonicalRequest = await signer.BuildCanonicalRequest(request); var expectedBuilder = new StringBuilder(); expectedBuilder.Append("GET\n"); expectedBuilder.Append("/\n"); expectedBuilder.Append("Action=ListUsers&Version=2010-05-08\n"); expectedBuilder.Append("content-type:application/x-www-form-urlencoded; charset=utf-8\n"); // The names should be lower cased and then ordered so DifficultContent should be second expectedBuilder.Append("difficultcontent:This & That + Something = the rest\n"); expectedBuilder.Append("host:iam.amazonaws.com\n"); expectedBuilder.Append("x-amz-date:20150830T123600Z\n"); expectedBuilder.Append("\n"); expectedBuilder.Append("content-type;difficultcontent;host;x-amz-date\n"); expectedBuilder.Append("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); var expected = expectedBuilder.ToString(); Assert.AreEqual(expected, canonicalRequest); }
public async Task CanonicalRequestCreatedHasherTest() { var signer = new AwsSigner(); var request = Helpers.CreateExampleRequest(); var inputBuilder = new StringBuilder(); inputBuilder.Append("GET\n"); inputBuilder.Append("/\n"); inputBuilder.Append("Action=ListUsers&Version=2010-05-08\n"); inputBuilder.Append("content-type:application/x-www-form-urlencoded; charset=utf-8\n"); inputBuilder.Append("host:iam.amazonaws.com\n"); inputBuilder.Append("x-amz-date:20150830T123600Z\n"); inputBuilder.Append("\n"); inputBuilder.Append("content-type;host;x-amz-date\n"); inputBuilder.Append("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); var canonicalRequest = await signer.BuildCanonicalRequest(request); Assert.AreEqual(inputBuilder.ToString(), canonicalRequest, "Request are not equal"); var output = signer.HashText(canonicalRequest); const string expected = "f536975d06c0309214f805bb90ccff089219ecd68b2577efef23edd43b7e1a59"; Assert.AreEqual(expected, output, "Hash content failed"); }