Ejemplo n.º 1
0
        public async Task Agent_Processes_Signed_Encrypted_UserMessage_With_Static_ReceivingPMode()
        {
            await TestStaticReceive(
                StaticReceiveSettings,
                async (url, msh) =>
            {
                // Arrange
                string ebmsMessageId = $"user-{Guid.NewGuid()}";
                AS4Message m         = SignedEncryptedAS4UserMessage(msh, ebmsMessageId);

                // Act
                HttpResponseMessage response =
                    await StubSender.SendAS4Message(url, m);

                // Assert
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                var spy          = new DatabaseSpy(msh.GetConfiguration());
                InMessage actual = await PollUntilPresent(
                    () => spy.GetInMessageFor(im => im.EbmsMessageId == ebmsMessageId),
                    timeout: TimeSpan.FromSeconds(15));

                Assert.Equal(Operation.ToBeDelivered, actual.Operation);
                Assert.Equal(InStatus.Received, actual.Status.ToEnum <InStatus>());
                Assert.Equal(DefaultPModeId, actual.PModeId);
            });
        }
Ejemplo n.º 2
0
        public async Task ThenMultiHopSignalMessageIsToBeForwarded()
        {
            // Arrange
            SignalMessage signal = CreateMultihopSignalMessage(
                refToMessageId: "someusermessageid",
                pmodeId: "Forward_Push");

            // Act
            await StubSender.SendAS4Message(_receiveAgentUrl, AS4Message.Create(signal));

            // Assert
            InMessage inMessage = _databaseSpy.GetInMessageFor(m => m.EbmsMessageId == signal.MessageId);

            Assert.NotNull(inMessage);
            Assert.True(inMessage.Intermediary);
            Assert.Equal(Operation.ToBeForwarded, inMessage.Operation);

            Stream messageBody = await Registry.Instance
                                 .MessageBodyStore
                                 .LoadMessageBodyAsync(inMessage.MessageLocation);

            AS4Message savedMessage = await SerializerProvider.Default
                                      .Get(inMessage.ContentType)
                                      .DeserializeAsync(messageBody, inMessage.ContentType);

            Assert.NotNull(savedMessage.EnvelopeDocument.SelectSingleNode("//*[local-name()='RoutingInput']"));
        }
Ejemplo n.º 3
0
        private static async Task SubmitMessageToSubmitAgent(string submitMessage)
        {
            await StubSender.SendRequest(SubmitUrl, Encoding.UTF8.GetBytes(submitMessage), "application/soap+xml");

            // Wait a bit so that we're sure that the processing agent has picked up the message.
            await Task.Delay(3000);
        }
Ejemplo n.º 4
0
        public async Task OnInvalidReceipt_ExceptionIsLogged()
        {
            string userMessageId = Guid.NewGuid().ToString();

            var receiptString = Encoding.UTF8.GetString(receipt_with_invalid_signature).Replace("{{RefToMessageId}}", userMessageId);

            StoreToBeAckOutMessage(userMessageId, CreateSendingPMode());

            var response = await StubSender.SendRequest(_receiveAgentUrl, Encoding.UTF8.GetBytes(receiptString), "application/soap+xml");

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.Equal("text/plain", response.Content.Headers.ContentType.MediaType);

            var inMessage = _databaseSpy.GetInMessageFor(m => m.EbmsRefToMessageId == userMessageId);

            Assert.NotNull(inMessage);
            Assert.Equal(MessageType.Receipt, inMessage.EbmsMessageType);
            Assert.Equal(InStatus.Exception, inMessage.Status.ToEnum <InStatus>());

            var inExceptions = _databaseSpy.GetInExceptions(m => m.EbmsRefToMessageId == inMessage.EbmsMessageId);

            Assert.NotNull(inExceptions);
            Assert.NotEmpty(inExceptions);

            var outMessage = _databaseSpy.GetOutMessageFor(m => m.EbmsRefToMessageId == userMessageId);

            Assert.True(outMessage == null, "No OutMessage should be created for the received SignalMessage");
        }
Ejemplo n.º 5
0
        public async Task Agent_Returns_Error_When_ReceivingPMode_Cannot_Be_Found()
        {
            OverrideTransformerReceivingPModeSetting(
                StaticReceiveSettings,
                pmodeId: "non-existing-pmode-id");

            await TestStaticReceive(
                StaticReceiveSettings,
                async (url, _) =>
            {
                AS4Message userMessage = AS4Message.Create(new UserMessage("user-" + Guid.NewGuid()));

                // Act
                HttpResponseMessage response =
                    await StubSender.SendAS4Message(url, userMessage);

                // Assert
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                AS4Message error = await response.DeserializeToAS4Message();
                Assert.Collection(
                    error.MessageUnits,
                    m =>
                {
                    Assert.IsType <Error>(m);
                    var e = (Error)m;

                    Assert.Equal(
                        ErrorAlias.ProcessingModeMismatch,
                        e.ErrorLines.First().ShortDescription);
                });
            });
        }
Ejemplo n.º 6
0
            public async Task ThenAgentStoresOutMessageFoReceivedSubmitMessage()
            {
                // Arrange
                string fixture       = SubmitMessageFixture;
                var    submitMessage = AS4XmlSerializer.FromString <SubmitMessage>(fixture);

                Assert.True(submitMessage?.MessageInfo?.MessageId != null, "Send SubmitMessage hasn't got a MessageInfo.MessageId element");
                Assert.True(submitMessage?.Collaboration?.AgreementRef != null, "Send SubmitMessage hasn't got a Collaboration.AgreementRef element");

                // Act
                using (HttpResponseMessage response = await StubSender.SendRequest(HttpSubmitAgentUrl, Encoding.UTF8.GetBytes(fixture), "application/xml"))
                {
                    Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
                    Assert.True(String.IsNullOrWhiteSpace(response.Content.Headers.ContentType?.ToString()));
                }

                // Assert
                IConfig config  = _as4Msh.GetConfiguration();
                string  pmodeId = submitMessage.Collaboration.AgreementRef.PModeId;
                SendingProcessingMode usedSendingPMode = config.GetSendingPMode(pmodeId);

                Assert.True(usedSendingPMode.PushConfiguration?.Protocol != null, "SendingPMode for SubmitMessage hasn't got PushConfiguration.Protocol element");

                var        databaseSpy = new DatabaseSpy(config);
                OutMessage outMessage  = databaseSpy.GetOutMessageFor(
                    m => m.EbmsMessageId == submitMessage.MessageInfo.MessageId);

                Assert.True(outMessage != null, "No OutMessage was stored for send SubmitMessage");
                Assert.Equal(usedSendingPMode.PushConfiguration.Protocol.Url, outMessage.Url);
            }
Ejemplo n.º 7
0
        public async Task ThenInMessageOperationIsToBeForwarded()
        {
            const string messageId = "forwarding_message_id";

            var as4Message = AS4Message.Create(
                new UserMessage(
                    messageId,
                    new CollaborationInfo(
                        agreement: new AgreementReference(
                            value: "forwarding/agreement",
                            type: "forwarding",
                            // Make sure that the forwarding receiving pmode is used; therefore
                            // explicitly set the Id of the PMode that must be used by the receive-agent.
                            pmodeId: "Forward_Push"),
                        service: new Service(
                            value: "Forward_Push_Service",
                            type: "eu:europa:services"),
                        action: "Forward_Push_Action",
                        conversationId: "eu:europe:conversation")));

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, as4Message);

            // Assert
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            Assert.True(String.IsNullOrWhiteSpace(await response.Content.ReadAsStringAsync()));

            InMessage receivedUserMessage = _databaseSpy.GetInMessageFor(m => m.EbmsMessageId == messageId);

            Assert.NotNull(receivedUserMessage);
            Assert.Equal(Operation.ToBeForwarded, receivedUserMessage.Operation);
        }
Ejemplo n.º 8
0
        public async Task ReturnsErrorMessageWhenDecryptionCertificateCannotBeFound()
        {
            var userMessage = new UserMessage(
                Guid.NewGuid().ToString(),
                new CollaborationInfo(
                    agreement: new AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: "receiveagent-non_existing_decrypt_cert-pmode"),
                    service: new Service(
                        value: "errorhandling",
                        type: "as4.net:receive_agent:componenttest"),
                    action: "as4.net:receive_agent:decryption_failed",
                    conversationId: "as4.net:receive_agent:conversation"));

            var as4Message = CreateAS4MessageWithAttachment(userMessage);

            var encryptedMessage = AS4MessageUtils.EncryptWithCertificate(as4Message, new StubCertificateRepository().GetStubCertificate());

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, encryptedMessage);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var contentType = response.Content.Headers.ContentType.MediaType;
            var result      = await SerializerProvider.Default.Get(contentType)
                              .DeserializeAsync(await response.Content.ReadAsStreamAsync(), contentType);

            Assert.True(result.IsSignalMessage);

            var errorMessage = result.FirstSignalMessage as Error;

            Assert.NotNull(errorMessage);
            Assert.Equal(ErrorCode.Ebms0102, errorMessage.ErrorLines.First().ErrorCode);
        }
Ejemplo n.º 9
0
 private static async Task SubmitAnonymousPayload()
 {
     using (HttpResponseMessage response = await StubSender.SendRequest(HttpSubmitAgentUrl, payload, "image/jpg"))
     {
         Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
     }
 }
Ejemplo n.º 10
0
        public async Task ThenReceivedMultihopUserMessageIsSetAsIntermediaryAndForwarded()
        {
            // Arrange
            var userMessage = new UserMessage(
                "test-" + Guid.NewGuid(),
                new
                CollaborationInfo(
                    agreement: new AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: "Forward_Push_Multihop"),
                    service: new Service(
                        value: "Forward_Push_Multihop_Service",
                        type: "eu:europa:services"),
                    action: "Forward_Push_Multihop_Action",
                    conversationId: "eu:europe:conversation"));
            var multihopPMode = new SendingProcessingMode {
                MessagePackaging = { IsMultiHop = true }
            };
            AS4Message multihopMessage = AS4Message.Create(userMessage, multihopPMode);

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, multihopMessage);

            // Assert
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);

            InMessage inUserMessage = _databaseSpy.GetInMessageFor(m => m.EbmsMessageId == userMessage.MessageId);

            Assert.NotNull(inUserMessage);
            Assert.True(inUserMessage.Intermediary);
            Assert.Equal(Operation.ToBeForwarded, inUserMessage.Operation);
        }
Ejemplo n.º 11
0
        public async Task RespondsWithBadRequest_WhenInvalidMessageReceived()
        {
            // Act
            HttpResponseMessage response =
                await StubSender.SendRequest(PullSendUrl, Encoding.UTF8.GetBytes(pullsendagent_submit), "application/soap+xml");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Ejemplo n.º 12
0
        public async Task ReturnsEmptyMessageFromInvalidMessage_IfReceivePModeIsCallback()
        {
            // Act
            HttpResponseMessage response = await StubSender.SendRequest(_receiveAgentUrl, receiveagent_wrong_encrypted_message,
                                                                        "multipart/related; boundary=\"=-WoWSZIFF06iwFV8PHCZ0dg==\"; type=\"application/soap+xml\"; charset=\"utf-8\"");

            // Assert
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            Assert.Empty(await response.Content.ReadAsStringAsync());
        }
Ejemplo n.º 13
0
 public async Task Responds_With_BadRequest_When_Content_Is_Pdf()
 {
     using (HttpResponseMessage response =
                await StubSender.SendRequest(
                    HttpSubmitAgentUrl,
                    Properties.Resources.pdf_document,
                    "application/pdf"))
     {
         Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
     }
 }
Ejemplo n.º 14
0
 public async Task Responds_With_BadRequest_When_Content_Is_Empty()
 {
     using (HttpResponseMessage response =
                await StubSender.SendRequest(
                    HttpSubmitAgentUrl,
                    new byte[] { },
                    "application/xml"))
     {
         Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
     }
 }
Ejemplo n.º 15
0
        public async Task RespondsWithHttpForbidden_WhenReceivedPullRequestIsNotAllowed()
        {
            OverridePullAuthorizationMap(@".\config\componenttest-settings\security\pull_authorizationmap_notallowed_facts.xml");

            var pullRequest = CreatePullRequestWithMpc("componenttest-mpc");

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(PullSendUrl, pullRequest);

            // Assert
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
        }
Ejemplo n.º 16
0
        public async Task ThenAgentReturnsBadRequest_IfReceivedMessageIsNotAS4Message()
        {
            // Arrange
            byte[] content = Encoding.UTF8.GetBytes(Convert.ToBase64String(receiveagent_message));

            // Act
            HttpResponseMessage response = await StubSender.SendRequest(_receiveAgentUrl, content,
                                                                        "multipart/related; boundary=\"=-C3oBZDXCy4W2LpjPUhC4rw==\"; type=\"application/soap+xml\"; charset=\"utf-8\"");

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Agent_Correctly_Handles_Message_Which_Bypasses_Interceptor()
        {
            const string contentType =
                "multipart/related; boundary=\"=-GpNI15tekzCG48QM0jucBg==\"; type=\"application/soap+xml\"";

            HttpResponseMessage response = await StubSender.SendRequest(
                _receiveUrl,
                Properties.Resources.c3_minderreceiveagent_request,
                contentType);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Ejemplo n.º 18
0
        public async Task Received_Bundled_UserMessages_Should_Responds_With_Bundled_Receipts()
        {
            // Arrange
            var bundled = AS4Message.Create(
                new UserMessage(
                    $"user1-{Guid.NewGuid()}",
                    new CollaborationInfo(
                        new AgreementReference(
                            value: "http://agreements.europe.org/agreement",
                            pmodeId: "receive_bundled_message_pmode"))));

            bundled.AddMessageUnits(
                Enumerable.Range(2, 3)
                .Select(i => new UserMessage($"user{i}-{Guid.NewGuid()}")));

            bundled.Sign(new CalculateSignatureConfig(
                             Registry.Instance.CertificateRepository.GetCertificate(
                                 X509FindType.FindBySubjectName,
                                 "AccessPointA")));

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, bundled);

            // Assert
            AS4Message receipts = await response.DeserializeToAS4Message();

            int receiptCount     = receipts.MessageUnits.Count();
            int userMessageCount = bundled.MessageUnits.Count();

            Assert.True(
                receiptCount == userMessageCount,
                $"{userMessageCount} UserMessage should result in {receiptCount} Receipts");

            Assert.True(
                receipts.SignalMessages.Select(s => s.RefToMessageId).SequenceEqual(bundled.MessageIds),
                "All Receipts must reference the right UserMessages");

            Assert.All(
                receipts.MessageUnits,
                r => Assert.True(
                    Assert.IsType <Receipt>(r).NonRepudiationInformation != null,
                    $"Receipt for UserMessage {r.RefToMessageId} is not a Non-Repudiation Receipt"));

            foreach (string ebmsMessageId in bundled.MessageIds)
            {
                OutMessage entry = await PollUntilPresent(
                    () => _databaseSpy.GetOutMessageFor(m => m.EbmsRefToMessageId == ebmsMessageId),
                    TimeSpan.FromSeconds(20));

                Assert.Equal(MessageType.Receipt, entry.EbmsMessageType);
            }
        }
Ejemplo n.º 19
0
        public async Task Correctly_Verifies_Encrypted_And_Signed_Message_With_SecurityTokenReference(
            X509ReferenceType securityTokenReferenceType)
        {
            // Arrange
            var pdf        = new Attachment("pdf", new MemoryStream(pdf_document), "application/pdf");
            var xml        = new Attachment("xml", new MemoryStream(Encoding.UTF8.GetBytes("<Root>Don't modify me</Root>")), "application/xml");
            var as4Message = AS4Message.Create(
                new UserMessage(
                    $"user-{Guid.NewGuid()}",
                    new CollaborationInfo(
                        new AgreementReference("http://agreements.europa.org/agreement"),
                        new Service("getting:started", "org:europa:services"),
                        "eu:sample:03",
                        "eu:edelivery:as4:sampleconversation"),
                    new Party("Sender", new PartyId("org:eu:europa:as4:example:accesspoint:A")),
                    new Party("Receiver", new PartyId("org:eu:europa:as4:example:accesspoint:B")),
                    new[]
            {
                PartInfo.CreateFor(pdf),
                PartInfo.CreateFor(xml)
            },
                    Enumerable.Empty <MessageProperty>()));

            as4Message.AddAttachments(new[] { pdf, xml });
            as4Message.Sign(
                new CalculateSignatureConfig(
                    Registry.Instance.CertificateRepository.GetCertificate(
                        X509FindType.FindBySubjectName,
                        "AccessPointA"),
                    securityTokenReferenceType,
                    Constants.SignAlgorithms.Sha256,
                    Constants.HashFunctions.Sha256));

            as4Message.Encrypt(
                new KeyEncryptionConfiguration(
                    Registry.Instance.CertificateRepository.GetCertificate(
                        X509FindType.FindBySubjectName,
                        "AccessPointB")),
                DataEncryptionConfiguration.Default);

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(_receiveAgentUrl, as4Message);

            // Assert
            AS4Message message = await response.DeserializeToAS4Message();

            Assert.False(
                message.PrimaryMessageUnit is Error,
                (message.PrimaryMessageUnit as Error)?.FormatErrorLines());

            Assert.IsType <Receipt>(message.PrimaryMessageUnit);
        }
Ejemplo n.º 20
0
            public async Task ThenAgentRespondsWithErrorWhenSubmitFails()
            {
                // Wait a little bit to make sure we do not delete the DB to early; otherwise it is recreated.
                await Task.Delay(1500);

                File.Delete(@".\database\messages.db");

                using (var response = await StubSender.SendRequest(HttpSubmitAgentUrl, Encoding.UTF8.GetBytes(SubmitMessageFixture), "application/xml"))
                {
                    Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
                    Assert.False(String.IsNullOrWhiteSpace(await response.Content.ReadAsStringAsync()));
                }
            }
Ejemplo n.º 21
0
        public async Task PullSendAgentReturnsHttpOk_IfPullRequestIsAllowed()
        {
            OverridePullAuthorizationMap(@".\config\componenttest-settings\security\pull_authorizationmap_allowed_facts.xml");

            AS4Message pullRequest       = CreateAllowedPullRequest();
            AS4Message signedPullRequest = SignAS4MessageWithPullRequestCert(pullRequest);

            // Act
            HttpResponseMessage response = await StubSender.SendAS4Message(PullSendUrl, signedPullRequest);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Ejemplo n.º 22
0
        public async Task ThenAgentReturnsError_IfMessageHasNonExsistingAttachment()
        {
            // Arrange
            byte[] content = receiveagent_message_nonexist_attachment;

            // Act
            HttpResponseMessage response = await StubSender.SendRequest(_receiveAgentUrl, content,
                                                                        "multipart/related; boundary=\"=-C3oBZDXCy4W2LpjPUhC4rw==\"; type=\"application/soap+xml\"; charset=\"utf-8\"");

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            AS4Message as4Message = await response.DeserializeToAS4Message();

            Assert.IsType <Error>(as4Message.PrimaryMessageUnit);
        }
Ejemplo n.º 23
0
        private async Task TestDeliverRetryByBlockingDeliveryLocationFor(AS4Message as4Message, TimeSpan period)
        {
            string deliverLocation = DeliverMessageLocationOf(as4Message);

            CleanDirectoryAt(Path.GetDirectoryName(deliverLocation));

            using (WriteBlockingFileTo(deliverLocation))
            {
                await StubSender.SendAS4Message(_receiveAgentUrl, as4Message);

                // Assert
                // Blocks the delivery location for a period of time
                await Task.Delay(period);
            }
        }
Ejemplo n.º 24
0
            public async Task ThenDatabaseContainsInException()
            {
                var invalidSubmitMessage = GetInvalidSubmitMessage();

                using (var response = await StubSender.SendRequest(HttpSubmitAgentUrl, Encoding.UTF8.GetBytes(invalidSubmitMessage), "application/xml"))
                {
                    Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
                }

                var spy = new DatabaseSpy(_as4Msh.GetConfiguration());

                var loggedException = spy.GetInExceptions(x => String.IsNullOrWhiteSpace(x.EbmsRefToMessageId)).FirstOrDefault();

                Assert.NotNull(loggedException);
                Assert.NotNull(loggedException.MessageLocation);
            }
Ejemplo n.º 25
0
        public async Task TestPullRequestWithSpecifiedMpc()
        {
            // Arrange
            const string mpc = "http://as4.net.eu/mpc/2";

            await StoreToBeSentUserMessage(mpc);

            // Act
            HttpResponseMessage userMessageResponse = await StubSender.SendAS4Message(PullSendUrl, CreatePullRequestWithMpc(mpc));

            // Assert
            AS4Message as4Message = await userMessageResponse.DeserializeToAS4Message();

            Assert.True(as4Message.IsUserMessage, "AS4 Message isn't a User Message");
            Assert.Equal(mpc, as4Message.FirstUserMessage.Mpc);
        }
Ejemplo n.º 26
0
        private async Task <HttpResponseMessage> TestSendNRReceiptWith(string messageId, Func <int, int> selection)
        {
            // Arrange
            var nrrPMode = new SendingProcessingMode {
                Id = "verify-nrr", ReceiptHandling = { VerifyNRR = true }
            };
            X509Certificate2 cert = new StubCertificateRepository().GetStubCertificate();

            AS4Message signedUserMessage = SignedUserMessage(messageId, nrrPMode, cert);

            InsertRelatedSignedUserMessage(nrrPMode, signedUserMessage);

            AS4Message signedReceipt = SignedNRReceipt(cert, signedUserMessage, selection);

            // Act
            return(await StubSender.SendAS4Message(_receiveAgentUrl, signedReceipt));
        }
Ejemplo n.º 27
0
        public async Task Agent_Returns_BadRequest_When_Receiving_SignalMessage()
        {
            await TestStaticReceive(
                StaticReceiveSettings,
                async (url, _) =>
            {
                // Arrange
                AS4Message receipt = AS4Message.Create(
                    new Receipt($"receipt-{Guid.NewGuid()}", $"reftoid-{Guid.NewGuid()}"));

                // Act
                HttpResponseMessage response =
                    await StubSender.SendAS4Message(url, receipt);

                // Assert
                Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            });
        }
Ejemplo n.º 28
0
        public async Task ThenMultiHopSignalMessageThatHasReachedItsDestinationIsNotified()
        {
            // Arrange
            const string messageId    = "some-user-message-id";
            var          sendingPMode = new SendingProcessingMode
            {
                ReceiptHandling = new SendReceiptHandling
                {
                    NotifyMessageProducer = true,
                    NotifyMethod          = new Method
                    {
                        Type       = "FILE",
                        Parameters = new List <Parameter>
                        {
                            new Parameter
                            {
                                Name  = "Location",
                                Value = @".\messages\receipts"
                            }
                        }
                    }
                }
            };

            StoreToBeAckOutMessage(messageId, sendingPMode);

            SignalMessage signal = CreateMultihopSignalMessage(
                refToMessageId: messageId,
                pmodeId: "ComponentTest_ReceiveAgent_Sample1");

            // Act
            await StubSender.SendAS4Message(_receiveAgentUrl, AS4Message.Create(signal));

            // Assert
            var inMessage = _databaseSpy.GetInMessageFor(m => m.EbmsRefToMessageId == messageId);

            Assert.NotNull(inMessage);
            Assert.Equal(Operation.ToBeNotified, inMessage.Operation);

            var outMessage = _databaseSpy.GetOutMessageFor(m => m.EbmsMessageId == messageId);

            Assert.NotNull(outMessage);
            Assert.Equal(OutStatus.Ack, outMessage.Status.ToEnum <OutStatus>());
        }
Ejemplo n.º 29
0
        public async Task ThenRelatedUserMessageIsNotAcked()
        {
            // Arrange
            const string expectedId = "message-id";

            StoreToBeAckOutMessage(expectedId, CreateSendingPMode());

            AS4Message as4Message = CreateAS4ErrorMessage(expectedId);

            // Act
            var response = await StubSender.SendAS4Message(_receiveAgentUrl, as4Message);

            // Assert
            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            Assert.True(String.IsNullOrWhiteSpace(await response.Content.ReadAsStringAsync()), "An empty response was expected");

            AssertIfStatusOfOutMessageIs(expectedId, OutStatus.Nack);
            AssertIfInMessageExistsForSignalMessage(expectedId);
        }
Ejemplo n.º 30
0
        public async Task CanReceiveErrorSignalWithoutRefToMessageId()
        {
            var as4Message = AS4Message.Create(
                Error.FromErrorResult(
                    messageId: $"error-{Guid.NewGuid()}",
                    refToMessageId: null,
                    result: new ErrorResult("An Error occurred", ErrorAlias.NonApplicable)));

            string id = as4Message.GetPrimaryMessageId();

            var response = await StubSender.SendAS4Message(_receiveAgentUrl, as4Message);

            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            Assert.True(String.IsNullOrWhiteSpace(await response.Content.ReadAsStringAsync()));

            var inMessage = _databaseSpy.GetInMessageFor(m => m.EbmsMessageId == id);

            Assert.NotNull(inMessage);
            Assert.Equal(Operation.NotApplicable, inMessage.Operation);
        }