public async Task ItShouldFetchRecordsForTheSpecifiedDomainAndSelectors()
        {
            List <string> selectors = new List <string> {
                "foo", "bar"
            };

            A.CallTo(() => _config.AllowNullResults).Returns(true);

            await _sut.Handle(new DkimPollPending("ncsc.gov.uk", 1, selectors));

            A.CallTo(() => _dnsClient.FetchDkimRecords("ncsc.gov.uk", selectors)).MustHaveHappened();
        }
Example #2
0
        public async Task Handle(DkimPollPending message)
        {
            try
            {
                List <DkimSelectorRecords> dkimSelectorRecords =
                    await _dnsClient.FetchDkimRecords(message.Id, message.Selectors);

                if (!_config.AllowNullResults && dkimSelectorRecords.TrueForAll(x =>
                                                                                x.Records.Count == 0 || x.Records.TrueForAll(y => string.IsNullOrWhiteSpace(y.Record))))
                {
                    throw new Exception($"Unable to retrieve DKIM records for {message.Id}, selectors: {JsonConvert.SerializeObject(message)}");
                }

                DkimRecordsPolled dkimRecordsPolled = new DkimRecordsPolled(message.Id, dkimSelectorRecords);

                _log.LogInformation("Polled DKIM selectors for {Domain}", message.Id);

                _dispatcher.Dispatch(dkimRecordsPolled, _config.SnsTopicArn);

                _log.LogInformation("Published DKIM records for {Domain}", message.Id);
            }
            catch (Exception e)
            {
                string error = $"Error occurred polling domain {message.Id}";
                _log.LogError(e, error);
                throw;
            }
        }