Пример #1
0
        public void AuthorizationHeaderValueForAwsS3ShouldBeCalculatedCorrectly1()
        {
            using (var client = new RavenAwsS3Client("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "us-east-1"))
            {
                var date = new DateTime(2013, 5, 24);

                var stream      = new MemoryStream(Encoding.UTF8.GetBytes("Welcome to Amazon S3."));
                var payloadHash = RavenAwsHelper.CalculatePayloadHash(stream);

                Assert.Equal("44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072", payloadHash);

                var url     = client.GetUrl("examplebucket") + "/" + "test%24file.text";
                var headers = new Dictionary <string, string>
                {
                    { "x-amz-date", RavenAwsHelper.ConvertToString(date) },
                    { "x-amz-content-sha256", payloadHash },
                    { "x-amz-storage-class", "REDUCED_REDUNDANCY" },
                    { "Date", date.ToString("R") },
                    { "Host", "examplebucket.s3.amazonaws.com" }
                };

                var auth = client.CalculateAuthorizationHeaderValue("PUT", url, date, headers);

                Assert.Equal("AWS4-HMAC-SHA256", auth.Scheme);
                Assert.Equal("Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request,SignedHeaders=date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class,Signature=98ad721746da40c64f1a55b78f14c238d841ea1380cd77a1b5971af0ece108bd", auth.Parameter);
            }
        }
Пример #2
0
        public void AuthorizationHeaderValueForAwsS3ShouldBeCalculatedCorrectly2()
        {
            using (var client = new RavenAwsS3Client("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "us-east-1", "examplebucket"))
            {
                var date        = new DateTime(2013, 5, 24);
                var payloadHash = RavenAwsHelper.CalculatePayloadHash(null);

                Assert.Equal("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", payloadHash);

                var url     = client.GetUrl() + "/test.txt";
                var headers = new Dictionary <string, string>
                {
                    { "x-amz-date", RavenAwsHelper.ConvertToString(date) },
                    { "x-amz-content-sha256", payloadHash },
                    { "Date", date.ToString("R") },
                    { "Host", "s3.amazonaws.com" },
                    { "Range", "bytes=0-9" }
                };

                var auth = client.CalculateAuthorizationHeaderValue(HttpMethods.Get, url, date, headers);

                Assert.Equal("AWS4-HMAC-SHA256", auth.Scheme);
                Assert.Equal("Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request,SignedHeaders=host;range;x-amz-content-sha256;x-amz-date,Signature=819484c483cfb97d16522b1ac156f87e61677cc8f1f2545c799650ef178f4aa8", auth.Parameter);
            }
        }
Пример #3
0
        public void AuthorizationHeaderValueForAwsS3ShouldBeCalculatedCorrectly2()
        {
            using (var client = new RavenAwsS3Client("AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "us-east-1"))
            {
                var date        = new DateTime(2013, 5, 24);
                var payloadHash = RavenAwsHelper.CalculatePayloadHash(null);

                Assert.Equal("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", payloadHash);

                var url     = client.GetUrl("examplebucket") + "/" + "test.txt";
                var headers = new Dictionary <string, string>
                {
                    { "x-amz-date", RavenAwsHelper.ConvertToString(date) },
                    { "x-amz-content-sha256", payloadHash },
                    { "Date", date.ToString("R") },
                    { "Host", "examplebucket.s3.amazonaws.com" },
                    { "Range", "bytes=0-9" }
                };

                var auth = client.CalculateAuthorizationHeaderValue("GET", url, date, headers);

                Assert.Equal("AWS4-HMAC-SHA256", auth.Scheme);
                Assert.Equal("Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request,SignedHeaders=host;range;x-amz-content-sha256;x-amz-date,Signature=f0e8bdb87c964420e857bd35b5d6ed310bd44f0170aba48dd91039c6036bdb41", auth.Parameter);
            }
        }
Пример #4
0
        public void AuthorizationHeaderValueForAwsS3ShouldBeCalculatedCorrectly1()
        {
            var s3Settings = new S3Settings
            {
                AwsAccessKey  = "AKIAIOSFODNN7EXAMPLE",
                AwsSecretKey  = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
                AwsRegionName = "us-east-1",
                BucketName    = "examplebucket"
            };

            using (var client = new RavenAwsS3Client(s3Settings))
            {
                var date = new DateTime(2013, 5, 24);

                var stream      = new MemoryStream(Encoding.UTF8.GetBytes("Welcome to Amazon S3."));
                var payloadHash = RavenAwsHelper.CalculatePayloadHash(stream);

                Assert.Equal("44ce7dd67c959e0d3524ffac1771dfbba87d2b6b4b4e99e42034a8b803f8b072", payloadHash);

                var url     = client.GetUrl() + "/test%24file.text";
                var headers = new Dictionary <string, string>
                {
                    { "x-amz-date", RavenAwsHelper.ConvertToString(date) },
                    { "x-amz-content-sha256", payloadHash },
                    { "x-amz-storage-class", "REDUCED_REDUNDANCY" },
                    { "Date", date.ToString("R") },
                    { "Host", "s3.amazonaws.com" }
                };

                var auth = client.CalculateAuthorizationHeaderValue(HttpMethods.Put, url, date, headers);

                Assert.Equal("AWS4-HMAC-SHA256", auth.Scheme);
                Assert.Equal("Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request,SignedHeaders=date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class,Signature=d2dd2e48b10d2cb89c271a6464d0748686c158b5fde44e8d83936fd9b30b5c4c", auth.Parameter);
            }
        }