package customer import ( "net/http" "testing" ) func TestParseMoneyCentsExact(t *testing.T) { cases := map[string]int64{ "0": 0, "1": 100, "1.2": 120, "1.20": 120, "499.99": 49999, } for in, want := range cases { got, err := parseMoneyCents(in) if err != nil || got != want { t.Fatalf("parseMoneyCents(%q) = %d, %v; want %d", in, got, err, want) } } for _, in := range []string{"", "-1.00", "+1.00", "1.234", "1,00", "abc"} { if _, err := parseMoneyCents(in); err == nil { t.Fatalf("parseMoneyCents(%q) should fail", in) } } } func TestCustomerCookieUsesLaxAndAdminStrict(t *testing.T) { s := &Service{} if got := s.cookieSameSite(customerCookie); got != http.SameSiteLaxMode { t.Fatalf("customer cookie SameSite = %v; want Lax", got) } if got := s.cookieSameSite(csAdminCookie); got != http.SameSiteStrictMode { t.Fatalf("admin cookie SameSite = %v; want Strict", got) } } func TestAdminCookieSecureAutoForVPNHTTPAndHTTPSProxy(t *testing.T) { s := &Service{cfg: Config{CookieSecure: true, AdminCookieSecureMode: "auto"}} httpReq, err := http.NewRequest(http.MethodGet, "http://192.168.16.3:8091/admin", nil) if err != nil { t.Fatal(err) } if s.cookieSecure(httpReq, csAdminCookie) { t.Fatal("admin cookie should not be Secure for direct HTTP/VPN access in auto mode") } if !s.cookieSecure(httpReq, customerCookie) { t.Fatal("public customer cookie must remain Secure") } httpsProxyReq, err := http.NewRequest(http.MethodGet, "http://customer-service:8091/admin", nil) if err != nil { t.Fatal(err) } httpsProxyReq.Header.Set("X-Forwarded-Proto", "https") if !s.cookieSecure(httpsProxyReq, csAdminCookie) { t.Fatal("admin cookie should be Secure behind an HTTPS proxy in auto mode") } }