fix: force file urls to https
This commit is contained in:
@@ -74,6 +74,51 @@ func TestAuthFileRequestFromSessionRequiresTenant(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeUploadURL(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "public http becomes https",
|
||||
in: "http://api.118im.com/v0/file/s/abc.jpg",
|
||||
want: "https://api.118im.com/v0/file/s/abc.jpg",
|
||||
},
|
||||
{
|
||||
name: "query preserved",
|
||||
in: "http://cdn.example.com/a/b.png?x=1",
|
||||
want: "https://cdn.example.com/a/b.png?x=1",
|
||||
},
|
||||
{
|
||||
name: "relative unchanged",
|
||||
in: "/v0/file/s/abc.jpg",
|
||||
want: "/v0/file/s/abc.jpg",
|
||||
},
|
||||
{
|
||||
name: "https unchanged",
|
||||
in: "https://api.118im.com/v0/file/s/abc.jpg",
|
||||
want: "https://api.118im.com/v0/file/s/abc.jpg",
|
||||
},
|
||||
{
|
||||
name: "localhost unchanged",
|
||||
in: "http://localhost:6060/v0/file/s/abc.jpg",
|
||||
want: "http://localhost:6060/v0/file/s/abc.jpg",
|
||||
},
|
||||
{
|
||||
name: "private ip unchanged",
|
||||
in: "http://10.42.0.1/v0/file/s/abc.jpg",
|
||||
want: "http://10.42.0.1/v0/file/s/abc.jpg",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := normalizeUploadURL(tc.in); got != tc.want {
|
||||
t.Fatalf("normalizeUploadURL(%q)=%q, want %q", tc.in, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthFileRequestFromTokenReturnsPrincipal(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
Reference in New Issue
Block a user