Skip to content

Commit

Permalink
Merge pull request #51 from moorereason/iss45
Browse files Browse the repository at this point in the history
Handle multiple auth results
  • Loading branch information
tierpod authored Apr 14, 2024
2 parents 8caa163 + 9a8b613 commit 96ba341
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 218 deletions.
275 changes: 97 additions & 178 deletions cmd/dmarc-report-converter/consts.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/dmarc/dmarc.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ type Identifiers struct {

// AuthResults represents feedback>record>auth_results section
type AuthResults struct {
DKIM DKIMAuthResult `xml:"dkim" json:"dkim"`
SPF SPFAuthResult `xml:"spf" json:"spf"`
DKIM []DKIMAuthResult `xml:"dkim" json:"dkim"`
SPF []SPFAuthResult `xml:"spf" json:"spf"`
}

// DKIMAuthResult represnets feedback>record>auth_results>dkim sections
Expand Down
63 changes: 37 additions & 26 deletions pkg/dmarc/dmarc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,24 @@ var xmlRecord1 = Record{
EnvelopeFrom: "",
},
AuthResults: AuthResults{
DKIM: DKIMAuthResult{
Domain: "test.net",
Result: "pass",
Selector: "selector",
DKIM: []DKIMAuthResult{
{
Domain: "test1.net",
Result: "fail",
Selector: "selector1",
},
{
Domain: "test2.net",
Result: "pass",
Selector: "selector2",
},
},
SPF: SPFAuthResult{
Domain: "test.net",
Result: "pass",
Scope: "mfrom",
SPF: []SPFAuthResult{
{
Domain: "test.net",
Result: "pass",
Scope: "mfrom",
},
},
},
}
Expand All @@ -71,15 +80,19 @@ var xmlRecord2 = Record{
EnvelopeFrom: "",
},
AuthResults: AuthResults{
DKIM: DKIMAuthResult{
Domain: "test2.net",
Result: "fail",
Selector: "selector",
DKIM: []DKIMAuthResult{
{
Domain: "test2.net",
Result: "fail",
Selector: "selector",
},
},
SPF: SPFAuthResult{
Domain: "test2.net",
Result: "softfail",
Scope: "mfrom",
SPF: []SPFAuthResult{
{
Domain: "test2.net",
Result: "softfail",
Scope: "mfrom",
},
},
},
}
Expand Down Expand Up @@ -225,15 +238,13 @@ var xmlEmptyReport = Report{
EnvelopeFrom: "",
},
AuthResults: AuthResults{
DKIM: DKIMAuthResult{
Domain: "",
Result: "",
Selector: "",
},
SPF: SPFAuthResult{
Domain: "",
Result: "",
Scope: "",
DKIM: nil,
SPF: []SPFAuthResult{
{
Domain: "",
Result: "",
Scope: "",
},
},
},
},
Expand All @@ -259,6 +270,6 @@ func TestReadParse_Empty(t *testing.T) {
}

if !reflect.DeepEqual(out, xmlEmptyReport) {
t.Errorf("ReadParse(%v): parsed structs are invalid: %+v", testFile, out)
t.Errorf("ReadParse(%v): parsed structs are invalid:\nGOT:\n%#v\nWANT:\n%#v", testFile, out, xmlEmptyReport)
}
}
20 changes: 12 additions & 8 deletions pkg/dmarc/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ func TestReport_MergeRecord(t *testing.T) {
EnvelopeFrom: "",
},
AuthResults: AuthResults{
DKIM: DKIMAuthResult{
Domain: "test3.net",
Result: "fail",
Selector: "selector",
DKIM: []DKIMAuthResult{
{
Domain: "test3.net",
Result: "fail",
Selector: "selector",
},
},
SPF: SPFAuthResult{
Domain: "test3.net",
Result: "softfail",
Scope: "mfrom",
SPF: []SPFAuthResult{
{
Domain: "test3.net",
Result: "softfail",
Scope: "mfrom",
},
},
},
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/dmarc/testdata/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
</identifiers>
<auth_results>
<dkim>
<domain>test.net</domain>
<domain>test1.net</domain>
<result>fail</result>
<selector>selector1</selector>
</dkim>
<dkim>
<domain>test2.net</domain>
<result>pass</result>
<selector>selector</selector>
<selector>selector2</selector>
</dkim>
<spf>
<domain>test.net</domain>
Expand Down
Binary file modified pkg/dmarc/testdata/test.xml.gz
Binary file not shown.
Binary file modified pkg/dmarc/testdata/test.xml.gz.gz
Binary file not shown.
Binary file modified pkg/dmarc/testdata/test.xml.zip
Binary file not shown.
9 changes: 7 additions & 2 deletions pkg/dmarc/testdata/test2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
</identifiers>
<auth_results>
<dkim>
<domain>test.net</domain>
<domain>test1.net</domain>
<result>fail</result>
<selector>selector1</selector>
</dkim>
<dkim>
<domain>test2.net</domain>
<result>pass</result>
<selector>selector</selector>
<selector>selector2</selector>
</dkim>
<spf>
<domain>test.net</domain>
Expand Down

0 comments on commit 96ba341

Please sign in to comment.