private static Property NotifyMethod_Should_Be_Specified_When_We_Notify_MessageProducer(
            bool notifyMessageProducer,
            Func <SendingProcessingMode, SendHandling> getHandling)
        {
            return(Prop.ForAll(
                       CreateMethodGen().ToArbitrary(),
                       method =>
            {
                // Arrange
                var pmode = ValidSendingPModeFactory.Create();
                SendHandling sendHandling = getHandling(pmode);
                sendHandling.NotifyMessageProducer = notifyMessageProducer;
                sendHandling.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")}");
            }));
        }
Esempio n. 2
0
        private static SendingProcessingMode CreateAnonymousSendingPModeWith(string expectedMpc)
        {
            SendingProcessingMode expectedSendingPMode = ValidSendingPModeFactory.Create("expected-id");

            expectedSendingPMode.MessagePackaging.Mpc = expectedMpc;

            return(expectedSendingPMode);
        }
        /// <summary>
        /// Retrieve the PMode from the Global Settings
        /// </summary>
        /// <param name="id"></param>
        /// <exception cref="Exception"></exception>
        /// <returns></returns>
        public override SendingProcessingMode GetSendingPMode(string id)
        {
            SendingProcessingMode pmode = ValidSendingPModeFactory.Create();

            pmode.MessagePackaging.MessageProperties = new List <AS4.Model.PMode.MessageProperty>();

            return(pmode);
        }
        public void ValidSendingPMode_IfKeySizeIs(int beforeKeySize, int afterKeySize)
        {
            SendingProcessingMode pmode = ValidSendingPModeFactory.Create();

            pmode.Security.Encryption.IsEnabled        = true;
            pmode.Security.Encryption.AlgorithmKeySize = beforeKeySize;

            // Act
            ExerciseValidation(pmode);

            // Assert
            Assert.True(pmode.Security.Encryption.AlgorithmKeySize == afterKeySize);
        }
        public Property Encryption_Certificate_Should_Be_Specified_When_Encryption_Is_Enabled_For_A_Non_DynamicDiscovery_Setup(
            bool isEnabled,
            string findValue,
            string certificate)
        {
            var genDynamicDiscoveryProfile =
                Gen.Fresh(() => new DynamicDiscoveryConfiguration())
                .OrNull();

            return(Prop.ForAll(
                       CreateEncryptionCertificateInfoGen(findValue, certificate).ToArbitrary(),
                       genDynamicDiscoveryProfile.ToArbitrary(),
                       (cert, dynamicDiscovery) =>
            {
                // Arrange
                var pmode = ValidSendingPModeFactory.Create();
                pmode.DynamicDiscovery = dynamicDiscovery;
                pmode.Security.Encryption = new Encryption
                {
                    IsEnabled = isEnabled,
                    EncryptionCertificateInformation = cert.Item2,
                    CertificateType = cert.Item1
                };

                // Act
                ValidationResult result = ExerciseValidation(pmode);

                // Assert
                bool specifiedDynamicDiscoveryProfile = pmode.DynamicDiscoverySpecified;
                bool specifiedCertFindCriteria =
                    cert.Item1 == PublicKeyCertificateChoiceType.CertificateFindCriteria &&
                    cert.Item2 is CertificateFindCriteria c &&
                    !String.IsNullOrWhiteSpace(c.CertificateFindValue);

                bool specifiedPublicKeyCert =
                    cert.Item1 == PublicKeyCertificateChoiceType.PublicKeyCertificate &&
                    cert.Item2 is PublicKeyCertificate k &&
                    !String.IsNullOrWhiteSpace(k.Certificate);

                bool specifiedEncryptionCert = specifiedCertFindCriteria || specifiedPublicKeyCert;
                return result.IsValid
                .Equals(specifiedEncryptionCert && isEnabled && !specifiedDynamicDiscoveryProfile)
                .Or(!isEnabled)
                .Or(specifiedDynamicDiscoveryProfile)
                .Label(
                    $"Validation has {(result.IsValid ? "succeeded" : "failed")} " +
                    $"but encryption certificate {(specifiedEncryptionCert ? "is" : "isn't")} specified " +
                    $"with a {cert.Item1} while the encryption is {(isEnabled ? "enabled" : "disabled")} " +
                    $"for a {(specifiedDynamicDiscoveryProfile ? "configured" : "non-configured")} Dynamic Discovery");
            }));
        }
Esempio n. 6
0
        private static SendingProcessingMode CreateSendingPMode(AS4.Model.PMode.Party fromParty, AS4.Model.PMode.Party toParty)
        {
            SendingProcessingMode pmode = ValidSendingPModeFactory.Create();

            pmode.MessagePackaging = new SendMessagePackaging
            {
                PartyInfo = new PartyInfo
                {
                    FromParty = fromParty,
                    ToParty   = toParty
                }
            };

            return(pmode);
        }
Esempio n. 7
0
        public async Task FailsToRetrievePMode_IfInvalidPMode()
        {
            // Arrange
            const string pmodeId         = "01-pmode";
            var          internalMessage = new MessagingContext(GetStubSubmitMessage(pmodeId));

            SendingProcessingMode invalidPMode = ValidSendingPModeFactory.Create(pmodeId);

            invalidPMode.ReceiptHandling.NotifyMessageProducer = true;
            invalidPMode.ReceiptHandling.NotifyMethod          = null;

            var sut = new RetrieveSendingPModeStep(CreateStubConfigWithSendingPMode(invalidPMode));

            // Act / Assert
            await Assert.ThrowsAnyAsync <Exception>(() => sut.ExecuteAsync(internalMessage));
        }
        public Property Tls_Certificate_Should_Be_Specified_When_Tls_Is_Enabled(
            bool isEnabled,
            string clientCertFindValue,
            string password,
            string certificate)
        {
            return(Prop.ForAll(
                       CreateTlsCertificateInfoGen(clientCertFindValue, password, certificate)
                       .ToArbitrary(),
                       tls =>
            {
                // Arrange
                SendingProcessingMode pmode = ValidSendingPModeFactory.Create();
                pmode.PushConfiguration.TlsConfiguration = new TlsConfiguration
                {
                    IsEnabled = isEnabled,
                    ClientCertificateInformation = tls.Item2,
                    CertificateType = tls.Item1
                };

                // Act
                ValidationResult result = ExerciseValidation(pmode);

                // Assert
                bool specifiedClientCertRef =
                    tls.Item1 == TlsCertificateChoiceType.ClientCertificateReference &&
                    tls.Item2 is ClientCertificateReference clientCertRef &&
                    !String.IsNullOrWhiteSpace(clientCertRef.ClientCertificateFindValue);

                bool specifiedPrivateKeyCert =
                    tls.Item1 == TlsCertificateChoiceType.PrivateKeyCertificate &&
                    tls.Item2 is PrivateKeyCertificate privateKeyCert &&
                    !String.IsNullOrWhiteSpace(privateKeyCert.Certificate) &&
                    !String.IsNullOrWhiteSpace(privateKeyCert.Password);

                bool specifiedCert = specifiedClientCertRef || specifiedPrivateKeyCert;
                return result.IsValid
                .Equals(specifiedCert && isEnabled)
                .Or(!isEnabled)
                .Label(
                    $"Validation has {(result.IsValid ? "succeeded" : "failed")} " +
                    $"but TLS client certificate {(specifiedCert ? "is" : "isn't")} specified " +
                    $"with a {tls.Item1} while the TLS configuration is {(isEnabled ? "enabled" : "disabled")}");
            }));
        }
        public Property Signing_Certificate_Should_Be_Specified_When_Signing_Is_Enabled(
            bool isEnabled,
            string findValue,
            string certificate,
            string password)
        {
            return(Prop.ForAll(
                       CreatePrivateKeyCertificateGen(findValue, certificate, password)
                       .ToArbitrary(),
                       cert =>
            {
                // Arrange
                SendingProcessingMode pmode = ValidSendingPModeFactory.Create();
                pmode.Security.Signing = new Signing
                {
                    IsEnabled = isEnabled,
                    SigningCertificateInformation = cert.Item2,
                    CertificateType = cert.Item1
                };

                // Act
                ValidationResult result = ExerciseValidation(pmode);

                // Assert
                bool specifiedCertFindCriteria =
                    cert.Item1 == PrivateKeyCertificateChoiceType.CertificateFindCriteria &&
                    cert.Item2 is CertificateFindCriteria c &&
                    !String.IsNullOrWhiteSpace(c.CertificateFindValue);

                bool specifiedPrivateKeyCert =
                    cert.Item1 == PrivateKeyCertificateChoiceType.PrivateKeyCertificate &&
                    cert.Item2 is PrivateKeyCertificate k &&
                    !String.IsNullOrWhiteSpace(k.Certificate) &&
                    !String.IsNullOrWhiteSpace(k.Password);

                bool specifiedCertInfo = specifiedCertFindCriteria || specifiedPrivateKeyCert;
                return result.IsValid
                .Equals(specifiedCertInfo && isEnabled)
                .Or(!isEnabled)
                .Label(
                    $"Validation has {(result.IsValid ? "succeeded" : "failed")} " +
                    $"but signing certificate {(specifiedCertInfo ? "is" : "isn't")} specified " +
                    $"with a {cert.Item1} while the signing is {(isEnabled ? "enabled" : "disabled")}");
            }));
        }
        private static Property TestRelialityForEnabledFlag(
            bool isEnabled,
            int retryCount,
            TimeSpan retryInterval,
            Func <SendingProcessingMode, RetryReliability> getReliability)
        {
            return(Prop.ForAll(
                       Gen.Frequency(
                           Tuple.Create(1, Arb.From <string>().Generator),
                           Tuple.Create(2, Gen.Constant(retryInterval.ToString())))
                       .ToArbitrary(),
                       retryIntervalText =>
            {
                // Arrange
                SendingProcessingMode pmode = ValidSendingPModeFactory.Create();
                RetryReliability r = getReliability(pmode);
                r.IsEnabled = isEnabled;
                r.RetryCount = retryCount;
                r.RetryInterval = retryIntervalText;

                // Act
                ValidationResult result = ExerciseValidation(pmode);

                // Assert
                bool correctConfigured =
                    retryCount > 0 &&
                    r.RetryInterval.AsTimeSpan() > default(TimeSpan);

                bool expected =
                    !isEnabled && !correctConfigured ||
                    !isEnabled ||
                    correctConfigured;

                return expected.Equals(result.IsValid)
                .Label(result.AppendValidationErrorsToErrorMessage(string.Empty))
                .Classify(result.IsValid, "Valid PMode")
                .Classify(!result.IsValid, "Invalid PMode")
                .Classify(correctConfigured, "Correct Reliability")
                .Classify(!correctConfigured, "Incorrect Reliability")
                .Classify(isEnabled, "Reliability is enabled")
                .Classify(!isEnabled, "Reliability is disabled");
            }));
        }
Esempio n. 11
0
        public async Task MessageIsntCreated_IfDuplicatePayloadIdsAreFound()
        {
            // Arrange
            SendingProcessingMode pmode = ValidSendingPModeFactory.Create();
            var submit = new SubmitMessage
            {
                PMode    = pmode,
                Payloads = new []
                {
                    new Payload("earth", "location", "mime"),
                    new Payload("earth", "location", "mime")
                }
            };
            var context = new MessagingContext(submit)
            {
                SendingPMode = pmode
            };

            // Act / Assert
            await Assert.ThrowsAsync <InvalidMessageException>(() => ExerciseCreation(context));
        }
        public Property RetryCount_And_RetryInterval_Should_Be_Specified_When_ReceptionAwarness_Is_Enabled(
            bool isEnabled,
            int retryCount,
            TimeSpan retryInterval)
        {
            return(Prop.ForAll(
                       Gen.Frequency(
                           Tuple.Create(1, Arb.Generate <string>()),
                           Tuple.Create(2, Gen.Constant(retryInterval.ToString())))
                       .ToArbitrary(),
                       retryIntervalText =>
            {
                // Arrange
                SendingProcessingMode pmode = ValidSendingPModeFactory.Create();
                var r = new ReceptionAwareness
                {
                    IsEnabled = isEnabled,
                    RetryCount = retryCount,
                    RetryInterval = retryIntervalText
                };
                pmode.Reliability.ReceptionAwareness = r;

                // Act
                ValidationResult result = ExerciseValidation(pmode);

                // Assert
                bool validRetryCount = r.RetryCount > 0;
                bool validRetryInterval = r.RetryInterval.AsTimeSpan() > default(TimeSpan);
                return result.IsValid
                .Equals(isEnabled &&
                        validRetryCount &&
                        validRetryInterval)
                .Or(!isEnabled)
                .Label(
                    $"Validation has {(result.IsValid ? "succeeded" : "failed")} " +
                    $"but the RetryCount {(validRetryCount ? ">" : "<=")} 0 (was {r.RetryCount}) and " +
                    $"RetryInterval {(validRetryInterval ? ">" : "<=")} {default(TimeSpan)} (was {r.RetryInterval}) " +
                    $"while the ReceptionAwareness is {(isEnabled ? "enabled" : "disabled")}");
            }));
        }