This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathverify_test.go
111 lines (93 loc) · 3.56 KB
/
verify_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package dkim
import (
"io"
"reflect"
"strings"
"testing"
"time"
)
const verifiedMailString = `DKIM-Signature: v=1; a=rsa-sha256; s=brisbane; d=example.com;
c=simple/simple; q=dns/txt; [email protected];
h=Received : From : To : Subject : Date : Message-ID;
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB
4nujc7YopdG5dWLSdNg6xNAZpOPr+kHxt1IrE+NahM6L/LbvaHut
KVdkLLkpVaVVQPzeRDI009SO2Il5Lu7rDNH6mZckBdrIx0orEtZV
4bmp/YzhwvcubU4=;
Received: from client1.football.example.com [192.0.2.1]
by submitserver.example.com with SUBMISSION;
Fri, 11 Jul 2003 21:01:54 -0700 (PDT)
From: Joe SixPack <[email protected]>
To: Suzie Q <[email protected]>
Subject: Is dinner ready?
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
Message-ID: <[email protected]>
Hi.
We lost the game. Are you hungry yet?
Joe.
`
var testVerification = &Verification{
Domain: "example.com",
Identifier: "[email protected]",
HeaderKeys: []string{"Received", "From", "To", "Subject", "Date", "Message-ID"},
BodyLength: -1,
}
func newMailStringReader(s string) io.Reader {
return strings.NewReader(strings.Replace(s, "\n", "\r\n", -1))
}
func TestVerify(t *testing.T) {
r := newMailStringReader(verifiedMailString)
verifications, err := Verify(r)
if err != nil {
t.Fatalf("Expected no error while verifying signature, got: %v", err)
} else if len(verifications) != 1 {
t.Fatalf("Expected exactly one verification, got %v", len(verifications))
}
v := verifications[0]
if !reflect.DeepEqual(testVerification, v) {
t.Errorf("Expected verification to be \n%+v\n but got \n%+v", testVerification, v)
}
}
const verifiedEd25519MailString = `DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed;
d=football.example.com; [email protected];
q=dns/txt; s=brisbane; t=1528637909; h=from : to :
subject : date : message-id : from : subject : date;
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
b=/gCrinpcQOoIfuHNQIbq4pgh9kyIK3AQUdt9OdqQehSwhEIug4D11Bus
Fa3bT3FY5OsU7ZbnKELq+eXdp1Q1Dw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=football.example.com; [email protected];
q=dns/txt; s=test; t=1528637909; h=from : to : subject :
date : message-id : from : subject : date;
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
b=F45dVWDfMbQDGHJFlXUNB2HKfbCeLRyhDXgFpEL8GwpsRe0IeIixNTe3
DhCVlUrSjV4BwcVcOF6+FF3Zo9Rpo1tFOeS9mPYQTnGdaSGsgeefOsk2Jz
dA+L10TeYt9BgDfQNZtKdN1WO//KgIqXP7OdEFE4LjFYNcUxZQ4FADY+8=
From: Joe SixPack <[email protected]>
To: Suzie Q <[email protected]>
Subject: Is dinner ready?
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT)
Message-ID: <[email protected]>
Hi.
We lost the game. Are you hungry yet?
Joe.`
var testEd25519Verification = &Verification{
Domain: "football.example.com",
Identifier: "@football.example.com",
HeaderKeys: []string{"from", "to", "subject", "date", "message-id", "from", "subject", "date"},
BodyLength: -1,
Time: time.Unix(1528637909, 0),
}
func TestVerify_ed25519(t *testing.T) {
r := newMailStringReader(verifiedEd25519MailString)
verifications, err := Verify(r)
if err != nil {
t.Fatalf("Expected no error while verifying signature, got: %v", err)
} else if len(verifications) != 2 {
t.Fatalf("Expected exactly two verifications, got %v", len(verifications))
}
v := verifications[0]
if !reflect.DeepEqual(testEd25519Verification, v) {
t.Errorf("Expected verification to be \n%+v\n but got \n%+v", testEd25519Verification, v)
}
}