Live: allow connections with request host matching origin host (#38538)

This commit is contained in:
Alexander Emelin
2021-08-27 13:26:28 +03:00
committed by GitHub
parent b25eb0aa74
commit a95a40d87d
2 changed files with 20 additions and 8 deletions
+9
View File
@@ -62,6 +62,7 @@ func TestCheckOrigin(t *testing.T) {
appURL string
allowedOrigins []string
success bool
host string
}{
{
name: "empty_origin",
@@ -126,6 +127,13 @@ func TestCheckOrigin(t *testing.T) {
allowedOrigins: []string{"*"},
success: true,
},
{
name: "request_host_matches_origin_host",
origin: "http://example.com",
appURL: "https://example.com",
success: true,
host: "example.com",
},
}
for _, tc := range testCases {
@@ -141,6 +149,7 @@ func TestCheckOrigin(t *testing.T) {
checkOrigin := getCheckOriginFunc(appURL, tc.allowedOrigins, originGlobs)
r := httptest.NewRequest("GET", tc.appURL, nil)
r.Host = tc.host
r.Header.Set("Origin", tc.origin)
require.Equal(t, tc.success, checkOrigin(r),
"origin %s, appURL: %s", tc.origin, tc.appURL,