0.3.49
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -89,6 +90,57 @@ func TestForYouRebuildHourIsValidated(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrustedProxiesDefaultToLoopbackAndPrivateRanges(t *testing.T) {
|
||||
t.Setenv("MEMBY_EMBY_URL", "http://emby")
|
||||
t.Setenv("MEMBY_DATABASE_URL", "postgres://memby")
|
||||
t.Setenv("MEMBY_TRUSTED_PROXIES", "")
|
||||
|
||||
cfg, err := Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
trusts := func(ip string) bool {
|
||||
addr := netip.MustParseAddr(ip)
|
||||
for _, prefix := range cfg.TrustedProxies {
|
||||
if prefix.Contains(addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
for _, want := range []string{"127.0.0.1", "10.0.0.2", "192.168.1.5"} {
|
||||
if !trusts(want) {
|
||||
t.Fatalf("%s should be trusted by default", want)
|
||||
}
|
||||
}
|
||||
if trusts("203.0.113.9") {
|
||||
t.Fatal("a public address must not be trusted by default")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrustedProxiesNoneClearsTheList(t *testing.T) {
|
||||
t.Setenv("MEMBY_EMBY_URL", "http://emby")
|
||||
t.Setenv("MEMBY_DATABASE_URL", "postgres://memby")
|
||||
t.Setenv("MEMBY_TRUSTED_PROXIES", "none")
|
||||
|
||||
cfg, err := Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.TrustedProxies == nil || len(cfg.TrustedProxies) != 0 {
|
||||
t.Fatalf("trusted proxies = %v, want an empty non-nil list", cfg.TrustedProxies)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrustedProxiesRejectGarbage(t *testing.T) {
|
||||
t.Setenv("MEMBY_EMBY_URL", "http://emby")
|
||||
t.Setenv("MEMBY_DATABASE_URL", "postgres://memby")
|
||||
t.Setenv("MEMBY_TRUSTED_PROXIES", "10.0.0.0/8, not-an-address")
|
||||
if _, err := Load(); err == nil {
|
||||
t.Fatal("expected an unparseable trusted proxy entry to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecommendationWeightsMustBeJSON(t *testing.T) {
|
||||
t.Setenv("MEMBY_EMBY_URL", "http://emby")
|
||||
t.Setenv("MEMBY_DATABASE_URL", "postgres://memby")
|
||||
|
||||
Reference in New Issue
Block a user