MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestExtractDomains

Function TestExtractDomains

internal/dmarc/evaluate_test.go:459–514  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

457}
458
459func TestExtractDomains(t *testing.T) {
460 type tCase struct {
461 hdr string
462
463 fromDomain string
464 }
465 test := func(i int, c tCase) {
466 hdr, err := textproto.ReadHeader(bufio.NewReader(strings.NewReader(c.hdr + "\n\n")))
467 if err != nil {
468 panic(err)
469 }
470
471 domain, err := ExtractFromDomain(hdr)
472 if c.fromDomain == "" && err == nil {
473 t.Errorf("%d: expected failure, got fromDomain = %s", i, domain)
474 return
475 }
476 if c.fromDomain != "" && err != nil {
477 t.Errorf("%d: unexpected error: %v", i, err)
478 return
479 }
480 if domain != c.fromDomain {
481 t.Errorf("%d: want fromDomain = %v but got %s", i, c.fromDomain, domain)
482 }
483 }
484
485 cases := []tCase{
486 {
487 hdr: `From: <test@example.org>`,
488 fromDomain: "example.org",
489 },
490 {
491 hdr: `From: <test@foo.example.org>`,
492 fromDomain: "foo.example.org",
493 },
494 {
495 hdr: `From: <test@foo.example.org>, <test@bar.example.org>`,
496 },
497 {
498 hdr: `From: <test@foo.example.org>,
499From: <test@bar.example.org>`,
500 },
501 {
502 hdr: `From: <test@>`,
503 },
504 {
505 hdr: `From: `,
506 },
507 {
508 hdr: `From: foo`,
509 },
510 }
511 for i, case_ := range cases {
512 test(i, case_)
513 }
514}

Callers

nothing calls this directly

Calls 2

ExtractFromDomainFunction · 0.85
testStruct · 0.85

Tested by

no test coverage detected