public async Task ShouldHandleChangeSaveAndDispatchWhenTlsTestResultIsReceived()
        {
            string snsTopicArn = "snsTopicArn";

            A.CallTo(() => _tlsEntityConfig.SnsTopicArn).Returns(snsTopicArn);

            string hostName = "testhostname";

            TlsEntityState stateFromDb = new TlsEntityState(hostName)
            {
                TlsState = TlsState.Created
            };

            A.CallTo(() => _dao.Get(hostName)).Returns(Task.FromResult(stateFromDb));
            A.CallTo(() => _dao.GetDomainsFromHost(hostName)).Returns(Task.FromResult(new List <string> {
                "test.gov.uk"
            }));



            A.CallTo(() => _tlsEntityConfig.NextScheduledInSeconds).Returns(33);
            A.CallTo(() => _clock.GetDateTimeUtc()).Returns(DateTime.MinValue);

            CertificateResults certificateResults = new CertificateResults(null, null);

            TlsResultsEvaluated message = new TlsResultsEvaluated(hostName, false, new TlsRecords(
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      , new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      , new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      , new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      ), certificateResults);

            await _tlsEntity.Handle(message);

            Assert.AreEqual(stateFromDb.TlsState, TlsState.Evaluated);
            Assert.AreEqual(stateFromDb.TlsRecords, message.TlsRecords);
            Assert.AreEqual(stateFromDb.LastUpdated, message.Timestamp);
            List <string> domains = new List <string>();

            A.CallTo(() => _changeNotifierComposite.Handle(stateFromDb, message, A <List <string> > ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _dao.Save(stateFromDb)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _dispatcher.Dispatch(A <TlsRecordEvaluationsChanged> .That.Matches(a => a.Id == message.Id && a.TlsRecords == message.TlsRecords && a.CertificateResults == message.Certificates), snsTopicArn)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _dispatcher.Dispatch(A <CreateScheduledReminder> .That.Matches(a => a.ResourceId == hostName && a.Service == "Tls" && a.ScheduledTime.Second == 33), snsTopicArn)).MustHaveHappenedOnceExactly();
        }
        public async Task Handle(TlsTestResults message)
        {
            TlsResultsEvaluated results = await _tlsRptEvaluationProcessor.Process(message);

            if (message.Certificates.Any())
            {
                CertificateResults certs = await _certificateProcessor.Process(message);

                results = new TlsResultsEvaluated(results.Id, results.Failed, results.TlsRecords, certs);
            }

            _dispatcher.Dispatch(results, _config.SnsTopicArn);
        }
        public async Task ShouldRescheduledWhenItHasFailedToCorrectPeriod()
        {
            string snsTopicArn = "snsTopicArn";

            A.CallTo(() => _tlsEntityConfig.SnsTopicArn).Returns(snsTopicArn);

            string hostName = "testhostname";

            TlsEntityState stateFromDb = new TlsEntityState(hostName)
            {
                TlsState = TlsState.Created
            };

            A.CallTo(() => _dao.Get(hostName)).Returns(Task.FromResult(stateFromDb));


            A.CallTo(() => _tlsEntityConfig.FailureNextScheduledInSeconds).Returns(15);
            A.CallTo(() => _tlsEntityConfig.MaxTlsRetryAttempts).Returns(5);

            A.CallTo(() => _clock.GetDateTimeUtc()).Returns(DateTime.MinValue);

            CertificateResults certificateResults = new CertificateResults(null, null);

            TlsResultsEvaluated message = new TlsResultsEvaluated(hostName, true, new TlsRecords(
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      , new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      , new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      , new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS)),
                                                                      new TlsRecord(new TlsEvaluatedResult(Guid.NewGuid(), EvaluatorResult.PASS))
                                                                      ), certificateResults);

            await _tlsEntity.Handle(message);

            A.CallTo(() => _changeNotifierComposite.Handle(stateFromDb, message, A <List <string> > ._)).MustNotHaveHappened();
            A.CallTo(() => _dao.Save(stateFromDb)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _dispatcher.Dispatch(A <TlsRecordEvaluationsChanged> .That.Matches(a => a.Id == message.Id && a.TlsRecords == message.TlsRecords && a.CertificateResults == message.Certificates), snsTopicArn, null)).MustNotHaveHappened();
            A.CallTo(() => _dispatcher.Dispatch(A <CreateScheduledReminder> .That.Matches(a => a.ResourceId == hostName && a.Service == "Tls" && a.ScheduledTime.Second == 15), snsTopicArn)).MustHaveHappenedOnceExactly();
        }
Beispiel #4
0
 public TlsResultsEvaluated(string id, bool failed, TlsRecords tlsRecords, CertificateResults certificates = null) : base(id)
 {
     TlsRecords   = tlsRecords;
     Certificates = certificates;
     Failed       = failed;
 }
 private MxTlsCertificateEvaluatorResults CreateMxTlsCertificateEvaluatorResults(string hostName, int preference, DateTime lastChecked,
                                                                                 CertificateResults certificateResults)
 {
     return(new MxTlsCertificateEvaluatorResults(hostName, preference, lastChecked, certificateResults?.Certificates,
                                                 certificateResults?.Errors));
 }
 public TlsRecordEvaluationsChanged(string id, TlsRecords records, CertificateResults certificateResults) : base(id)
 {
     TlsRecords         = records;
     CertificateResults = certificateResults;
 }