Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/spflib/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Parse(text string, dnsres Resolver) (*SPFRecord, error) {
return nil, fmt.Errorf("in included SPF: %w", err)
}
}
} else if strings.HasPrefix(part, "exists:") || strings.HasPrefix(part, "ptr:") {
} else if strings.HasPrefix(part, "exists:") || part == "ptr" || strings.HasPrefix(part, "ptr:") {
p.IsLookup = true
} else {
return nil, fmt.Errorf("unsupported SPF part %s", part)
Expand Down
29 changes: 29 additions & 0 deletions pkg/spflib/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ func TestParseQualifiedMechanisms(t *testing.T) {
}
}

func TestParsePtrMechanism(t *testing.T) {
tests := []struct {
input string
wantErr bool
lookups int
}{
{"v=spf1 ptr -all", false, 1},
{"v=spf1 a mx ptr -all", false, 3},
{"v=spf1 mx ptr ip4:107.161.151.0/24 ~all", false, 2},
{"v=spf1 +ptr -all", false, 1},
{"v=spf1 ~ptr -all", false, 1},
{"v=spf1 ?ptr -all", false, 1},
{"v=spf1 ptr:example.com -all", false, 1},
{"v=spf1 ptrfoo -all", true, 0},
{"v=spf1 ptrfoo:example.com -all", true, 0},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
rec, err := Parse(tt.input, nil)
if (err != nil) != tt.wantErr {
t.Fatalf("Parse(%q) error = %v, wantErr %v", tt.input, err, tt.wantErr)
}
if err == nil && rec.Lookups() != tt.lookups {
t.Errorf("Parse(%q) lookups = %d, want %d", tt.input, rec.Lookups(), tt.lookups)
}
})
}
}

func TestParseRedirectLast(t *testing.T) {
dnsres, err := NewCache("testdata-dns1.json")
if err != nil {
Expand Down