1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

Add base URL validation

This commit is contained in:
Frédéric Guillot 2018-07-07 14:01:02 -07:00
parent cda0efb731
commit 55a1e97778
2 changed files with 75 additions and 17 deletions

View file

@ -56,7 +56,7 @@ func TestCustomBaseURLWithTrailingSlash(t *testing.T) {
}
if cfg.RootURL() != "http://example.org" {
t.Fatalf(`Unexpected root URL, got "%s"`, cfg.BaseURL())
t.Fatalf(`Unexpected root URL, got "%s"`, cfg.RootURL())
}
if cfg.BasePath() != "/folder" {
@ -64,6 +64,42 @@ func TestCustomBaseURLWithTrailingSlash(t *testing.T) {
}
}
func TestBaseURLWithoutScheme(t *testing.T) {
os.Clearenv()
os.Setenv("BASE_URL", "example.org/folder/")
cfg := NewConfig()
if cfg.BaseURL() != "http://localhost" {
t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL())
}
if cfg.RootURL() != "http://localhost" {
t.Fatalf(`Unexpected root URL, got "%s"`, cfg.RootURL())
}
if cfg.BasePath() != "" {
t.Fatalf(`Unexpected base path, got "%s"`, cfg.BasePath())
}
}
func TestBaseURLWithInvalidScheme(t *testing.T) {
os.Clearenv()
os.Setenv("BASE_URL", "ftp://example.org/folder/")
cfg := NewConfig()
if cfg.BaseURL() != "http://localhost" {
t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL())
}
if cfg.RootURL() != "http://localhost" {
t.Fatalf(`Unexpected root URL, got "%s"`, cfg.RootURL())
}
if cfg.BasePath() != "" {
t.Fatalf(`Unexpected base path, got "%s"`, cfg.BasePath())
}
}
func TestDefaultBaseURL(t *testing.T) {
os.Clearenv()
cfg := NewConfig()