suporte a dynamic dns
This commit is contained in:
@@ -13,6 +13,9 @@ addr: ":9000"
|
||||
pdns_api_url: "http://pdns.example.test:8081"
|
||||
pdns_api_key: "from-file"
|
||||
pdns_server_id: "authoritative"
|
||||
database:
|
||||
mysql:
|
||||
dsn: "user:pass@tcp(mysql:3306)/pdns_admin"
|
||||
auth:
|
||||
disabled: true
|
||||
`)
|
||||
@@ -34,16 +37,23 @@ auth:
|
||||
if cfg.PDNSServerID != "authoritative" {
|
||||
t.Fatalf("unexpected server id: %q", cfg.PDNSServerID)
|
||||
}
|
||||
if cfg.Database.MySQL.DSN != "user:pass@tcp(mysql:3306)/pdns_admin" {
|
||||
t.Fatalf("unexpected mysql dsn: %q", cfg.Database.MySQL.DSN)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileEnvironmentOverridesYAML(t *testing.T) {
|
||||
clearConfigEnv(t)
|
||||
t.Setenv("PDNS_API_KEY", "from-env")
|
||||
t.Setenv("PDNS_API_URL", "http://env.example.test:8081")
|
||||
t.Setenv("DATABASE_MYSQL_DSN", "env:pass@tcp(mysql:3306)/pdns_admin")
|
||||
path := writeConfig(t, `
|
||||
pdns_api_url: "http://file.example.test:8081"
|
||||
pdns_api_key: "from-file"
|
||||
pdns_server_id: "from-file"
|
||||
database:
|
||||
mysql:
|
||||
dsn: "file:pass@tcp(mysql:3306)/pdns_admin"
|
||||
auth:
|
||||
disabled: true
|
||||
`)
|
||||
@@ -62,11 +72,15 @@ auth:
|
||||
if cfg.PDNSServerID != "from-file" {
|
||||
t.Fatalf("expected yaml server id, got %q", cfg.PDNSServerID)
|
||||
}
|
||||
if cfg.Database.MySQL.DSN != "env:pass@tcp(mysql:3306)/pdns_admin" {
|
||||
t.Fatalf("expected env mysql dsn, got %q", cfg.Database.MySQL.DSN)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileUsesDefaultsWithoutYAML(t *testing.T) {
|
||||
clearConfigEnv(t)
|
||||
t.Setenv("PDNS_API_KEY", "secret")
|
||||
t.Setenv("DATABASE_MYSQL_DSN", "user:pass@tcp(mysql:3306)/pdns_admin")
|
||||
t.Setenv("AUTH_DISABLED", "true")
|
||||
|
||||
cfg, err := LoadFile("")
|
||||
@@ -87,6 +101,7 @@ func TestLoadFileUsesDefaultsWithoutYAML(t *testing.T) {
|
||||
|
||||
func TestLoadFileRequiresAPIKey(t *testing.T) {
|
||||
clearConfigEnv(t)
|
||||
t.Setenv("DATABASE_MYSQL_DSN", "user:pass@tcp(mysql:3306)/pdns_admin")
|
||||
|
||||
_, err := LoadFile("")
|
||||
if err == nil {
|
||||
@@ -94,10 +109,24 @@ func TestLoadFileRequiresAPIKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileRequiresMySQLDSN(t *testing.T) {
|
||||
clearConfigEnv(t)
|
||||
t.Setenv("PDNS_API_KEY", "secret")
|
||||
t.Setenv("AUTH_DISABLED", "true")
|
||||
|
||||
_, err := LoadFile("")
|
||||
if err == nil {
|
||||
t.Fatal("expected missing mysql dsn error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadFileReadsLDAPConfig(t *testing.T) {
|
||||
clearConfigEnv(t)
|
||||
path := writeConfig(t, `
|
||||
pdns_api_key: "secret"
|
||||
database:
|
||||
mysql:
|
||||
dsn: "user:pass@tcp(mysql:3306)/pdns_admin"
|
||||
auth:
|
||||
ldap:
|
||||
url: ldap://ldap.example.com:389
|
||||
@@ -139,6 +168,9 @@ func TestLoadFileLDAPEnvironmentOverridesYAML(t *testing.T) {
|
||||
t.Setenv("AUTH_LDAP_BIND_PASSWORD", "from-env")
|
||||
path := writeConfig(t, `
|
||||
pdns_api_key: "secret"
|
||||
database:
|
||||
mysql:
|
||||
dsn: "user:pass@tcp(mysql:3306)/pdns_admin"
|
||||
auth:
|
||||
ldap:
|
||||
url: ldap://file.example.com:389
|
||||
@@ -162,6 +194,7 @@ auth:
|
||||
func TestLoadFileRequiresLDAPUnlessAuthDisabled(t *testing.T) {
|
||||
clearConfigEnv(t)
|
||||
t.Setenv("PDNS_API_KEY", "secret")
|
||||
t.Setenv("DATABASE_MYSQL_DSN", "user:pass@tcp(mysql:3306)/pdns_admin")
|
||||
|
||||
_, err := LoadFile("")
|
||||
if err == nil {
|
||||
@@ -252,6 +285,7 @@ func clearConfigEnv(t *testing.T) {
|
||||
"PDNS_API_URL",
|
||||
"PDNS_API_KEY",
|
||||
"PDNS_SERVER_ID",
|
||||
"DATABASE_MYSQL_DSN",
|
||||
"AUTH_DISABLED",
|
||||
"AUTH_LDAP_URL",
|
||||
"AUTH_LDAP_START_TLS",
|
||||
|
||||
Reference in New Issue
Block a user