cookie ready

This commit is contained in:
2026-05-13 22:34:11 +02:00
parent 8c4e664ca8
commit 1b53c1c199
16 changed files with 798 additions and 146 deletions
+6 -1
View File
@@ -24,6 +24,7 @@ type Config struct {
PrestaShopBaseURL string
PrestaShopProxyTarget string
PrestaShopVersion string
DomainCookie string
PrestaShopCookieKey string
PrestaShopCookieIV string
PrestaShopCookieName string
@@ -48,6 +49,7 @@ func Load() (Config, error) {
PrestaShopBaseURL: os.Getenv("PRESTASHOP_BASE_URL"),
PrestaShopProxyTarget: os.Getenv("PRESTASHOP_PROXY_TARGET"),
PrestaShopVersion: envOr("PRESTASHOP_VERSION", "1.7.3"),
DomainCookie: os.Getenv("DOMAIN_COOKIE"),
PrestaShopCookieKey: os.Getenv("PRESTASHOP_COOKIE_KEY"),
PrestaShopCookieIV: os.Getenv("PRESTASHOP_COOKIE_IV"),
PrestaShopCookieName: os.Getenv("PRESTASHOP_COOKIE_NAME"),
@@ -140,7 +142,10 @@ func (c Config) DeriveCookieName(host string) string {
return c.PrestaShopCookieName
}
domain := fallbackCookieHashDomain(host)
domain := fallbackCookieHashDomain(c.DomainCookie)
if domain == "" {
domain = fallbackCookieHashDomain(host)
}
if domain == "" {
domain = fallbackCookieHashDomain(c.PrestaShopBaseURL)
}
+28
View File
@@ -17,3 +17,31 @@ func TestDeriveCookieNameMatchesFallbackPrestashopRule(t *testing.T) {
t.Fatalf("DeriveCookieName() = %q, want %q", got, want)
}
}
func TestDeriveCookieNameUsesDomainCookieOverride(t *testing.T) {
cfg := Config{
PrestaShopVersion: "1.7.3",
DomainCookie: ".example.com",
}
got := cfg.DeriveCookieName("localhost")
sum := md5.Sum([]byte("1.7.3" + "ps-s1" + "example.com"))
want := fmt.Sprintf("PrestaShop-%x", sum)
if got != want {
t.Fatalf("DeriveCookieName() = %q, want %q", got, want)
}
}
func TestDeriveCookieNamePrefersExplicitCookieName(t *testing.T) {
cfg := Config{
PrestaShopVersion: "1.7.3",
DomainCookie: ".example.com",
PrestaShopCookieName: "PrestaShop-fixed",
}
got := cfg.DeriveCookieName("localhost")
if got != "PrestaShop-fixed" {
t.Fatalf("DeriveCookieName() = %q, want %q", got, "PrestaShop-fixed")
}
}