From 7db520a41769c4ac492a60677f5bf912686d5a7b Mon Sep 17 00:00:00 2001 From: Richard Robert Reitz Date: Mon, 29 Sep 2025 10:48:52 +0200 Subject: [PATCH] feat(validation): Added validation of baseURL config --- cmd/app.go | 16 ++++++++++------ cmd/app_test.go | 11 +++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/app.go b/cmd/app.go index fee8835..a9f187f 100644 --- a/cmd/app.go +++ b/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) } diff --git a/cmd/app_test.go b/cmd/app_test.go index 5f10b62..4b856ea 100644 --- a/cmd/app_test.go +++ b/cmd/app_test.go @@ -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",