public Property Only_Overdue_Entries_Are_Deleted() { return(Prop.ForAll( SupportedProviderSettings(), Arb.Default.PositiveInt(), Arb.Default.PositiveInt(), (specificSettings, insertion, retention) => { // Arrange int retentionDays = retention.Get; OverrideWithSpecificSettings(specificSettings, retentionDays: retentionDays); int insertionDays = insertion.Get; string id = GenId(); IConfig config = EnsureLocalConfigPointsToCreatedDatastore(); var spy = new DatabaseSpy(config); var insertionTime = DateTimeOffset.Now.Add(TimeSpan.FromDays(-insertionDays)); spy.InsertOutException(CreateOutException(id, insertionTime)); // Act ExerciseStartCleaning(); // Assert bool hasEntries = spy.GetOutExceptions(id).Any(); return (hasEntries == insertionDays < retentionDays) .When(insertionDays != retentionDays) .Classify(hasEntries, "OutException isn't deleted") .Classify(!hasEntries, "OutException is deleted"); })); }
public async Task Deliver_Message_Only_When_Referenced_Payloads_Are_Delivered() { AS4Message as4Message = await CreateAS4MessageFrom(deliveragent_message); string deliverLocation = DeliverPayloadLocationOf(as4Message.Attachments.First()); CleanDirectoryAt(Path.GetDirectoryName(deliverLocation)); // Act IPMode pmode = CreateReceivedPMode( deliverMessageLocation: DeliveryRoot, deliverPayloadLocation: @"%# \ (+_O) / -> Not a valid path"); InMessage inMessage = CreateInMessageRepresentingUserMessage(as4Message.GetPrimaryMessageId(), as4Message, pmode); await InsertInMessageAsync(inMessage); // Assert var spy = DatabaseSpy.Create(_as4Msh.GetConfiguration()); InMessage actual = await PollUntilPresent( () => spy.GetInMessageFor(im => im.Id == inMessage.Id && im.Status == InStatus.Exception.ToString()), TimeSpan.FromSeconds(10)); Assert.Empty(Directory.EnumerateFiles(DeliveryRoot)); Assert.Equal(InStatus.Exception, actual.Status.ToEnum <InStatus>()); Assert.Equal(Operation.DeadLettered, actual.Operation); }
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); }
public Property Only_Awnsered_UserMessages_Are_Deleted() { return(Prop.ForAll( SupportedProviderSettings(), Arb.From <OutStatus>(), (specificSettings, status) => { // Arrange OverrideWithSpecificSettings(specificSettings); string id = GenId(); OutMessage m = CreateOutMessage( id, insertionTime: DayBeforeYesterday, type: MessageType.UserMessage); m.SetStatus(status); IConfig config = EnsureLocalConfigPointsToCreatedDatastore(); var spy = new DatabaseSpy(config); spy.InsertOutMessage(m); // Act ExerciseStartCleaning(); // Assert bool isCleaned = !spy.GetOutMessages(id).Any(); bool isAckOrNack = status == OutStatus.Ack || status == OutStatus.Nack; return isCleaned == isAckOrNack; })); }
public Property Only_Entries_With_Allowed_Operations_Are_Deleted() { return(Prop.ForAll( SupportedProviderSettings(), Arb.From <Operation>(), (specificSettings, operation) => { // Arrange OverrideWithSpecificSettings(specificSettings); string id = GenId(); InMessage m = CreateInMessage(id, insertionTime: DayBeforeYesterday); m.Operation = operation; IConfig config = EnsureLocalConfigPointsToCreatedDatastore(); var spy = new DatabaseSpy(config); spy.InsertInMessage(m); // Act ExerciseStartCleaning(); // Assert bool hasEntries = spy.GetInMessages(id).Any(); string description = $"InMessage {(hasEntries ? "isn't" : "is")} deleted, with Operation: {operation}"; return (hasEntries == !AllowedOperations.Contains(operation)).Collect(description); })); }
public void MessageOlderThanRetentionDateWillBeDeleted(string specificSettings) { // Arrange: Insert a "retired" OutMessage with a referenced Reception Awareness. OverrideWithSpecificSettings(specificSettings); IConfig config = EnsureLocalConfigPointsToCreatedDatastore(); string outReferenceId = GenId(), outStandaloneId = GenId(), inMessageId = GenId(), outExceptionId = GenId(), inExceptionId = GenId(); var spy = new DatabaseSpy(config); OutMessage om = CreateOutMessage(outReferenceId, insertionTime: DayBeforeYesterday, type: MessageType.Error); spy.InsertOutMessage(om); spy.InsertRetryReliability(RetryReliability.CreateForOutMessage(om.Id, maxRetryCount: 0, retryInterval: default(TimeSpan), type: RetryType.Send)); spy.InsertOutMessage(CreateOutMessage(outStandaloneId, insertionTime: DayBeforeYesterday, type: MessageType.Receipt)); spy.InsertInMessage(CreateInMessage(inMessageId, DayBeforeYesterday)); spy.InsertOutException(CreateOutException(outExceptionId, DayBeforeYesterday)); spy.InsertInException(CreateInException(inExceptionId, DayBeforeYesterday)); // Act: AS4.NET Component will start the Clean Up Agent. ExerciseStartCleaning(); // Assert: No OutMessage or Reception Awareness entries must be found for a given EbmsMessageId. Assert.Empty(spy.GetOutMessages(outReferenceId, outStandaloneId)); Assert.Null(spy.GetRetryReliabilityFor(r => r.RefToOutMessageId == om.Id)); Assert.Empty(spy.GetInMessages(inMessageId)); Assert.Empty(spy.GetOutExceptions(outExceptionId)); Assert.Empty(spy.GetInExceptions(inExceptionId)); }
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); }); }
public async Task OutMessage_Is_To_Notified_When_Retry_Happen_Withing_Allowed_MaxRetry( HttpStatusCode secondAttemptStatusCode, Operation expected) { await TestComponentWithSettings( "outmessage_notify_reliability_settings.xml", async (settings, as4Msh) => { // Arrange const string url = "http://localhost:7071/business/outmessage/"; string ebmsMessageId = $"error-{Guid.NewGuid()}"; var store = new AS4MessageBodyFileStore(); var om = new OutMessage(ebmsMessageId) { ContentType = Constants.ContentTypes.Soap, MessageLocation = store.SaveAS4Message( as4Msh.GetConfiguration().InMessageStoreLocation, AS4Message.Create( Error.FromErrorResult( ebmsMessageId, refToMessageId: $"user-{Guid.NewGuid()}", result: new ErrorResult( "Invalid header example description failure", ErrorAlias.InvalidHeader)))) }; SendingProcessingMode pmode = NotifySendingPMode(url); Entities.RetryReliability CreateRetry(long id) => Entities.RetryReliability.CreateForOutMessage( refToOutMessageId: id, maxRetryCount: pmode.ErrorHandling.Reliability.RetryCount, retryInterval: pmode.ErrorHandling.Reliability.RetryInterval.AsTimeSpan(), type: RetryType.Notification); // Act InsertMessageEntityWithRetry(om, as4Msh.GetConfiguration(), pmode, CreateRetry); // Assert SimulateNotifyFailureOnFirstAttempt(url, secondAttemptStatusCode); var spy = new DatabaseSpy(as4Msh.GetConfiguration()); OutMessage notified = await PollUntilPresent( () => spy.GetOutMessageFor( m => m.Operation == expected), timeout: TimeSpan.FromSeconds(10)); Assert.Equal(ebmsMessageId, notified.EbmsMessageId); Entities.RetryReliability referenced = await PollUntilPresent( () => spy.GetRetryReliabilityFor(r => r.RefToOutMessageId == notified.Id), timeout: TimeSpan.FromSeconds(5)); Assert.Equal(RetryStatus.Completed, referenced.Status); }); }
/// <summary> /// Initializes a new instance of the <see cref="RetryAgentForDeliveryFacts"/> class. /// </summary> public RetryAgentForDeliveryFacts() { Settings settings = OverrideSettings("receive_deliver_agent_settings.xml"); _as4Msh = AS4Component.Start(Environment.CurrentDirectory); _databaseSpy = new DatabaseSpy(_as4Msh.GetConfiguration()); _receiveAgentUrl = settings.Agents.ReceiveAgents.First() .Receiver .Setting.FirstOrDefault(s => s.Key == "Url") ?.Value; }
private async Task SendPayloadToStaticSubmit(string settingsFile, Func <DatabaseSpy, Task> assertion) { // Arrange OverrideSettings(settingsFile); var msh = AS4Component.Start(Environment.CurrentDirectory); var databaseSpy = new DatabaseSpy(msh.GetConfiguration()); // Act await SubmitAnonymousPayload(); // Assert await assertion(databaseSpy); // TearDown msh.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="ReceiveAgentFacts" /> class. /// </summary> public ReceiveAgentFacts() { Settings receiveSettings = OverrideSettings("receiveagent_http_settings.xml"); _as4Msh = AS4Component.Start(Environment.CurrentDirectory); _databaseSpy = new DatabaseSpy(_as4Msh.GetConfiguration()); _receiveAgentUrl = receiveSettings.Agents.ReceiveAgents.First().Receiver.Setting .FirstOrDefault(s => s.Key == "Url") ?.Value; Assert.False( string.IsNullOrWhiteSpace(_receiveAgentUrl), "The URL where the receive agent is listening on, could not be retrieved."); }
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); }
public async Task Untouched_Forwarded_Message_Has_Still_Valid_Signature() { // Arrange string ebmsMessageId = $"user-{Guid.NewGuid()}"; IConfig configuration = _msh.GetConfiguration(); AS4Message tobeForwarded = CreateSignedAS4Message(ebmsMessageId, configuration); // Act InsertToBeForwardedMessage( msh: _msh, pmodeId: "Forwarding_Untouched_Push", mep: MessageExchangePattern.Push, tobeForwarded: tobeForwarded); // Assert var databaseSpy = DatabaseSpy.Create(configuration); OutMessage tobeSentRecord = await PollUntilPresent( () => databaseSpy.GetOutMessageFor(m => m.EbmsMessageId == ebmsMessageId && m.Operation == Operation.ToBeSent), timeout : TimeSpan.FromSeconds(20)); Registry.Instance .MessageBodyStore .SaveAS4Message( configuration.InMessageStoreLocation, tobeForwarded); using (Stream tobeSentContents = await tobeSentRecord.RetrieveMessageBody(Registry.Instance.MessageBodyStore)) { AS4Message tobeSentMessage = await SerializerProvider .Default .Get(tobeSentRecord.ContentType) .DeserializeAsync(tobeSentContents, tobeSentRecord.ContentType); bool validSignature = tobeSentMessage.VerifySignature( new VerifySignatureConfig( allowUnknownRootCertificateAuthority: false, attachments: tobeSentMessage.Attachments)); Assert.True(validSignature, "Forwarded AS4Message hasn't got a valid signature present while the message was forwaded 'untouched'"); } }
public async Task OutException_Is_Set_To_Notified_When_Retry_Happen_Within_Allowed_MaxRetry( HttpStatusCode secondAttempt, Operation expected) { await TestComponentWithSettings( "outexception_notify_reliability_settings.xml", async (settings, as4Msh) => { // Arrange var handler = new OutboundExceptionHandler( () => new DatastoreContext(as4Msh.GetConfiguration()), as4Msh.GetConfiguration(), Registry.Instance.MessageBodyStore); const string url = "http://localhost:7070/business/outexception/"; string ebmsMessageId = $"entity-{Guid.NewGuid()}"; var spy = new DatabaseSpy(as4Msh.GetConfiguration()); //var entity = new OutMessage(ebmsMessageId); //spy.InsertOutMessage(entity); // Act await handler.HandleExecutionException( new Exception("This is an test exception"), new MessagingContext(new SubmitMessage()) { SendingPMode = NotifySendingPMode(url) }); // Arrange SimulateNotifyFailureOnFirstAttempt(url, secondAttempt); OutException notified = await PollUntilPresent( () => spy.GetOutExceptions( ex => ex.Operation == expected).FirstOrDefault(), timeout: TimeSpan.FromSeconds(10)); Entities.RetryReliability referenced = await PollUntilPresent( () => spy.GetRetryReliabilityFor(r => r.RefToOutExceptionId == notified.Id), timeout: TimeSpan.FromSeconds(5)); Assert.Equal(RetryStatus.Completed, referenced.Status); }); }
private static void InsertToBeForwardedMessage( AS4Component msh, string pmodeId, MessageExchangePattern mep, AS4Message tobeForwarded) { foreach (MessageUnit m in tobeForwarded.MessageUnits) { string location = Registry.Instance .MessageBodyStore .SaveAS4Message( msh.GetConfiguration().InMessageStoreLocation, tobeForwarded); Operation operation = m.MessageId == tobeForwarded.PrimaryMessageUnit.MessageId ? Operation.ToBeForwarded : Operation.NotApplicable; var inMessage = new InMessage(m.MessageId) { Intermediary = true, Operation = operation, MessageLocation = location, MEP = mep, ContentType = tobeForwarded.ContentType }; ReceivingProcessingMode forwardPMode = msh.GetConfiguration() .GetReceivingPModes() .First(p => p.Id == pmodeId); inMessage.SetPModeInformation(forwardPMode); inMessage.SetStatus(InStatus.Received); inMessage.AssignAS4Properties(m); DatabaseSpy.Create(msh.GetConfiguration()) .InsertInMessage(inMessage); } }
public async Task PiggyBack_Receipt_On_Next_PullRequest_Result_In_Acked_UserMessage() { // Arrange OverrideServiceSettings("piggyback_service_settings.xml"); _windowsService.EnsureServiceIsStarted(); // Act await SubmitMessageToSubmitAgent(pullsendagent_piggyback); // Assert var spy = new DatabaseSpy(_consoleHost.GetConfiguration()); InMessage receipt = await PollUntilPresent( () => spy.GetInMessageFor( m => m.EbmsMessageType == MessageType.Receipt), timeout : TimeSpan.FromSeconds(30)); await PollUntilPresent( () => spy.GetOutMessageFor( m => m.EbmsMessageType == MessageType.UserMessage && m.EbmsMessageId == receipt.EbmsRefToMessageId && m.Status.ToEnum(OutStatus.NotApplicable) == OutStatus.Ack), timeout : TimeSpan.FromSeconds(10)); }
/// <summary> /// Initializes a new instance of the <see cref="PullReceiveAgentFacts"/> class. /// </summary> public PullReceiveAgentFacts() { _pullReceiveSettings = OverrideSettings("pullreceiveagent_settings.xml"); _as4Msh = AS4Component.Start(Environment.CurrentDirectory); _databaseSpy = new DatabaseSpy(_as4Msh.GetConfiguration()); }
public SendAgentFacts() { OverrideSettings("sendagent_settings.xml"); _as4Msh = AS4Component.Start(Environment.CurrentDirectory); _databaseSpy = new DatabaseSpy(_as4Msh.GetConfiguration()); }