fix cookie -- not working
This commit is contained in:
@@ -140,15 +140,15 @@ func (c Config) DeriveCookieName(host string) string {
|
||||
return c.PrestaShopCookieName
|
||||
}
|
||||
|
||||
domain := normalizedCookieDomain(host)
|
||||
domain := fallbackCookieHashDomain(host)
|
||||
if domain == "" {
|
||||
domain = normalizedCookieDomain(c.PrestaShopBaseURL)
|
||||
domain = fallbackCookieHashDomain(c.PrestaShopBaseURL)
|
||||
}
|
||||
if domain == "" {
|
||||
domain = normalizedCookieDomain(c.PrestaShopProxyTarget)
|
||||
domain = fallbackCookieHashDomain(c.PrestaShopProxyTarget)
|
||||
}
|
||||
|
||||
sum := md5.Sum([]byte(c.PrestaShopVersion + "PrestaShop" + domain))
|
||||
sum := md5.Sum([]byte(c.PrestaShopVersion + "ps-s1" + domain))
|
||||
return fmt.Sprintf("PrestaShop-%x", sum)
|
||||
}
|
||||
|
||||
@@ -256,6 +256,17 @@ func normalizedCookieDomain(input string) string {
|
||||
return value
|
||||
}
|
||||
|
||||
func fallbackCookieHashDomain(input string) string {
|
||||
value := normalizedCookieDomain(input)
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
if net.ParseIP(value) != nil || !strings.Contains(value, ".") {
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func dbDSNFromEnv() string {
|
||||
return mysqlDSN(
|
||||
firstNonEmpty(os.Getenv("PRESTASHOP_DB_HOST"), os.Getenv("DB_HOST")),
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeriveCookieNameMatchesFallbackPrestashopRule(t *testing.T) {
|
||||
cfg := Config{PrestaShopVersion: "1.7.3"}
|
||||
|
||||
got := cfg.DeriveCookieName("localhost")
|
||||
sum := md5.Sum([]byte("1.7.3" + "ps-s1"))
|
||||
want := fmt.Sprintf("PrestaShop-%x", sum)
|
||||
|
||||
if got != want {
|
||||
t.Fatalf("DeriveCookieName() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user