mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 05:37:43 +00:00
fix(origin): fall back to ExternalSecure (#7228)
* fix(origin): fall back to ExternalSecure * avoid middleware.Middleware * avoid else * lint
This commit is contained in:
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
func Test_composeOrigin(t *testing.T) {
|
||||
type args struct {
|
||||
h http.Header
|
||||
h http.Header
|
||||
fallBackToHttps bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -24,6 +25,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"Forwarded": []string{"proto=https"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://host.header",
|
||||
}, {
|
||||
@@ -32,6 +34,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"Forwarded": []string{"host=forwarded.host"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "http://forwarded.host",
|
||||
}, {
|
||||
@@ -40,6 +43,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"Forwarded": []string{"proto=https;host=forwarded.host"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://forwarded.host",
|
||||
}, {
|
||||
@@ -48,6 +52,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"Forwarded": []string{"proto=https;host=forwarded.host, proto=http;host=forwarded.host2"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://forwarded.host",
|
||||
}, {
|
||||
@@ -56,6 +61,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"Forwarded": []string{"proto=https;host=forwarded.host, proto=http"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://forwarded.host",
|
||||
}, {
|
||||
@@ -64,14 +70,37 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"Forwarded": []string{"proto=http", "proto=https;host=forwarded.host", "proto=http"},
|
||||
},
|
||||
fallBackToHttps: true,
|
||||
},
|
||||
want: "http://forwarded.host",
|
||||
}, {
|
||||
name: "x-forwarded-proto",
|
||||
name: "x-forwarded-proto https",
|
||||
args: args{
|
||||
h: http.Header{
|
||||
"X-Forwarded-Proto": []string{"https"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://host.header",
|
||||
}, {
|
||||
name: "x-forwarded-proto http",
|
||||
args: args{
|
||||
h: http.Header{
|
||||
"X-Forwarded-Proto": []string{"http"},
|
||||
},
|
||||
fallBackToHttps: true,
|
||||
},
|
||||
want: "http://host.header",
|
||||
}, {
|
||||
name: "fallback to http",
|
||||
args: args{
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "http://host.header",
|
||||
}, {
|
||||
name: "fallback to https",
|
||||
args: args{
|
||||
fallBackToHttps: true,
|
||||
},
|
||||
want: "https://host.header",
|
||||
}, {
|
||||
@@ -80,6 +109,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
h: http.Header{
|
||||
"X-Forwarded-Host": []string{"x-forwarded.host"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "http://x-forwarded.host",
|
||||
}, {
|
||||
@@ -89,6 +119,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
"X-Forwarded-Proto": []string{"https"},
|
||||
"X-Forwarded-Host": []string{"x-forwarded.host"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://x-forwarded.host",
|
||||
}, {
|
||||
@@ -98,6 +129,7 @@ func Test_composeOrigin(t *testing.T) {
|
||||
"Forwarded": []string{"host=forwarded.host"},
|
||||
"X-Forwarded-Host": []string{"x-forwarded.host"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "http://forwarded.host",
|
||||
}, {
|
||||
@@ -107,16 +139,20 @@ func Test_composeOrigin(t *testing.T) {
|
||||
"Forwarded": []string{"host=forwarded.host"},
|
||||
"X-Forwarded-Proto": []string{"https"},
|
||||
},
|
||||
fallBackToHttps: false,
|
||||
},
|
||||
want: "https://forwarded.host",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, composeOrigin(&http.Request{
|
||||
Host: "host.header",
|
||||
Header: tt.args.h,
|
||||
}), "headers: %+v", tt.args.h)
|
||||
assert.Equalf(t, tt.want, composeOrigin(
|
||||
&http.Request{
|
||||
Host: "host.header",
|
||||
Header: tt.args.h,
|
||||
},
|
||||
tt.args.fallBackToHttps,
|
||||
), "headers: %+v, fallBackToHttps: %t", tt.args.h, tt.args.fallBackToHttps)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user