fix: force file urls to https

This commit is contained in:
richjohnrambo
2026-09-16 09:52:55 +08:00
parent 9626e8ee7c
commit 1de69fcc5b
4 changed files with 90 additions and 2 deletions
+45
View File
@@ -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()