Ejemplo n.º 1
0
        public void WhenTheHeadersParameterIsNull_ProducesError()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("default-request", _now),
                Headers = null
            };

            Func <Task> act = () => Canonicalizer.Run(options);

            act.Should().Throw <Exception>();
        }
Ejemplo n.º 2
0
        public void WhenAHeaderIsSpecifiedInTheHeadersParameter_ButIsMissingFromTheMessage_ProducesError()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("basic-request", _now),
                Headers = "not-in-request"
            };

            Func <Task> act = () => Canonicalizer.Run(options);

            act.Should().Throw <Exception>();
        }
Ejemplo n.º 3
0
        public void ForCertainAlgorithms_ExpiresHeaderIsNotAllowedToBePartOfTheSignatureString(string algorithm, string type)
        {
            var options = new CanonicalizeOptions {
                Message   = HttpMessages.HttpMessageGenerator.GenerateMessage("created-" + type, _now),
                Headers   = "(expires)",
                Algorithm = algorithm
            };

            Func <Task> act = () => Canonicalizer.Run(options);

            act.Should().Throw <Exception>();
        }
Ejemplo n.º 4
0
        public static async Task <string> Run(CanonicalizeOptions options)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddHttpMessageSigning()
                                  .BuildServiceProvider();
            var requestSignerFactory = serviceProvider.GetRequiredService <IRequestSignerFactory>();

            string signingString = null;

            var signingSettings = new SigningSettings {
                SignatureAlgorithm  = new CustomSignatureAlgorithm(options.Algorithm ?? "hs2019"),
                EnableNonce         = false,
                DigestHashAlgorithm = default,
Ejemplo n.º 5
0
        public async Task ShouldCreateALowercasedListOfHeaderFields_SeparatorByANewLine_InOrderOfHeadersParameter()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("default-request", _now),
                Headers = "content-length,host,digest"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "content-length: 18\nhost: example.com\ndigest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=";

            actual.Should().Be(expected);
        }
Ejemplo n.º 6
0
        public async Task IgnoresHeaderNameCasing()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("ignore-case", _now),
                Headers = "content-length,host,digest"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "content-length: 18\nhost: example.com\ndigest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=";

            actual.Should().Be(expected);
        }
Ejemplo n.º 7
0
        public async Task ForMultiValueHeaders_ConcatenatesAllValues_SeparatedByAnASCIICommaAndASCIISpace()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("multi-value-header-request", _now),
                Headers = "Multi-value,host"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "multi-value: one, two\nhost: example.com";

            actual.Should().Be(expected);
        }
Ejemplo n.º 8
0
        public async Task AddsNewLineBetweenValues()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("default-request", _now),
                Headers = "digest,host"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "digest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=\nhost: example.com";

            actual.Should().Be(expected);
        }
Ejemplo n.º 9
0
        public void GivenAnExpirationValueThatIsNotAUnixTime_ProducesError()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("basic-request", _now),
                Headers = "(created)",
                Created = _now.ToUnixTimeSeconds().ToString(),
                Expires = "[not-an-integer]"
            };

            Func <Task> act = () => Canonicalizer.Run(options);

            act.Should().Throw <Exception>();
        }
Ejemplo n.º 10
0
        public async Task CreatesSignatureString()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("basic-request", _now),
                Headers = "date"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = $"date: {_now:R}";

            actual.Should().Be(expected);
        }
Ejemplo n.º 11
0
        public async Task GeneratesStringForRequestTargetAsMethodAndPath()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("basic-request", _now),
                Headers = "(request-target)"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "(request-target): get /basic/request";

            actual.Should().Be(expected);
        }
Ejemplo n.º 12
0
        public async Task ShouldLowercaseHeaderNames()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("basic-request", _now),
                Headers = "Connection"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "connection: keep-alive";

            actual.Should().Be(expected);
        }
Ejemplo n.º 13
0
        public async Task WhenTheHeaderValueIsAZeroLengthString_IncludesItAsAnASCIISpace()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("zero-length-header-request", _now),
                Headers = "zero"
            };

            var actual = await Canonicalizer.Run(options);

            var expected = "zero: ";

            actual.Should().Be(expected);
        }
Ejemplo n.º 14
0
        public async Task GivenAValidExpiresValue_ReturnsExpectedSignatureString()
        {
            var options = new CanonicalizeOptions {
                Message = HttpMessages.HttpMessageGenerator.GenerateMessage("basic-request", _now),
                Headers = "(expires)",
                Created = _now.ToUnixTimeSeconds().ToString(),
                Expires = _now.AddMinutes(5).ToUnixTimeSeconds().ToString()
            };

            var actual = await Canonicalizer.Run(options);

            var expected = $"(expires): {options.Expires}";

            actual.Should().Be(expected);
        }