fix(tenant): 隔离经营租户与旧分销站点上下文
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package sitecode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
@@ -45,6 +46,22 @@ func TestFromRequest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromRequestIgnoresLegacySiteCodeInTenantScope(t *testing.T) {
|
||||
c := newTestContext(
|
||||
"GET",
|
||||
"/api/listings?distribution_site_code=query_site",
|
||||
map[string]string{
|
||||
HeaderName: "new_site",
|
||||
LegacyHeaderName: "legacy_site",
|
||||
},
|
||||
)
|
||||
c.Request = c.Request.WithContext(WithTenantScope(context.Background()))
|
||||
|
||||
if got := FromRequest(c); got != "" {
|
||||
t.Fatalf("经营租户请求不应解析旧分销站点编码, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromQueryThenHeader(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -67,6 +84,19 @@ func TestFromQueryThenHeader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromQueryThenHeaderIgnoresLegacySiteCodeInTenantScope(t *testing.T) {
|
||||
c := newTestContext(
|
||||
"GET",
|
||||
"/distribution/site-info?code=probe_site&distribution_site_code=legacy_site",
|
||||
map[string]string{HeaderName: "header_site"},
|
||||
)
|
||||
c.Request = c.Request.WithContext(WithTenantScope(context.Background()))
|
||||
|
||||
if got := FromQueryThenHeader(c); got != "" {
|
||||
t.Fatalf("经营租户请求不应探测旧分销站点, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractHost(t *testing.T) {
|
||||
cases := []struct {
|
||||
raw string
|
||||
|
||||
Reference in New Issue
Block a user