예제 #1
0
        public async Task CreateSignature()
        {
            var          signer   = new AwsSigner();
            var          config   = Helpers.CreateExampleConfig();
            var          request  = Helpers.CreateExampleRequest();
            const string expected = "5d672d79c15b13162d9279b0855cfba6789a8edb4c82c400e06b5924a6f2b5d7";
            var          dateTime = DateTimeOffset.Parse("2015-08-30T12:36:00Z");

            var signingKey = signer.CreateSigningKey(config.Secret, dateTime, config.Region, config.Service);
            var signString = await signer.CreateSignString(config.Region, config.Service, request, dateTime);

            var result = signer.CreateSignature(signingKey, signString);

            Assert.AreEqual(expected, result, "Create signature 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");
        }
        public async Task SignRequest()
        {
            var signer          = new AwsSigner();
            var config          = Helpers.CreateExampleConfig();
            var expectedRequest = Helpers.CreateExampleRequest();
            var request         = Helpers.CreateExampleRequest();

            //Remove the X-Amz-Date header since the authorize method should do this
            request.Headers.Remove("X-Amz-Date");

            var expectedDateTime = DateTimeOffset.Parse("2015-08-30T12:36:00Z");
            await AwsSigner.SignRequest(config, request, expectedDateTime);

            var signature = await signer.CreateSignature(config, expectedRequest, expectedDateTime);

            var expectedScheme  = "AWS4-HMAC-SHA256";
            var expectedContent = $"Credential=AKIDEXAMPLE/{expectedDateTime:yyyyMMdd}/us-east-1/iam/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature={signature}";

            Assert.AreEqual(expectedScheme, request.Headers.Authorization.Scheme, "Authorization scheme does not match");
            Assert.AreEqual(expectedContent, request.Headers.Authorization.Parameter, "Authorization content does not match");
        }