Example #1
0
            public void IgnoresAdditionalSettings()
            {
                SetHeader(_request, "app1", "rsa-sha256", _nowEpoch.ToString(), _expiresEpoch.ToString(), "(request-target) date content-length", "xyz123==", "abc123", _options.Scheme);
                _request.Headers["Authorization"] = _request.Headers["Authorization"] + ",additional=true";

                SignatureParsingResult actual = null;
                Action act = () => actual = _sut.Parse(_request, _options);

                act.Should().NotThrow();

                var expected = new Signature {
                    KeyId     = new KeyId("app1"),
                    Algorithm = "rsa-sha256",
                    Created   = _now,
                    Expires   = _expires,
                    Headers   = new[] {
                        new HeaderName("(request-target)"),
                        new HeaderName("date"),
                        new HeaderName("content-length")
                    },
                    String = "xyz123==",
                    Nonce  = "abc123"
                };

                actual.As <SignatureParsingSuccess>().Signature.Should().BeEquivalentTo(expected);
                actual.IsSuccess.Should().BeTrue();
            }
Example #2
0
            public void WhenRequestHasAnAuthorizationHeaderWithoutParam_ReturnsFailure()
            {
                _request.Headers["Authorization"] = _options.Scheme + " ";

                SignatureParsingResult actual = null;
                Action act = () => actual = _sut.Parse(_request, _options);

                act.Should().NotThrow();
                actual.Should().BeAssignableTo <SignatureParsingFailure>();
                actual.IsSuccess.Should().BeFalse();
            }
Example #3
0
            public void WhenRequestHasAnAuthorizationHeaderForAnotherScheme_ReturnsFailure()
            {
                SetHeader(_request, "app1", "rsa-sha256", _nowEpoch.ToString(), _expiresEpoch.ToString(), "(request-target) date content-length", "xyz123==", "abc123", "SomethingElse");

                SignatureParsingResult actual = null;
                Action act = () => actual = _sut.Parse(_request, _options);

                act.Should().NotThrow();
                actual.Should().BeAssignableTo <SignatureParsingFailure>();
                actual.IsSuccess.Should().BeFalse();
            }
Example #4
0
            public void WhenRequestHasNoAuthorizationHeader_ReturnsFailure()
            {
                _request.Headers.Clear();

                SignatureParsingResult actual = null;
                Action act = () => actual = _sut.Parse(_request, _options);

                act.Should().NotThrow();
                actual.Should().BeAssignableTo <SignatureParsingFailure>();
                actual.IsSuccess.Should().BeFalse();
            }
Example #5
0
            public void GivenDuplicateSignature_ReturnsFailure()
            {
                SetHeader(_request, "app1", "rsa-sha256", _nowEpoch.ToString(), _expiresEpoch.ToString(), "(request-target) date content-length", "xyz123==", "abc123", _options.Scheme, "signature=\"xyz987==\"");

                SignatureParsingResult actual = null;
                Action act = () => actual = _sut.Parse(_request, _options);

                act.Should().NotThrow();
                actual.Should().BeAssignableTo <SignatureParsingFailure>();
                actual.IsSuccess.Should().BeFalse();
            }
Example #6
0
            public void WhenStringNotSpecified_ReturnsFailure()
            {
                SetHeader(_request, "app1", "rsa-sha256", _nowEpoch.ToString(), _expiresEpoch.ToString(), "(request-target) date content-length", null, "abc123", _options.Scheme);

                SignatureParsingResult actual = null;
                Action act = () => actual = _sut.Parse(_request, _options);

                act.Should().NotThrow();
                actual.Should().BeAssignableTo <SignatureParsingFailure>();
                actual.IsSuccess.Should().BeFalse();
            }