示例#1
0
        public void CanonicalHeadersOrdinalCaseOrderedTest()
        {
            var signer       = new AwsSigner();
            var inputHeaders = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"),
                new KeyValuePair <string, string>("host", "iam.amazonaws.com"),
                new KeyValuePair <string, string>("X-AMZ-Date", "20150830T123600Z"),
                new KeyValuePair <string, string>("my-header1", "a  b  c"),
                new KeyValuePair <string, string>("My-header1", "\"a  b  c\"")
            };

            var expectedBuilder = new StringBuilder();

            expectedBuilder.Append("content-type:application/x-www-form-urlencoded; charset=utf-8\n");
            expectedBuilder.Append("my-header1:\"a b c\"\n");
            expectedBuilder.Append("x-amz-date:20150830T123600Z\n");
            expectedBuilder.Append("host:iam.amazonaws.com\n");
            expectedBuilder.Append("my-header1:a b c\n");
            var expected = expectedBuilder.ToString();

            var output = signer.BuildCanonicalHeaders(inputHeaders);

            Assert.AreEqual(expected, output, "Header builder failed");
        }
        public async Task CreateAuthorizationHeader()
        {
            var signer        = new AwsSigner();
            var config        = Helpers.CreateExampleConfig();
            var request       = Helpers.CreateExampleRequest();
            var dateTime      = DateTimeOffset.Parse("2015-08-30T12:36:00Z");
            var signedHeaders = signer.BuildSignedHeaders(signer.BuildCanonicalHeaders(request));

            const string expected  = "Credential=AKIDEXAMPLE/20150830/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=5d672d79c15b13162d9279b0855cfba6789a8edb4c82c400e06b5924a6f2b5d7";
            var          signature = await signer.CreateSignature(config, request, dateTime);

            var result = signer.CreateAuthorizationHeader(config.AccessId, dateTime, config.Region, config.Service, signedHeaders, signature);

            Assert.AreEqual(expected, result, "Authorization string creation failed");
        }
示例#3
0
        public void CanonicalHeadersFromNullContentTest()
        {
            var signer  = new AwsSigner();
            var request = Helpers.CreateExampleRequest();

            request.Content = null;
            request.Headers.Add("My-header1", "a  b  c");
            request.Headers.Add("My-header1", "\"a  b  c\"");

            var expectedBuilder = new StringBuilder();

            expectedBuilder.Append("host:iam.amazonaws.com\n");
            expectedBuilder.Append("my-header1:a b c\n");
            expectedBuilder.Append("my-header1:\"a b c\"\n");
            expectedBuilder.Append("x-amz-date:20150830T123600Z\n");
            var expected = expectedBuilder.ToString();

            var output = signer.BuildCanonicalHeaders(request);

            Assert.AreEqual(expected, output, "Header builder failed");
        }