public async Task <SpfPollResult> Process(string domain) { Stopwatch stopwatch = Stopwatch.StartNew(); DnsResult <List <List <string> > > spfDnsRecords = await _dnsClient.GetSpfRecords(domain); if (!_config.AllowNullResults && (spfDnsRecords.IsErrored || spfDnsRecords.Value.Count == 0 || spfDnsRecords.Value.TrueForAll(x => x.TrueForAll(string.IsNullOrWhiteSpace)))) { throw new SpfPollerException($"Unable to retrieve spf records for {domain}."); } if (spfDnsRecords.IsErrored) { string message = string.Format(SpfProcessorResource.FailedSpfRecordQueryErrorMessage, domain, spfDnsRecords.Error); string markdown = string.Format(SpfProcessorMarkdownResource.FailedSpfRecordQueryErrorMessage, domain, spfDnsRecords.Error); Guid id = Guid.Parse("76390C8C-12D5-47FF-981E-D880D2B77216"); return(new SpfPollResult(new Error(id, ErrorType.Error, message, markdown))); } SpfRecords root = await _spfRecordsParser.Parse(domain, spfDnsRecords.Value, spfDnsRecords.MessageSize); int lookupCount = await _spfRecordExpander.ExpandSpfRecords(domain, root); SpfPollResult pollResult = new SpfPollResult(root, lookupCount, stopwatch.Elapsed); EvaluationResult <SpfPollResult> errors = await _pollResultRulesEvaluator.Evaluate(pollResult); pollResult.Errors.AddRange(errors.Errors); return(pollResult); }
public async Task RedirectTermExpanded() { List <string> spfRecord = new List <string> { "v=spf1" }; A.CallTo(() => _dnsClient.GetSpfRecords(A <string> ._)) .Returns(Task.FromResult(new DnsResult <List <List <string> > > (new List <List <string> > { spfRecord }, 200))); Redirect redirect = new Redirect("", new DomainSpec("")); SpfRecords spfRecords = await _spfRedirectTermExpander.Process("", redirect); Assert.That(spfRecords, Is.Not.Null); Assert.That(redirect.Records, Is.SameAs(spfRecords)); Assert.That(redirect.AllErrors, Is.Empty); }
public async Task IncludeTermExpanded() { List <string> spfRecord = new List <string> { "v=spf1" }; A.CallTo(() => _dnsClient.GetSpfRecords(A <string> ._)) .Returns(Task.FromResult(new DnsResult <List <List <string> > > (new List <List <string> > { spfRecord }, 200))); Include include = new Include("", Qualifier.Pass, new DomainSpec("")); SpfRecords spfRecords = await _spfIncludeTermExpander.Process("", include); Assert.That(spfRecords, Is.Not.Null); Assert.That(include.Records, Is.SameAs(spfRecords)); Assert.That(include.AllErrors, Is.Empty); }
public async Task <SpfRecords> Process(string domain, Term term) { Redirect redirect = term as Redirect; DnsResult <List <List <string> > > spfDnsRecords = await _dnsClient.GetSpfRecords(redirect.DomainSpec.Domain); if (spfDnsRecords.IsErrored) { string message = string.Format(SpfExpansionResource.FailedSpfRecordQueryErrorMessage, redirect.DomainSpec.Domain, spfDnsRecords.Error); string markdown = string.Format(SpfExpansionMarkdownResource.FailedSpfRecordQueryErrorMessage, redirect.DomainSpec.Domain, spfDnsRecords.Error); term.AddError(new Error(Id, ErrorType.Error, message, markdown)); return(null); } redirect.Records = await _recordsParser.Parse(redirect.DomainSpec.Domain, spfDnsRecords.Value, spfDnsRecords.MessageSize); return(redirect.Records); }