-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite of the Authentication-Results header parser for a complete RFC 8601 implementation. Ignore any header comments in parenthesis. Allow escape sequences and semi-colons in comments and quoted strings as values. Fixes: #32
- Loading branch information
Showing
2 changed files
with
259 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,22 @@ var parseTests = []msgauthTest{ | |
&SPFResult{Value: ResultPass, From: "example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
"dkim=pass reason=\"good signature\" [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&DKIMResult{Value: ResultPass, Reason: "good signature", Identifier: "@mail-router.example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
"dkim=pass reason=\"good; signature\" [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&DKIMResult{Value: ResultPass, Reason: "good; signature", Identifier: "@mail-router.example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5) [email protected];", | ||
|
@@ -32,6 +48,63 @@ var parseTests = []msgauthTest{ | |
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5) [email protected];" + | ||
" spf=pass smtp.mailfrom=example.net", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
&SPFResult{Value: ResultPass, From: "example.net"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5 (comment inside comment)) [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5; comment with semicolon) [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "example.com;" + | ||
" auth=pass (cram-md5 \\( comment with escaped char) [email protected];", | ||
identifier: "example.com", | ||
results: []Result{ | ||
&AuthResult{Value: ResultPass, Auth: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
value: "foo.example.net (foobar) 1 (baz);" + | ||
" dkim (Because I like it) / 1 (One yay) = (wait for it) fail" + | ||
" policy (A dot can go here) . (like that) expired" + | ||
" (this surprised me) = (as I wasn't expecting it) 1362471462", | ||
identifier: "foo.example.net", | ||
results: []Result{ | ||
&DKIMResult{Value: ResultFail, Reason: "", Domain: "", Identifier: ""}, | ||
}, | ||
}, | ||
} | ||
|
||
var mustFailParseTests = []msgauthTest{ | ||
{ | ||
value: " ; ", | ||
identifier: "", | ||
results: nil, | ||
}, | ||
{ | ||
value: "example.com 2; none", | ||
identifier: "example.com", | ||
results: nil, | ||
}, | ||
} | ||
|
||
func TestParse(t *testing.T) { | ||
|
@@ -51,4 +124,10 @@ func TestParse(t *testing.T) { | |
} | ||
} | ||
} | ||
for _, test := range mustFailParseTests { | ||
_, _, err := Parse(test.value) | ||
if err == nil { | ||
t.Errorf("Expected an error when parsing header, but got none.") | ||
} | ||
} | ||
} |