예제 #1
0
        public void Asynchronous_Receive_CertificateSignError()
        {
            Exception receiveException = null;

            Client = new MessagingClient(Settings, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new SignThenEncryptMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Client.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            Server = new MessagingServer(Settings, Logger, LoggerFactory, CollaborationRegistry, AddressRegistry)
            {
                DefaultMessageProtection    = new SignThenEncryptMessageProtection(), // disable protection for most tests
                DefaultCertificateValidator = CertificateValidator
            };
            Server.ServiceBus.RegisterAlternateMessagingFactory(MockFactory);

            CollaborationRegistry.SetupFindAgreementForCounterparty(i =>
            {
                var file = Path.Combine("Files", $"CPA_{i}_ChangedSignedCertificate.xml");
                return(File.Exists(file) == false ? null : File.ReadAllText(file));
            });

            RunAsynchronousReceive(
                postValidation: () => {
                Assert.IsTrue(_startingCalled);
                Assert.IsFalse(_receivedCalled);
                Assert.IsTrue(_completedCalled);
                var error = MockLoggerProvider.FindEntry(EventIds.RemoteCertificate);
                Assert.IsTrue(error.Message
                              .Contains($"{TestCertificates.HelsenorgePrivateSigntature.Thumbprint}"));
                Assert.IsTrue(error.Message
                              .Contains($"{TestCertificates.HelsenorgePrivateSigntature.NotBefore}"));
                var signingException = receiveException as CertificateException;
                Assert.IsNotNull(signingException);
                Assert.IsNotNull(signingException.Payload);
            },
                wait: () => _completedCalled,
                received: (m) => { },
                messageModification: (m) => { },
                handledException: ((m, e) =>
            {
                Server.Stop(TimeSpan.FromSeconds(10));
                _handledExceptionCalled = true;
                _completedCalled = true;
                receiveException = e;
            }),
                messageProtected: true);
        }
예제 #2
0
 /// <summary>
 /// Stop the server.
 /// </summary>
 public void Stop()
 {
     _server.Stop();
 }