Skip to content

Commit

Permalink
dmarc tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
phillip-stephens committed May 6, 2024
1 parent 579d3de commit 5531527
Showing 1 changed file with 100 additions and 91 deletions.
191 changes: 100 additions & 91 deletions pkg/modules/dmarc/dmarc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,99 +65,108 @@ func TestDmarcLookup_Valid_1(t *testing.T) {
assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
assert.Equal(t, queries[0].Type, dns.TypeTXT)
assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
assert.Equal(t, queries[0].NameServer, "")
assert.Equal(t, queries[0].NameServer, "127.0.0.1")

assert.Equal(t, zdns.STATUS_NOERROR, status)
assert.Equal(t, res.(Result).Dmarc, "v=DMARC1; p=none; rua=mailto:postmaster@censys.io")
}

//
//func TestDmarcLookup_Valid_2(t *testing.T) {
// _, _, _, l := InitTest()
// mockResults["_dmarc.zdns-testing.com"] = zdns.Result{
// Answers: []interface{}{
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// // Capital V in V=DMARC1; should pass
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "V=DMARC1; p=none; rua=mailto:postmaster@censys.io"}},
// }
// res, _, status, _ := l.DoLookup("_dmarc.zdns-testing.com", "")
// assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
// assert.Equal(t, queries[0].Type, dns.TypeTXT)
// assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
// assert.Equal(t, queries[0].NameServer, "")
//
// assert.Equal(t, zdns.STATUS_NOERROR, status)
// assert.Equal(t, res.(Result).Dmarc, "V=DMARC1; p=none; rua=mailto:postmaster@censys.io")
//}
//
//func TestDmarcLookup_Valid_3(t *testing.T) {
// _, _, _, l := InitTest()
// mockResults["_dmarc.zdns-testing.com"] = zdns.Result{
// Answers: []interface{}{
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// // spaces and tabs should pass
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "v\t\t\t=\t\t DMARC1\t\t; p=none; rua=mailto:postmaster@censys.io"}},
// }
// res, _, status, _ := l.DoLookup("_dmarc.zdns-testing.com", "")
// assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
// assert.Equal(t, queries[0].Type, dns.TypeTXT)
// assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
// assert.Equal(t, queries[0].NameServer, "")
//
// assert.Equal(t, zdns.STATUS_NOERROR, status)
// assert.Equal(t, res.(Result).Dmarc, "v\t\t\t=\t\t DMARC1\t\t; p=none; rua=mailto:postmaster@censys.io")
//}
//
//func TestDmarcLookup_NotValid_1(t *testing.T) {
// _, _, _, l := InitTest()
// mockResults["_dmarc.zdns-testing.com"] = zdns.Result{
// Answers: []interface{}{
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// // spaces before "v" should not be accepted
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "\t\t v =DMARC1; p=none; rua=mailto:postmaster@censys.io"}},
// }
// res, _, status, _ := l.DoLookup("_dmarc.zdns-testing.com", "")
// assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
// assert.Equal(t, queries[0].Type, dns.TypeTXT)
// assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
// assert.Equal(t, queries[0].NameServer, "")
//
// assert.Equal(t, zdns.STATUS_NO_RECORD, status)
// assert.Equal(t, res.(Result).Dmarc, "")
//}
//
//func TestDmarcLookup_NotValid_2(t *testing.T) {
// _, _, _, l := InitTest()
// mockResults["_dmarc.zdns-testing.com"] = zdns.Result{
// Answers: []interface{}{
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// // DMARC1 should be capital letters
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "v=DMARc1; p=none; rua=mailto:postmaster@censys.io"}},
// }
// res, _, status, _ := l.DoLookup("_dmarc.zdns-testing.com", "")
// assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
// assert.Equal(t, queries[0].Type, dns.TypeTXT)
// assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
// assert.Equal(t, queries[0].NameServer, "")
//
// assert.Equal(t, zdns.STATUS_NO_RECORD, status)
// assert.Equal(t, res.(Result).Dmarc, "")
//}
//
//func TestDmarcLookup_NotValid_3(t *testing.T) {
// _, _, _, l := InitTest()
// mockResults["_dmarc.zdns-testing.com"] = zdns.Result{
// Answers: []interface{}{
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// // ; has to be present after DMARC1
// zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "v=DMARc1. p=none; rua=mailto:postmaster@censys.io"}},
// }
// res, _, status, _ := l.DoLookup("_dmarc.zdns-testing.com", "")
// assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
// assert.Equal(t, queries[0].Type, dns.TypeTXT)
// assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
// assert.Equal(t, queries[0].NameServer, "")
//
// assert.Equal(t, zdns.STATUS_NO_RECORD, status)
// assert.Equal(t, res.(Result).Dmarc, "")
//}
func TestDmarcLookup_Valid_2(t *testing.T) {
resolver := InitTest(t)
mockResults["_dmarc.zdns-testing.com"] = &zdns.SingleQueryResult{
Answers: []interface{}{
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// Capital V in V=DMARC1; should pass
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "V=DMARC1; p=none; rua=mailto:postmaster@censys.io"}},
}
dmarcMod := DmarcLookupModule{}
dmarcMod.CLIInit(nil, &zdns.ResolverConfig{}, nil)
res, _, status, _ := dmarcMod.Lookup(resolver, "_dmarc.zdns-testing.com", "")
assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
assert.Equal(t, queries[0].Type, dns.TypeTXT)
assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
assert.Equal(t, queries[0].NameServer, "127.0.0.1")

assert.Equal(t, zdns.STATUS_NOERROR, status)
assert.Equal(t, res.(Result).Dmarc, "V=DMARC1; p=none; rua=mailto:postmaster@censys.io")
}

func TestDmarcLookup_Valid_3(t *testing.T) {
resolver := InitTest(t)
mockResults["_dmarc.zdns-testing.com"] = &zdns.SingleQueryResult{
Answers: []interface{}{
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// spaces and tabs should pass
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "v\t\t\t=\t\t DMARC1\t\t; p=none; rua=mailto:postmaster@censys.io"}},
}
dmarcMod := DmarcLookupModule{}
dmarcMod.CLIInit(nil, &zdns.ResolverConfig{}, nil)
res, _, status, _ := dmarcMod.Lookup(resolver, "_dmarc.zdns-testing.com", "")
assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
assert.Equal(t, queries[0].Type, dns.TypeTXT)
assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
assert.Equal(t, queries[0].NameServer, "127.0.0.1")

assert.Equal(t, zdns.STATUS_NOERROR, status)
assert.Equal(t, res.(Result).Dmarc, "v\t\t\t=\t\t DMARC1\t\t; p=none; rua=mailto:postmaster@censys.io")
}

func TestDmarcLookup_NotValid_1(t *testing.T) {
resolver := InitTest(t)
mockResults["_dmarc.zdns-testing.com"] = &zdns.SingleQueryResult{
Answers: []interface{}{
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// spaces before "v" should not be accepted
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "\t\t v =DMARC1; p=none; rua=mailto:postmaster@censys.io"}},
}
dmarcMod := DmarcLookupModule{}
dmarcMod.CLIInit(nil, &zdns.ResolverConfig{}, nil)
res, _, status, _ := dmarcMod.Lookup(resolver, "_dmarc.zdns-testing.com", "")
assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
assert.Equal(t, queries[0].Type, dns.TypeTXT)
assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
assert.Equal(t, queries[0].NameServer, "127.0.0.1")

assert.Equal(t, zdns.STATUS_NO_RECORD, status)
assert.Equal(t, res.(Result).Dmarc, "")
}

func TestDmarcLookup_NotValid_2(t *testing.T) {
resolver := InitTest(t)
mockResults["_dmarc.zdns-testing.com"] = &zdns.SingleQueryResult{
Answers: []interface{}{
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// DMARC1 should be capital letters
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "v=DMARc1; p=none; rua=mailto:postmaster@censys.io"}},
}
dmarcMod := DmarcLookupModule{}
dmarcMod.CLIInit(nil, &zdns.ResolverConfig{}, nil)
res, _, status, _ := dmarcMod.Lookup(resolver, "_dmarc.zdns-testing.com", "")
assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
assert.Equal(t, queries[0].Type, dns.TypeTXT)
assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
assert.Equal(t, queries[0].NameServer, "127.0.0.1")

assert.Equal(t, zdns.STATUS_NO_RECORD, status)
assert.Equal(t, res.(Result).Dmarc, "")
}

func TestDmarcLookup_NotValid_3(t *testing.T) {
resolver := InitTest(t)
mockResults["_dmarc.zdns-testing.com"] = &zdns.SingleQueryResult{
Answers: []interface{}{
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "some TXT record"},
// ; has to be present after DMARC1
zdns.Answer{Name: "_dmarc.zdns-testing.com", Answer: "v=DMARc1. p=none; rua=mailto:postmaster@censys.io"}},
}
dmarcMod := DmarcLookupModule{}
dmarcMod.CLIInit(nil, &zdns.ResolverConfig{}, nil)
res, _, status, _ := dmarcMod.Lookup(resolver, "_dmarc.zdns-testing.com", "")
assert.Equal(t, queries[0].Class, uint16(dns.ClassINET))
assert.Equal(t, queries[0].Type, dns.TypeTXT)
assert.Equal(t, queries[0].Name, "_dmarc.zdns-testing.com")
assert.Equal(t, queries[0].NameServer, "127.0.0.1")

assert.Equal(t, zdns.STATUS_NO_RECORD, status)
assert.Equal(t, res.(Result).Dmarc, "")
}

0 comments on commit 5531527

Please sign in to comment.