public void Process(TlsRptRecord record) { foreach (var tagExplainer in _tagExplainers) { tagExplainer.AddExplanation(record); } }
public async Task ErrorForIncorrectMailCheckUriHasDuplicateNcscAuthorityRemoved2() { RuaTag tag = new RuaTag( "rua=rua=mailto:[email protected],mailto:[email protected],mailto:[email protected];", new List <Uri> { new MailToUri("mailto:[email protected]"), new MailToUri("mailto:[email protected]"), new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", "rua=mailto:[email protected],mailto:[email protected],mailto:[email protected];" }, new List <Tag> { tag }); string actualMarkdown = (await _rule.Evaluate(testTlsRptRecord)).First().MarkDown; string expectedMarkdown = "Your TLS-RPT record contains the wrong email address for Mail Check aggregate report processing.\n\nPlease change your TLS-RPT record to be:\n\n`v=TLSRPTv1;rua=mailto:[email protected],mailto:[email protected];`"; Assert.AreEqual(expectedMarkdown, actualMarkdown); }
public void AddExplanation(TlsRptRecord record) { VersionTag version = record.Tags.OfType <VersionTag>().FirstOrDefault(); if (version != null) { version.Explanation = TlsRptExplainerResource.VersionTlsRptExplanation; } }
public void AddExplanation(TlsRptRecord record) { RuaTag ruaTag = record.Tags.OfType <RuaTag>().FirstOrDefault(); if (ruaTag != null) { if (!ruaTag.Uris.Any(_ => _.Type == nameof(UnknownUri) || _.Type == nameof(MalformedUri))) { string uris = string.Join(Environment.NewLine, ruaTag.Uris.Select(_ => $"{_.Value}")); ruaTag.Explanation = string.Format(TlsRptExplainerResource.RuaExplanation, uris); } } }
public EvaluationResult <TlsRptRecord> Parse(TlsRptRecordInfo tlsRptRecordInfo) { List <Tag> tags = new List <Tag>(); List <Error> errors = new List <Error>(); string[] tokens = tlsRptRecordInfo.Record .Split(TagDelimiter) .Select(_ => _.Trim()) .Where(_ => !string.IsNullOrWhiteSpace(_)) .ToArray(); foreach (string token in tokens) { string[] tagParts = token.Split(TagPartDelimiter); if (tagParts.Length == 2) { string tagKey = tagParts[0].ToLower(); string tagValue = tagParts[1]; if (_parsers.TryGetValue(tagKey, out ITagParser tagParser)) { EvaluationResult <Tag> tag = tagParser.Parse(tags, tlsRptRecordInfo.Record, token, tagKey, tagValue); int tagInstanceCount = tags.Count(_ => _.GetType() == tag.Item.GetType()); if (tagInstanceCount == tagParser.MaxOccurrences) { tag.Errors.Add(new MaxOccurrencesExceededError(tagKey, tagParser.MaxOccurrences, tagInstanceCount)); } tags.Add(tag.Item); errors.AddRange(tag.Errors); } else { tags.Add(new UnknownTag(token)); errors.Add(new UnknownTagError(tagKey, tagValue)); } } else { tags.Add(new MalformedTag(token)); errors.Add(new MalformedTagError(token)); } } TlsRptRecord tlsRptRecord = new TlsRptRecord(tlsRptRecordInfo.Domain, tlsRptRecordInfo.RecordParts, tags); return(new EvaluationResult <TlsRptRecord>(tlsRptRecord, errors)); }
public async Task Test(TlsRptRecord tlsRptRecord, bool isErrorExpected, MessageType?expectedError = null, string markDown = null) { List <Message> messages = await _rule.Evaluate(tlsRptRecord); Assert.That(messages.Any(), Is.EqualTo(isErrorExpected)); Assert.That(messages.FirstOrDefault()?.MessageType, Is.EqualTo(expectedError)); if (markDown != null) { Assert.That(messages.FirstOrDefault()?.MarkDown, Is.EqualTo(markDown)); } }
public async Task WarningWhenNoUris() { RuaTag tag = new RuaTag("rua=;", new List <Uri>()); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", tag.RawValue }, new List <Tag> { tag }); await Test(testTlsRptRecord, true, MessageType.info); }
public async Task ErrorWhenIncorrectMailCheckMailbox() { RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", tag.RawValue }, new List <Tag> { tag }); await Test(testTlsRptRecord, true, MessageType.error); }
public void NoExceptionWhenNullUri() { RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]"), null }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", tag.RawValue }, new List <Tag> { tag }); Assert.DoesNotThrowAsync(async() => await Test(testTlsRptRecord, false)); }
public async Task NoErrorWhenCorrectMailboxIsUsed() { RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", "rua=mailto:[email protected];" }, new List <Tag> { tag }); await Test(testTlsRptRecord, false); }
public async Task NoErrorWhenUnknownUriTest() { string record = "v=TLSRPTv1;rua=mailto:[email protected], mailto:[email protected], mailto:[email protected]"; RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]"), new MailToUri("mailto:[email protected]"), new UnknownUri("abc:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string>(), new List <Tag> { tag }); List <Message> result = await _rule.Evaluate(testTlsRptRecord); Assert.That(result.Count, Is.EqualTo(0)); }
public async Task ErrorForIncorrectMailCheckUriHasCorrectlyFormattedMarkdown1() { string record = "v=TLSRPTv1;rua=mailto:[email protected]"; RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string>(), new List <Tag> { tag }); string actualMarkdown = (await _rule.Evaluate(testTlsRptRecord)).First().MarkDown; string expectedMarkdown = "The TLS-RPT record does not contain the NCSC Mail Check email address, it's fine to use other tools but be aware that we won't be able to help you investigate encrypted email deliverability, and you won't see any reporting in Mail Check.\n\nIf you would like Mail Check to receive a copy of your reports, then please change your record to:\n\n`rua=mailto:[email protected];`"; Assert.AreEqual(expectedMarkdown, actualMarkdown); }
public async Task WarningWhenSameMailboxMentionedMoreThanOnce() { RuaTag tag = new RuaTag("rua=mailto:[email protected]; mailto:[email protected]; mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]"), new MailToUri("mailto:[email protected]"), new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", "rua=mailto:[email protected],mailto:[email protected],mailto:[email protected];" }, new List <Tag> { tag }); await Test(testTlsRptRecord, true, MessageType.warning); }
public async Task NoErrorWhenNewRuaMailboxFoundWithOtherInvalidMailbox() { RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]"), new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", "rua=mailto:[email protected],mailto:[email protected]" }, new List <Tag> { tag }); List <Message> result = await _rule.Evaluate(testTlsRptRecord); Assert.That(result.Count, Is.EqualTo(0)); }
public async Task ErrorWhenNoNewOrOriginalRuaMailboxFound() { RuaTag tag = new RuaTag("rua=mailto:[email protected]", new List <Uri> { new MailToUri("mailto:[email protected]") }); TlsRptRecord testTlsRptRecord = new TlsRptRecord(Id, new List <string> { "v=TLSRPTv1;", "rua=mailto:[email protected]" }, new List <Tag> { tag }); List <Message> result = await _rule.Evaluate(testTlsRptRecord); Assert.That(result.Count, Is.EqualTo(1)); Assert.That(result[0].Text, Is.EqualTo( "Mail Check can only provide email reporting if the aggregate report URI tag (rua) includes the [email protected] mailbox. Consider adding `mailto:[email protected]` to the rua tag values.")); }
private static ContractTlsRptRecord ToContractTlsRptRecord(this TlsRptRecord tlsRptRecord) { return(new ContractTlsRptRecord(tlsRptRecord.Domain, tlsRptRecord.RecordsParts, tlsRptRecord.Tags.Select(x => x.ToContract()).ToList())); }