-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package dkim | ||
|
||
import ( | ||
"bytes" | ||
"math/rand" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const signedEd25519MailString = "DKIM-Signature: a=ed25519-sha256; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJ" + "\r\n" + | ||
" " + "VOzv8=; c=simple/simple; d=football.example.com; h=From:To:Subject:Date:Mes" + "\r\n" + | ||
" " + "sage-ID; s=brisbane; t=424242; v=1; b=ZduPZq83AOTqjhScIfHll6W90tMG1nf34a34Q" + "\r\n" + | ||
" " + "XKat3iFtP7NQE/3AwnHOrcsR2r5nVNoW+LeZURpT2obCthPCw==;" + "\r\n" + | ||
mailHeaderString + | ||
"\r\n" + | ||
mailBodyString | ||
|
||
func init() { | ||
randReader = rand.New(rand.NewSource(42)) | ||
} | ||
|
||
func TestSignEd25519(t *testing.T) { | ||
r := strings.NewReader(mailString) | ||
options := &SignOptions{ | ||
Domain: "football.example.com", | ||
Selector: "brisbane", | ||
Signer: testEd25519PrivateKey, | ||
} | ||
|
||
var b bytes.Buffer | ||
if err := Sign(&b, r, options); err != nil { | ||
t.Fatal("Expected no error while signing mail, got:", err) | ||
} | ||
|
||
if s := b.String(); s != signedEd25519MailString { | ||
t.Errorf("Expected signed message to be \n%v\n but got \n%v", signedEd25519MailString, s) | ||
} | ||
} | ||
|
||
func TestSignAndVerifyEd25519(t *testing.T) { | ||
r := strings.NewReader(mailString) | ||
options := &SignOptions{ | ||
Domain: "football.example.com", | ||
Selector: "brisbane", | ||
Signer: testEd25519PrivateKey, | ||
} | ||
|
||
var b bytes.Buffer | ||
if err := Sign(&b, r, options); err != nil { | ||
t.Fatal("Expected no error while signing mail, got:", err) | ||
} | ||
|
||
verifications, err := Verify(&b) | ||
if err != nil { | ||
t.Fatalf("Expected no error while verifying signature, got: %v", err) | ||
} | ||
if len(verifications) != 1 { | ||
t.Error("Expected exactly one verification") | ||
} else { | ||
v := verifications[0] | ||
if err := v.Err; err != nil { | ||
t.Errorf("Expected no error when verifying signature, got: %v", err) | ||
} | ||
if v.Domain != options.Domain { | ||
t.Errorf("Expected domain to be %q but got %q", options.Domain, v.Domain) | ||
} | ||
} | ||
} |