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
|
package controlplane
import (
"net/url"
"strings"
"testing"
"time"
)
func TestAccountActionURLKeepsAdminPathAndEncodesToken(t *testing.T) {
link, err := accountActionURL("https://console.example.test/admin/", actionVerifyEmail, "act-aigw-a+b/c")
if err != nil {
t.Fatal(err)
}
parsed, err := url.Parse(link)
if err != nil {
t.Fatal(err)
}
if parsed.Path != "/admin/" || parsed.Query().Get("action") != "verify-email" || parsed.Query().Get("token") != "act-aigw-a+b/c" {
t.Fatalf("unexpected action URL %q", link)
}
}
func TestActionMailUsesSingularDuration(t *testing.T) {
_, dayBody := actionMail("Test", actionVerifyEmail, "https://example.test", 24*time.Hour)
_, hourBody := actionMail("Test", actionPasswordReset, "https://example.test", time.Hour)
if !strings.Contains(dayBody, "1 day") || strings.Contains(dayBody, "1 days") {
t.Fatalf("unexpected day label %q", dayBody)
}
if !strings.Contains(hourBody, "1 hour") || strings.Contains(hourBody, "1 hours") {
t.Fatalf("unexpected hour label %q", hourBody)
}
}
|