10 "github.com/mjl-/mox/mlog"
11 "github.com/mjl-/mox/smtp"
14func TestSubjectPass(t *testing.T) {
15 log := mlog.New("subjectpass", nil)
17 key := []byte("secret token")
18 addr, _ := smtp.ParseAddress("mox@mox.example")
19 sig := Generate(log.Logger, addr, key, time.Now())
21 message := fmt.Sprintf("From: <mox@mox.example>\r\nSubject: let me in %s\r\n\r\nthe message", sig)
22 if err := Verify(log.Logger, strings.NewReader(message), key, time.Hour); err != nil {
23 t.Fatalf("verifyPassToken: %s", err)
26 if err := Verify(log.Logger, strings.NewReader(message), []byte("bad key"), time.Hour); err == nil {
27 t.Fatalf("verifyPassToken did not fail")
30 sig = Generate(log.Logger, addr, key, time.Now().Add(-time.Hour-257))
31 message = fmt.Sprintf("From: <mox@mox.example>\r\nSubject: let me in %s\r\n\r\nthe message", sig)
32 if err := Verify(log.Logger, strings.NewReader(message), key, time.Hour); !errors.Is(err, ErrExpired) {
33 t.Fatalf("verifyPassToken should have expired")