1 parent
8c4d463f1e
commit
de13d851a8
75 files changed
+4656
-442
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDockerEnvironmentCredentialsAndServerSlots(t *testing.T) {
|
||||
t.Setenv("EASYDNS_UI_PASSWORD", "a-strong-admin-password-123")
|
||||
t.Setenv("EASYDNS_UI_SESSION_AUTO", "true")
|
||||
t.Setenv("EASYDNS_UI_SESSION_KEY_FILE", filepath.Join(t.TempDir(), "session.key"))
|
||||
t.Setenv("EASYDNS_API_URL", "https://primary.example.net:9953")
|
||||
t.Setenv("EASYDNS_API_TOKEN", "primary-token-from-env")
|
||||
t.Setenv("EASYDNS_UI_MULTISERVER", "true")
|
||||
t.Setenv("EASYDNS_UI_ALLOW_INSECURE_HTTP", "true")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_NAME", "Secondary One")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_ROLE", "secondary")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_URL", "http://dns-secondary:9953")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_TOKEN", "secondary-token-from-env")
|
||||
c, err := Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.Password != "a-strong-admin-password-123" || c.APIToken != "primary-token-from-env" || !c.SessionAuto || !c.MultiServer || !c.MultiServerExplicit || !c.AllowInsecureHTTP {
|
||||
t.Fatalf("environment not loaded correctly: %#v", c)
|
||||
}
|
||||
if len(c.Servers) != 1 || c.Servers[0].Token != "secondary-token-from-env" || c.Servers[0].Role != "secondary" {
|
||||
t.Fatalf("remote slot not loaded: %#v", c.Servers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectShortPasswordAndIncompleteRemoteSlot(t *testing.T) {
|
||||
t.Setenv("EASYDNS_UI_PASSWORD", "too-short")
|
||||
t.Setenv("EASYDNS_UI_SESSION_AUTO", "true")
|
||||
if _, err := Load(); err == nil || !strings.Contains(err.Error(), "at least 16") {
|
||||
t.Fatalf("short password accepted: %v", err)
|
||||
}
|
||||
t.Setenv("EASYDNS_UI_PASSWORD", "long-enough-password-123")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_NAME", "Secondary One")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_URL", "https://dns-secondary.example.net:9953")
|
||||
t.Setenv("EASYDNS_UI_SERVER_1_TOKEN", "")
|
||||
if _, err := Load(); err == nil || !strings.Contains(err.Error(), "incomplete server slot") {
|
||||
t.Fatalf("incomplete server accepted: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user