public void PublisherDeterminesStatusAndDispatchesIt()
        {
            Message rootMessage            = CreateInfoMessage();
            Message recordsMessage         = CreateInfoMessage();
            Message recordsRecordsMessages = CreateInfoMessage();

            SpfRecordsEvaluated message = new SpfRecordsEvaluated("testDomain", new SpfRecords(new List <SpfRecord> {
                new SpfRecord(null, null, null, new List <Message> {
                    recordsRecordsMessages
                }, false)
            }, 0, new List <Message> {
                recordsMessage
            }), null, null, new List <Message> {
                rootMessage
            }, DateTime.MinValue);

            A.CallTo(() => _domainStatusEvaluator.GetStatus(A <List <Message> > .That.Matches(x => x.Contains(rootMessage) && x.Contains(recordsMessage) && x.Contains(recordsRecordsMessages)))).Returns(Status.Info);

            _domainStatusPublisher.Publish(message);

            Expression <Func <DomainStatusEvaluation, bool> > predicate = x =>
                                                                          x.Status == Status.Info &&
                                                                          x.RecordType == "SPF" &&
                                                                          x.Id == "testDomain";

            A.CallTo(() => _dispatcher.Dispatch(A <DomainStatusEvaluation> .That.Matches(predicate), "testSnsTopicArn")).MustHaveHappenedOnceExactly();
        }
        public async Task Publish(TlsResultsEvaluated message)
        {
            List <TlsEvaluatedResult> evaluatedResults =
                message.TlsRecords?.Records?.Select(x => x.TlsEvaluatedResult).ToList();
            List <Error> evaluatedCertificates = message.Certificates?.Errors;

            Dictionary <string, List <TlsEntityState> > domainsContainingHost = await _dao.GetDomains(message.Id);

            foreach (string domain in domainsContainingHost.Keys)
            {
                List <TlsEntityState>     existingHostStates = domainsContainingHost[domain];
                List <TlsEvaluatedResult> existingResults    = existingHostStates
                                                               .Where(x => x.TlsRecords?.Records != null)
                                                               .SelectMany(x => x.TlsRecords?.Records?.Select(y => y.TlsEvaluatedResult)).ToList();

                List <Error> existingCertificates = existingHostStates
                                                    .Where(x => x.CertificateResults?.Errors != null)
                                                    .SelectMany(x => x.CertificateResults?.Errors).ToList();

                existingResults.AddRange(evaluatedResults ?? new List <TlsEvaluatedResult>());

                existingCertificates.AddRange(evaluatedCertificates ?? new List <Error>());

                Status status = _domainStatusEvaluator.GetStatus(existingResults, existingCertificates);

                DomainStatusEvaluation domainStatusEvaluation = new DomainStatusEvaluation(domain, "TLS", status);

                _log.LogInformation(
                    $"Publishing TLS domain status for domain {domain} because it contains mx host {message.Id} which was evaluated");
                _dispatcher.Dispatch(domainStatusEvaluation, _tlsEntityConfig.SnsTopicArn);
            }
        }
コード例 #3
0
        public void Publish(SpfRecordsEvaluated message)
        {
            List <Message>        rootMessages           = message.Messages;
            List <Message>        recordsMessages        = message.Records?.Messages;
            IEnumerable <Message> recordsRecordsMessages = message.Records?.Records?.SelectMany(x => x.Messages);
            List <SpfRecord>      recordsRecords         = message.Records?.Records;
            List <Message>        recursiveMessages      = new List <Message>();

            if (recordsRecords != null && recordsRecords.Count > 0)
            {
                foreach (SpfRecord record in recordsRecords)
                {
                    IEnumerable <Message> recordMessages = GetMessages(record);
                    recursiveMessages.AddRange(recordMessages);
                }
            }

            IEnumerable <Message> messages = (rootMessages ?? new List <Message>())
                                             .Concat(recordsMessages ?? new List <Message>())
                                             .Concat(recordsRecordsMessages ?? new List <Message>())
                                             .Concat(recursiveMessages ?? new List <Message>());

            Status status = _domainStatusEvaluator.GetStatus(messages.ToList());

            DomainStatusEvaluation domainStatusEvaluation = new DomainStatusEvaluation(message.Id, "SPF", status);

            _log.LogInformation($"Publishing SPF domain status for {message.Id} of {status}");

            _dispatcher.Dispatch(domainStatusEvaluation, _spfEntityConfig.SnsTopicArn);
        }
        public void Publish(DkimRecordEvaluationResult message)
        {
            if (message.SelectorResults is null || message.SelectorResults.Count == 0)
            {
                return;
            }

            List <Contracts.SharedDomain.DkimSelector> selectors = message.SelectorResults?.Select(x => x.Selector).ToList();

            IEnumerable <SharedDomainMessage> pollErrors = selectors
                                                           .Where(x => x.PollError != null)
                                                           .Select(x => x.PollError);

            IEnumerable <SharedDomainMessage> selectorMessages = selectors
                                                                 .Where(x => x.Records != null)
                                                                 .SelectMany(x => x.Records)
                                                                 .Where(x => x.Messages != null)
                                                                 .SelectMany(x => x.Messages);

            IEnumerable <SharedDomainMessage> messages = pollErrors.Concat(selectorMessages);

            List <DkimEvaluatorMessage> recordResults = message.SelectorResults.SelectMany(x => x.RecordsResults)
                                                        .SelectMany(x => x.Messages).ToList();

            Status status = _domainStatusEvaluator.GetStatus(recordResults.ToList(), messages.ToList());

            DomainStatusEvaluation domainStatusEvaluation = new DomainStatusEvaluation(message.Id, "DKIM", status);

            _log.LogInformation($"Publishing DKIM domain status for {message.Id}.");

            _dispatcher.Dispatch(domainStatusEvaluation, _spfEntityConfig.SnsTopicArn);
        }
コード例 #5
0
        public void StatusIsDeterminedAndDispatched()
        {
            Message pollError         = CreateMessage();
            Message dkimRecordMessage = CreateMessage();
            DkimEvaluatorMessage dkimEvaluatorMessage = CreateDkimEvaluatorMessage();

            DkimRecordEvaluationResult message = new DkimRecordEvaluationResult("testDomain",
                                                                                new List <DkimSelectorResult>
            {
                new DkimSelectorResult(
                    new DkimSelector("",
                                     new List <DkimRecord> {
                    new DkimRecord(null, new List <Message> {
                        dkimRecordMessage
                    })
                }, "",
                                     pollError),
                    new List <RecordResult>
                {
                    new RecordResult("", new List <DkimEvaluatorMessage> {
                        dkimEvaluatorMessage
                    })
                })
            });

            A.CallTo(() => _domainStatusEvaluator.GetStatus(A <List <DkimEvaluatorMessage> > .That.Matches(x => x.Contains(dkimEvaluatorMessage)), A <List <Message> > .That.Matches(x => x.Contains(pollError) && x.Contains(dkimRecordMessage)))).Returns(Status.Warning);

            _domainStatusPublisher.Publish(message);

            Expression <Func <DomainStatusEvaluation, bool> > predicate = x =>
                                                                          x.Status == Status.Warning &&
                                                                          x.RecordType == "DKIM" &&
                                                                          x.Id == "testDomain";

            A.CallTo(() => _dispatcher.Dispatch(A <DomainStatusEvaluation> .That.Matches(predicate), "testSnsTopicArn")).MustHaveHappenedOnceExactly();
        }