feat(validation): Added validation of baseURL config
This commit is contained in:
parent
03942636c8
commit
7db520a417
2 changed files with 21 additions and 6 deletions
16
cmd/app.go
16
cmd/app.go
|
|
@ -23,23 +23,27 @@ var (
|
|||
func validateBaseURL(baseURL string) error {
|
||||
url, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error parsing baseURL: '%s' with error '%s'", baseURL, err.Error())
|
||||
return fmt.Errorf("decoding error '%s'", err.Error())
|
||||
}
|
||||
|
||||
if url.Scheme == "" {
|
||||
return fmt.Errorf("Error parsing baseURL: '%s' baseURL schema should be set", baseURL)
|
||||
return fmt.Errorf("schema should be set (add https://)")
|
||||
}
|
||||
|
||||
if len(url.User.Username()) > 0 {
|
||||
return fmt.Errorf("user and or password should not be set")
|
||||
}
|
||||
|
||||
if !(url.Path == "" || url.Path == "/") {
|
||||
return fmt.Errorf("Error parsing baseURL: '%s' baseURL should not contain any path '%s'", baseURL, url.Path)
|
||||
return fmt.Errorf("should not contain any path '%s'", url.Path)
|
||||
}
|
||||
|
||||
if len(url.Query()) > 0 {
|
||||
return fmt.Errorf("Error parsing baseURL: '%s' baseURL should not contain any queries '%s'", baseURL, url.RawQuery)
|
||||
return fmt.Errorf("should not contain any queries '%s'", url.RawQuery)
|
||||
}
|
||||
|
||||
if len(url.Fragment) > 0 {
|
||||
return fmt.Errorf("Error parsing baseURL: '%s' baseURL should not contain any fragment '%s'", baseURL, url.Fragment)
|
||||
return fmt.Errorf("should not contain any fragment '%s'", url.Fragment)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -52,7 +56,7 @@ func newSDKClient() *edgeconnect.Client {
|
|||
|
||||
err := validateBaseURL(baseURL)
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing baseURL: '%s' with error '%s'", baseURL, err.Error())
|
||||
fmt.Printf("Error parsing baseURL: '%s' with error: %s\n", baseURL, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,17 @@ func TestValidateBaseURL(t *testing.T) {
|
|||
expectError: true,
|
||||
},
|
||||
|
||||
{
|
||||
name: "user set",
|
||||
input: "https://user@hub.edge.de",
|
||||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "user and password set",
|
||||
input: "https://user:password@hub.edge.de/",
|
||||
expectError: true,
|
||||
},
|
||||
|
||||
{
|
||||
name: "contains path and query",
|
||||
input: "http://hub.edge.de/index.html?a=b",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue