Beispiel #1
0
        public void Parse_WithInvalidPublicKey()
        {
            Dictionary <string, string> sampleNotification = gateway.WebhookTesting.SampleNotification(WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id");
            InvalidSignatureException   exception          = Assert.Throws <InvalidSignatureException>(() => gateway.WebhookNotification.Parse("bad" + sampleNotification["bt_signature"], sampleNotification["bt_payload"]));

            Assert.AreEqual(exception.Message, "no matching public key");
        }
Beispiel #2
0
        public void Parse_WithChangedPayload()
        {
            Dictionary <string, string> sampleNotification = gateway.WebhookTesting.SampleNotification(WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id");
            InvalidSignatureException   exception          = Assert.Throws <InvalidSignatureException>(() => gateway.WebhookNotification.Parse(sampleNotification["bt_signature"], "bad" + sampleNotification["bt_payload"]));

            Assert.AreEqual(exception.Message, "signature does not match payload - one has been modified");
        }
Beispiel #3
0
        public void Parse_AllowsAllValidChars()
        {
            Dictionary <string, string> sampleNotification = gateway.WebhookTesting.SampleNotification(WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id");
            InvalidSignatureException   exception          = Assert.Throws <InvalidSignatureException>(() => gateway.WebhookNotification.Parse(sampleNotification["bt_signature"], "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+=/\n"));

            Assert.AreEqual(exception.Message, "signature does not match payload - one has been modified");
        }
Beispiel #4
0
        public void Parse_WithInvalidCharactersInPayload()
        {
            Dictionary <string, string> sampleNotification = gateway.WebhookTesting.SampleNotification(WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id");
            InvalidSignatureException   exception          = Assert.Throws <InvalidSignatureException>(() => gateway.WebhookNotification.Parse(sampleNotification["bt_signature"], "^& bad ,* chars @!" + sampleNotification["bt_payload"]));

            Assert.AreEqual(exception.Message, "payload contains illegal characters");
        }
        public void InvalidSignatureException_StringCtor()
        {
            var msg     = "Message!";
            var subject = new InvalidSignatureException(msg);

            subject.Message.Should().Be(msg);
        }
        public void InvalidSignatureException_InnerExceptionCtor()
        {
            var inner = new Exception("inner");
            var msg   = "Message!";

            var subject = new InvalidSignatureException(msg, inner);

            subject.Message.Should().Be(msg);
            subject.InnerException.Should().Be(inner);
        }
Beispiel #7
0
            public async Task WhenSignatureCannotBeParsed_ReturnsFailureResult()
            {
                var failure = new InvalidSignatureException("Cannot parse signature.");

                A.CallTo(() => _signatureParser.Parse(_httpRequest, _options))
                .Throws(failure);

                A.CallTo(() => _signatureVerifier.VerifySignature(A <HttpRequestForSigning> ._, A <Signature> ._, A <Client> ._))
                .Returns((SignatureVerificationFailure)null);

                var actual = await _sut.VerifySignature(_httpRequest, _options);

                actual.Should().BeAssignableTo <RequestSignatureVerificationResultFailure>();
                actual.As <RequestSignatureVerificationResultFailure>().IsSuccess.Should().BeFalse();
                actual.As <RequestSignatureVerificationResultFailure>().Failure.Code.Should().Be("INVALID_SIGNATURE");
                actual.As <RequestSignatureVerificationResultFailure>().Failure.Exception.Should().Be(failure);
            }
Beispiel #8
0
        public async Task ExtractFileTamperedAsync()
        {
            var certPass          = GetTestCertPassword();
            X509Certificate2 cert = TemplatePackage.LoadCert(@"Packaging\TestCert.pfx", certPass);

            var inFile        = @"Packaging\SampleContent.txt";
            var outFile       = @"Packaging\ToExtract.package";
            var extractionDir = "SubDir";

            await TemplatePackage.PackAndSignAsync(inFile, outFile, cert, MediaTypeNames.Text.Plain);

            ModifyContent(outFile, "SampleContent.txt");

            InvalidSignatureException ex = await Assert.ThrowsAsync <InvalidSignatureException>(async() =>
            {
                await TemplatePackage.ExtractAsync(outFile, extractionDir);
            });

            File.Delete(outFile);
            Directory.Delete(extractionDir, true);
        }
        public void Serialize()
        {
            var formatter = new BinaryFormatter();

            using var ms = new MemoryStream();
            var pending = new PendingActivationState(
                new byte[] { 0x00 },
                new PrivateKey().PublicKey
                );
            var exc = new InvalidSignatureException(
                pending,
                new byte[] { 0x01 }
                );

            formatter.Serialize(ms, exc);
            ms.Seek(0, SeekOrigin.Begin);
            var deserialized =
                (InvalidSignatureException)formatter.Deserialize(ms);

            Assert.Equal(exc.Pending.Serialize(), deserialized.Pending.Serialize());
            Assert.Equal(exc.Signature, deserialized.Signature);
        }
Beispiel #10
0
        public void Verify_ThrowsErrorOnNullPayload()
        {
            InvalidSignatureException exception = Assert.Throws <InvalidSignatureException>(() => gateway.WebhookNotification.Parse("signature", null));

            Assert.AreEqual(exception.Message, "payload cannot be null");
        }