public async Task SendingPModeCorrectlyDetermined() { const string sendingPModeId = "Forward_SendingPMode_Id"; var receivingPMode = new ReceivingProcessingMode() { MessageHandling = new MessageHandling() { Item = new AS4.Model.PMode.Forward() { SendingPMode = sendingPModeId } } }; var config = new StubConfig(sendingPModes: new Dictionary <string, SendingProcessingMode>() { { sendingPModeId, new SendingProcessingMode() { Id = sendingPModeId } } }, receivingPModes: new Dictionary <string, ReceivingProcessingMode>()); var context = new MessagingContext(new ReceivedMessage(Stream.Null), MessagingContextMode.Forward) { ReceivingPMode = receivingPMode }; var sut = new DetermineRoutingStep(config); var result = await sut.ExecuteAsync(context); Assert.True(result.Succeeded); Assert.NotNull(result.MessagingContext.SendingPMode); }
public Property DeliverMethods_Requires_Either_Empty_Or_Filled_Name_And_Value_Attributes_When_Delivery_Is_Enabled( bool isEnabled) { return(Prop.ForAll( CreateMethodGen().ToArbitrary(), CreateMethodGen().ToArbitrary(), (deliver, payloadRef) => { // Arrange ReceivingProcessingMode pmode = CreateValidPMode(); pmode.MessageHandling.Item = null; pmode.MessageHandling.Item = new Deliver { IsEnabled = isEnabled, DeliverMethod = deliver, PayloadReferenceMethod = payloadRef }; // Act ValidationResult result = ExerciseValidation(pmode); // Assert bool specifiedDeliver = SpecifiedMethod(deliver); bool specifiedPayloadRef = SpecifiedMethod(payloadRef); return result.IsValid .Equals(isEnabled && specifiedDeliver && specifiedPayloadRef) .Or(!isEnabled) .Label( $"Validation has {(result.IsValid ? "succeeded" : "failed")} " + $"but the DeliverMethod {(specifiedDeliver ? "is" : "isn't")} specified " + $"and the PayloadReferenceMethod {(specifiedPayloadRef ? "is" : "isn't")} specified " + $"while the Delivery is {(isEnabled ? "enabled" : "disabled")}"); })); }
public Property PiggyBackReliability_Is_Only_Allowed_When_ReplyPattern_Is_PiggyBack(ReplyPattern pattern) { return(Prop.ForAll( Gen.Fresh(() => new RetryReliability { IsEnabled = false }) .OrNull() .ToArbitrary(), reliability => { // Arrange var pmode = new ReceivingProcessingMode { Id = "receiving-pmode", ReplyHandling = { ReplyPattern = pattern, PiggyBackReliability = reliability, } }; // Act ValidationResult result = ExerciseValidation(pmode); // Assert return result.IsValid.Equals(pattern == ReplyPattern.PiggyBack) .Label("valid when ReplyPattern = PiggyBack") .Or(result.IsValid.Equals(pattern != ReplyPattern.PiggyBack && reliability == null) .Label("valid when ReplyPattern != PiggyBack and no PiggyBackReliability")); })); }
private static IEnumerable <string> DeliverMessageOriginateFrom( UserMessage user, ReceivingProcessingMode receivingPMode, DeliverMessage deliver) { if (user.MessageId != deliver.MessageInfo?.MessageId) { yield return("MessageId"); } if (user.CollaborationInfo.Service.Value != deliver.CollaborationInfo?.Service?.Value) { yield return("Service"); } if (user.CollaborationInfo.Action != deliver.CollaborationInfo?.Action) { yield return("Action"); } if (user.Sender.PrimaryPartyId != deliver.PartyInfo?.FromParty?.PartyIds?.FirstOrDefault()?.Id) { yield return("FromParty"); } if (user.Receiver.PrimaryPartyId != deliver.PartyInfo?.ToParty?.PartyIds?.FirstOrDefault()?.Id) { yield return("ToParty"); } if (receivingPMode.Id != deliver.CollaborationInfo?.AgreementRef?.PModeId) { yield return("PModeId"); } }
private void InsertToBeForwardedInMessage(string pmodeId, MessageExchangePattern mep, AS4Message tobeForwarded) { foreach (MessageUnit m in tobeForwarded.MessageUnits) { string location = Registry.Instance .MessageBodyStore .SaveAS4Message( _as4Msh.GetConfiguration().InMessageStoreLocation, tobeForwarded); var inMessage = new InMessage(m.MessageId) { Intermediary = true, Operation = m.MessageId == tobeForwarded.PrimaryMessageUnit.MessageId ? Operation.ToBeForwarded : Operation.NotApplicable, MessageLocation = location, MEP = mep, ContentType = tobeForwarded.ContentType }; ReceivingProcessingMode forwardPMode = _as4Msh.GetConfiguration() .GetReceivingPModes() .First(p => p.Id == pmodeId); inMessage.SetPModeInformation(forwardPMode); inMessage.SetStatus(InStatus.Received); inMessage.AssignAS4Properties(m); _databaseSpy.InsertInMessage(inMessage); } }
public MonitorServiceTests() { pmode = new ReceivingProcessingMode() { Id = "monitorServiceTestPModeId" }; }
private static Method GetNotifyMethodBasedOnNotifyMessage( NotifyMessageEnvelope notifyMessage, SendingProcessingMode sendingPMode, ReceivingProcessingMode receivingPMode) { switch (notifyMessage.StatusCode) { case Status.Delivered: if (sendingPMode.ReceiptHandling?.NotifyMethod?.Type == null) { throw new InvalidOperationException( $"SendingPMode {sendingPMode.Id} should have a ReceiptHandling.NotifyMethod " + "with a <Type/> element indicating the notifying strategy when the NotifyMessage.StatusCode = Delivered. " + "Default strategies are: 'FILE' and 'HTTP'. See 'Notify Uploading' for more information"); } return(sendingPMode.ReceiptHandling.NotifyMethod); case Status.Error: if (sendingPMode.ErrorHandling?.NotifyMethod?.Type == null) { throw new InvalidOperationException( $"SendingPMode {sendingPMode.Id} should have a ErrorHandling.NotifyMethod " + "with a <Type/> element indicating the notifying strategy when the NotifyMessage.StatusCode = Error. " + "Default strategies are: 'FILE' and 'HTTP'. See 'Notify Uploading' for more information"); } return(sendingPMode.ErrorHandling.NotifyMethod); case Status.Exception: bool isNotifyMessageFormedBySending = sendingPMode?.Id != null; if (isNotifyMessageFormedBySending) { if (sendingPMode?.ExceptionHandling?.NotifyMethod?.Type == null) { throw new InvalidOperationException( $"SendingPMode {sendingPMode.Id} should have a ExceptionHandling.NotifyMethod " + "with a <Type/> element indicating the notifying strategy when the NotifyMessage.StatusCode = Exception. " + "This means that the NotifyMessage is an Exception occured during a outbound sending operation. " + "Default strategies are: 'FILE' and 'HTTP'. See 'Notify Uploading' for more information"); } return(sendingPMode.ExceptionHandling.NotifyMethod); } if (receivingPMode?.ExceptionHandling?.NotifyMethod?.Type == null) { throw new InvalidOperationException( $"ReceivingPMode {receivingPMode?.Id} should have a ExceptionHandling.NotifyMethod " + "with a <Type/> element indicating the notifying strategy when the NotifyMessage.StatusCode = Exception. " + "This means that the NotifyMessage is an Exception occured during an inbound receiving operation. " + "Default strategies are: 'FILE' and 'HTTP'. See 'Notify Uploading' for more information"); } return(receivingPMode.ExceptionHandling.NotifyMethod); default: throw new ArgumentOutOfRangeException($"No NotifyMethod not defined for status {notifyMessage.StatusCode}"); } }
public async Task Determine_Based_On_Unspecified_PartyInfo_Above_AgreementRef() { // Arrange var userMesasge = new UserMessage( $"user-{Guid.NewGuid()}", new CollaborationInfo( new AgreementReference( $"user-agreement-value-{Guid.NewGuid()}", $"user-agreement-type-{Guid.NewGuid()}", $"user-agreement-pmodeid-{Guid.NewGuid()}")), new Party("user-Sender-role", new PartyId($"user-sender-partyid-{Guid.NewGuid()}")), new Party("user-Receiver-role", new PartyId($"user-receiver-partyid-{Guid.NewGuid()}")), new PartInfo[0], new AS4.Model.Core.MessageProperty[0]); ReceivingProcessingMode pmodeByUnspecifiedPartyInfo = CreateMatchedReceivingPMode(userMesasge, PModeMatch.ByUnspecifiedPartyInfo | PModeMatch.ByAgreementRef); ReceivingProcessingMode pmodeByAgreementRef = CreateMatchedReceivingPMode(userMesasge, PModeMatch.ByAgreementRef); // Act ReceivingProcessingMode actual = await ExerciseScoringSystemAsync(userMesasge, pmodeByUnspecifiedPartyInfo, pmodeByAgreementRef); // Assert Assert.Equal(pmodeByUnspecifiedPartyInfo, actual); }
public async Task Determine_Based_On_PMode_PartyInfo_Containing_All_User_PartyIds() { // Arrange var userMessage = new UserMessage( $"user-{Guid.NewGuid()}", new Party("user-Sender-role", new PartyId($"user-sender-partyid-{Guid.NewGuid()}")), new Party("user-Receiver-role", new PartyId($"user-receiver-partyid-{Guid.NewGuid()}"))); ReceivingProcessingMode pmodeByPartyInfo = CreateMatchedReceivingPMode(userMessage, PModeMatch.ByPartyInfo | PModeMatch.ByServiceAction); IEnumerable <PartyId> extraSenderPartyIds = userMessage.Sender.PartyIds.Concat(new[] { new PartyId($"another-user-partyid-{Guid.NewGuid()}") }); IEnumerable <PartyId> extraReceiverPartyIds = userMessage.Receiver.PartyIds.Concat(new[] { new PartyId($"another-user-partyid-{Guid.NewGuid()}") }); var extraPartyIdUserMessage = new UserMessage( userMessage.MessageId, new Party(userMessage.Sender.Role, extraSenderPartyIds), new Party(userMessage.Receiver.Role, extraReceiverPartyIds)); ReceivingProcessingMode pmodeByExtraPartyIdsPartyInfo = CreateMatchedReceivingPMode(extraPartyIdUserMessage, PModeMatch.ByPartyInfo | PModeMatch.ByServiceAction); // Act ReceivingProcessingMode actual = await ExerciseScoringSystemAsync(extraPartyIdUserMessage, pmodeByPartyInfo, pmodeByExtraPartyIdsPartyInfo); // Assert Assert.Equal(pmodeByExtraPartyIdsPartyInfo, actual); }
public Property ExceptionHandling_Requires_To_Have_Specified_Method_When_The_MessageProducer_Must_Be_Notified( bool notifyMessageProducer) { return(Prop.ForAll( CreateMethodGen().ToArbitrary(), method => { // Arrange ReceivingProcessingMode pmode = CreateValidPMode(); pmode.ExceptionHandling = new ReceiveHandling { NotifyMessageConsumer = notifyMessageProducer, NotifyMethod = method }; // Act ValidationResult result = ExerciseValidation(pmode); // Assert bool specifiedNotifyMethod = SpecifiedMethod(method); return result.IsValid .Equals(notifyMessageProducer && specifiedNotifyMethod) .Or(!notifyMessageProducer) .Label( $"Validation has {(result.IsValid ? "succeeded" : "failed")} " + $"but the NotifyMethod {(specifiedNotifyMethod ? "is" : "isn't")} specified " + $"while the NotifyMessageProducer is {(notifyMessageProducer ? "enabled" : "disabled")}"); })); }
private async Task <StepResult> ExerciseVerifyNRRReceipt( IAS4MessageBodyStore messageStore, AS4Message signedReceiptResult, bool verifyNrr) { var verifyNrrPMode = new SendingProcessingMode { ReceiptHandling = { VerifyNRR = verifyNrr } }; var verifySignaturePMode = new ReceivingProcessingMode { Security = { SigningVerification = { Signature = Limit.Required } } }; var step = new VerifySignatureAS4MessageStep( GetDataStoreContext, messageStore); return(await step.ExecuteAsync( new MessagingContext( signedReceiptResult, MessagingContextMode.Receive) { SendingPMode = verifyNrrPMode, ReceivingPMode = verifySignaturePMode })); }
public void ResponseSigning_Is_Required_When_UseNRRFormat_Is_Enabled( bool isEnabled, bool useNrrFormat, bool expected) { // Arrange var pmode = new ReceivingProcessingMode { Id = "not-empty-id", ReplyHandling = { ReceiptHandling = { UseNRRFormat = useNrrFormat }, ResponseSigning = { IsEnabled = isEnabled, SigningCertificateInformation = new CertificateFindCriteria { CertificateFindType = X509FindType.FindBySubjectName, CertificateFindValue = "some-certificate-subject-name" } } } }; // Act ValidationResult result = ExerciseValidation(pmode); // Assert Assert.True( expected == result.IsValid, result.AppendValidationErrorsToErrorMessage("Invalid PMode: ")); }
private static ReceivingProcessingMode GetReceivingPMode() { var pmode = new ReceivingProcessingMode(); pmode.ReplyHandling.ReceiptHandling.UseNRRFormat = false; return(pmode); }
protected ReceivingProcessingMode ReceivingPModeWithAllowedSigningVerification() { var receivingPMode = new ReceivingProcessingMode(); receivingPMode.Security.SigningVerification.Signature = Limit.Allowed; return(receivingPMode); }
public void Set_Retry_Info_When_ReceivingPMode_Is_Configured_For_Retry( bool enabled, PositiveInt count, TimeSpan interval) { // Arrange ClearInExceptions(); IAgentExceptionHandler sut = CreateInboundExceptionHandler(); var pmode = new ReceivingProcessingMode(); pmode.ExceptionHandling.Reliability = new RetryReliability { IsEnabled = enabled, RetryCount = count.Get, RetryInterval = interval.ToString("G") }; var entity = new InMessage($"entity-{Guid.NewGuid()}"); GetDataStoreContext.InsertInMessage(entity); // Act sut.HandleExecutionException( new Exception(), new MessagingContext( new ReceivedEntityMessage(entity), MessagingContextMode.Deliver) { ReceivingPMode = pmode }) .GetAwaiter() .GetResult(); // Assert GetDataStoreContext.AssertInException(ex => { Assert.Null(ex.MessageLocation); GetDataStoreContext.AssertRetryRelatedInException( ex.Id, rr => { Assert.True( enabled == (0 == rr?.CurrentRetryCount), "CurrentRetryCount != 0 when RetryReliability is enabled"); Assert.True( enabled == (count.Get == rr?.MaxRetryCount), enabled ? $"Max retry count failed on enabled: {count.Get} != {rr?.MaxRetryCount}" : $"Max retry count should be 0 on disabled but is {rr?.MaxRetryCount}"); Assert.True( enabled == (interval == rr?.RetryInterval), enabled ? $"Retry interval failed on enabled: {interval:G} != {rr?.RetryInterval}" : $"Retry interval should be 0:00:00 on disabled but is {rr?.RetryInterval}"); }); }); }
public void ThenDeliverIsDefault() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.MessageHandling.DeliverInformation); Assert.False(pmode.MessageHandling.DeliverInformation.IsEnabled); }
public void ThenErrorHandlingIsDefault() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.ReplyHandling.ErrorHandling); Assert.False(pmode.ReplyHandling.ErrorHandling.UseSoapFault); }
/// <summary> /// Determine the points for the given Receiving PMode and UserMessage /// </summary> /// <param name="pmode"></param> /// <param name="userMessage"></param> /// <returns></returns> public int DeterminePoints(ReceivingProcessingMode pmode, UserMessage userMessage) { if (pmode == null) { throw new ArgumentNullException(nameof(pmode)); } if (userMessage == null) { throw new ArgumentNullException(nameof(userMessage)); } Model.PMode.AgreementReference pmodeAgreement = pmode.MessagePackaging ?.CollaborationInfo ?.AgreementReference; Model.Core.AgreementReference userAgreement = userMessage.CollaborationInfo .AgreementReference .GetOrElse(() => null); if (pmodeAgreement == null || userAgreement == null) { return(NotEqual); } bool equalPModeId = userAgreement.PModeId .Select(id => StringComparer.OrdinalIgnoreCase.Equals(id, pmodeAgreement?.PModeId)) .GetOrElse(false); bool noPModeId = userAgreement.PModeId == Maybe <string> .Nothing && pmodeAgreement?.PModeId == null; bool equalType = userAgreement.Type .Select(t => StringComparer.OrdinalIgnoreCase.Equals(t, pmodeAgreement?.Type)) .GetOrElse(false); bool noType = userAgreement.Type == Maybe <string> .Nothing && pmodeAgreement?.Type == null; bool equalValue = StringComparer .OrdinalIgnoreCase .Equals(userAgreement.Value, pmodeAgreement?.Value); return((equalPModeId || noPModeId) && (equalType || noType) && equalValue ? Points : NotEqual); }
public void ThenReceiptHandlingIsDefault() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.ReplyHandling.ReceiptHandling); Assert.False(pmode.ReplyHandling.ReceiptHandling.UseNRRFormat); Assert.Equal(ReplyPattern.Response, pmode.ReplyHandling.ReplyPattern); }
public void ThenExceptionHandlingIsDefault() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.ExceptionHandling); Assert.NotNull(pmode.ExceptionHandling.NotifyMethod); Assert.False(pmode.ExceptionHandling.NotifyMessageConsumer); }
public void ThenSigningVerificationIsDefault() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.Security); Assert.NotNull(pmode.Security.SigningVerification); Assert.Equal(Limit.Allowed, pmode.Security.SigningVerification.Signature); }
public void ThenDuplicateDetectionIsFalse() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.Reliability); Assert.NotNull(pmode.Reliability.DuplicateElimination); Assert.False(pmode.Reliability.DuplicateElimination.IsEnabled); }
public void ThenRetryReliabilityHasDefaultTimeSpan() { // Act var pmode = new ReceivingProcessingMode(); pmode.MessageHandling.DeliverInformation.Reliability.RetryInterval = Guid.NewGuid().ToString(); // Assert Assert.Equal(default(TimeSpan), pmode.MessageHandling.DeliverInformation.Reliability.RetryInterval.AsTimeSpan()); }
public void ThenDecryptionIsIgnoredByDefault() { // Act var pmode = new ReceivingProcessingMode(); // Assert Assert.NotNull(pmode.Security); Assert.NotNull(pmode.Security.Decryption); Assert.Equal(Limit.Ignored, pmode.Security.Decryption.Encryption); }
public Property ReplyHandling_Must_Be_Specified_When_There_Isnt_A_Forward_Element( string responsePMode, string forwardPMode) { var genForward = Gen.OneOf( Gen.Constant((object)null), Gen.Fresh(() => (object)new Forward { SendingPMode = forwardPMode }), Gen.Fresh(() => (object)new Deliver())); var genReplyHandling = Gen.OneOf( Gen.Constant((ReplyHandling)null), Gen.Fresh(() => new ReplyHandling { ResponseConfiguration = new PushConfiguration { Protocol = { Url = "http://not/empty/url" } } })); return(Prop.ForAll( genForward.ToArbitrary(), genReplyHandling.ToArbitrary(), (messageHandlingImp, replyHandling) => { // Arrange ReceivingProcessingMode pmode = CreateValidPMode(); pmode.ReplyHandling = replyHandling; pmode.MessageHandling.Item = messageHandlingImp; // Act ValidationResult result = ExerciseValidation(pmode); // Assert bool specifiedDeliver = messageHandlingImp is Deliver; bool specifiedForward = messageHandlingImp is Forward f && !String.IsNullOrWhiteSpace(f.SendingPMode); bool specifiedReplyHandling = replyHandling?.ResponseConfiguration != null; return result.IsValid .Equals(specifiedReplyHandling && specifiedDeliver) .Or(!specifiedReplyHandling && specifiedForward) .Or(specifiedReplyHandling && specifiedForward) .Label( $"Validation has {(result.IsValid ? "succeeded" : "failed")} " + $"but ReplyHandling {(specifiedReplyHandling ? "is" : "isn't")} specified and " + $"MessageHandling is {(specifiedDeliver ? "a Deliver" : specifiedForward ? "a Forward" : "empty")} element. " + $"{(result.IsValid ? String.Empty : result.AppendValidationErrorsToErrorMessage("Validation Failure: "))}"); })); }
private static async Task <MessagingContext> CreateAS4MessageWithAttachmentAsync() { const string attachmentId = "attachment-id"; var userMessage = new UserMessage(Guid.NewGuid().ToString(), new PartInfo("cid:" + attachmentId)); AS4Message as4Message = AS4Message.Create(userMessage); as4Message.AddAttachment(new Attachment(attachmentId, Stream.Null, "text/plain")); ReceivingProcessingMode pMode = CreateReceivingPModeWithPayloadMethod(); return(await PrepareAS4MessageForDeliveryAsync(as4Message, pMode)); }
/// <summary> /// Determine the points for the given Receiving PMode and UserMessage /// </summary> /// <param name="pmode"></param> /// <param name="userMessage"></param> /// <returns></returns> public int DeterminePoints(ReceivingProcessingMode pmode, UserMessage userMessage) { if (pmode == null) { throw new ArgumentNullException(nameof(pmode)); } if (userMessage == null) { throw new ArgumentNullException(nameof(userMessage)); } PartyInfo pmodePartyInfo = pmode.MessagePackaging?.PartyInfo; if (pmodePartyInfo == null) { return(NotEqual); } if (!pmodePartyInfo.FromPartySpecified && !pmodePartyInfo.ToPartySpecified) { return(NotEqual); } var points = 0; bool fromPartyEqual = ArePartyIdsEqual(pmodePartyInfo.FromParty, userMessage.Sender); bool toPartyEqual = ArePartyIdsEqual(pmodePartyInfo.ToParty, userMessage.Receiver); if (fromPartyEqual && !pmodePartyInfo.ToPartySpecified) { points += FromPartyPoints; } if (toPartyEqual && !pmodePartyInfo.FromPartySpecified) { points += ToPartyPoints; } if (fromPartyEqual && toPartyEqual) { points += FromPartyPoints + ToPartyPoints; } if (ArePartyRolesEqual(pmodePartyInfo, userMessage)) { points += PartyRolePoints; } return(points); }
private static PushConfiguration GetPushConfiguration( SendingProcessingMode sendingPMode, ReceivingProcessingMode receivingPMode) { if (sendingPMode != null) { Logger.Trace($"Use SendingPMode {sendingPMode.Id} for sending the AS4Message"); return(sendingPMode.PushConfiguration); } Logger.Trace($"Use ReceivingPMode {receivingPMode.Id} for sending the AS4Message"); return(receivingPMode?.ReplyHandling?.ResponseConfiguration); }
// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local private static void TestReceivePModeValidation(Action <ReceivingProcessingMode> arrangePMode, bool expected) { // Arrange ReceivingProcessingMode pmode = CreateValidPMode(); arrangePMode(pmode); // Act ValidationResult result = ExerciseValidation(pmode); // Assert Assert.Equal(expected, result.IsValid); }
private async Task ExerciseUpdateReceivedMessage( AS4Message as4Message, SendingProcessingMode sendPMode, ReceivingProcessingMode receivePMode) { // We need to mimick the retrieval of the SendingPMode. MessagingContext ctx = CreateMessageReceivedContext(as4Message, sendPMode, receivePMode); var sut = new UpdateReceivedAS4MessageBodyStep(StubConfig.Default, GetDataStoreContext, _messageBodyStore); MessagingContext savedResult = await ExecuteSaveReceivedMessage(ctx); await sut.ExecuteAsync(savedResult); }