Added host URL normalization
This commit is contained in:
@@ -63,6 +63,10 @@ func (c *Configuration) Validate() error {
|
||||
if !(u.Scheme == "http" || u.Scheme == "https") {
|
||||
return fmt.Errorf("PVE host '%s' must be protocol type of HTTP or HTTPS.", host)
|
||||
}
|
||||
|
||||
if u.Hostname() == "" {
|
||||
return fmt.Errorf("PVE host '%s' must contain an IP address or DNS name.", host)
|
||||
}
|
||||
}
|
||||
|
||||
// Validate PVE token
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package configuration
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestConfigurationValidateAcceptsIPAndDNSPveHosts(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
host string
|
||||
}{
|
||||
{name: "IP address", host: "https://192.168.0.10:8006"},
|
||||
{name: "DNS name", host: "https://pve.example.com:8006"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
configuration := Configuration{
|
||||
Host: "0.0.0.0",
|
||||
PVE: PveConfiguration{
|
||||
Hosts: []string{tt.host},
|
||||
Token: PveTokenConfiguration{
|
||||
TokenId: "token",
|
||||
Secret: "secret",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := configuration.Validate(); err != nil {
|
||||
t.Fatalf("Validate() rejected %s host %q: %v", tt.name, tt.host, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user