cookie ready
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
package session
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrestashopCookieDomain(t *testing.T) {
|
||||
if got := prestashopCookieDomain("localhost", nil); got != "" {
|
||||
@@ -25,3 +31,61 @@ func TestURIMatchesRequest(t *testing.T) {
|
||||
t.Fatalf("unexpected match for different shop URI")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCookieDomainSourcePrefersDatabaseDomain(t *testing.T) {
|
||||
shop := &cookieShopContext{
|
||||
Domain: "shop.example.com",
|
||||
DomainSSL: "secure.example.com",
|
||||
}
|
||||
|
||||
if got := cookieDomainSource(shop, "proxy.internal"); got != "secure.example.com" {
|
||||
t.Fatalf("cookieDomainSource() = %q, want %q", got, "secure.example.com")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCookieDomainSourceKeepsMatchingDatabaseHost(t *testing.T) {
|
||||
shop := &cookieShopContext{
|
||||
Domain: "shop.example.com",
|
||||
DomainSSL: "secure.example.com",
|
||||
}
|
||||
|
||||
if got := cookieDomainSource(shop, "shop.example.com"); got != "shop.example.com" {
|
||||
t.Fatalf("cookieDomainSource() = %q, want %q", got, "shop.example.com")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverrideCookieHashDomain(t *testing.T) {
|
||||
if got := overrideCookieHashDomain(".Example.com"); got != "example.com" {
|
||||
t.Fatalf("overrideCookieHashDomain() = %q, want %q", got, "example.com")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveCookieNameReturnsExplicitOverride(t *testing.T) {
|
||||
service := NewService(nil, "ps_", "1.7.3", "PrestaShop-fixed", "")
|
||||
|
||||
got, err := service.ResolveCookieName(context.Background(), httptest.NewRequest("GET", "https://shop.example.com/", nil))
|
||||
if err != nil {
|
||||
t.Fatalf("ResolveCookieName() error = %v", err)
|
||||
}
|
||||
if got != "PrestaShop-fixed" {
|
||||
t.Fatalf("ResolveCookieName() = %q, want %q", got, "PrestaShop-fixed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomainCookieOverrideParticipatesInHash(t *testing.T) {
|
||||
sum := md5.Sum([]byte("1.7.3" + "ps-s1" + overrideCookieHashDomain(".example.com")))
|
||||
got := fmt.Sprintf("PrestaShop-%x", sum)
|
||||
want := "PrestaShop-1e5aa4f42a55532134a4e84017cdf643"
|
||||
if got != want {
|
||||
t.Fatalf("derived cookie name = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeCookiePath(t *testing.T) {
|
||||
if got := normalizeCookiePath(""); got != "/" {
|
||||
t.Fatalf("normalizeCookiePath(\"\") = %q, want %q", got, "/")
|
||||
}
|
||||
if got := normalizeCookiePath("shop"); got != "/shop/" {
|
||||
t.Fatalf("normalizeCookiePath(\"shop\") = %q, want %q", got, "/shop/")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user