From 82b716dba95463f058db618c4535b80a071a25b4 Mon Sep 17 00:00:00 2001 From: Javier Marcos <1271349+javuto@users.noreply.github.com> Date: Sun, 28 Dec 2025 15:37:52 +0100 Subject: [PATCH 1/2] Multiple fixes in osctrl-cli and osctrl-api --- cmd/api/main.go | 4 +--- cmd/cli/main.go | 18 ++++++++++++++---- tools/api_tester.py | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/cmd/api/main.go b/cmd/api/main.go index d31b94de..7e8531ae 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -266,9 +266,7 @@ func osctrlAPIService() { muxAPI.HandleFunc("GET "+_apiPath(checksNoAuthPath), handlersApi.CheckHandlerNoAuth) // ///////////////////////// UNAUTHENTICATED - muxAPI.Handle( - "POST "+_apiPath(apiLoginPath)+"/{env}", - handlerAuthCheck(http.HandlerFunc(handlersApi.LoginHandler), flagParams.Service.Auth, flagParams.JWT.JWTSecret)) + muxAPI.HandleFunc("POST "+_apiPath(apiLoginPath)+"/{env}", handlersApi.LoginHandler) // ///////////////////////// AUTHENTICATED // API: check auth muxAPI.Handle( diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 5eb9a788..f7103ab3 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -1056,6 +1056,11 @@ func init() { Aliases: []string{"u"}, Usage: "User to be used in login", }, + &cli.StringFlag{ + Name: "url", + Aliases: []string{"U"}, + Usage: "URL to be used in login", + }, &cli.StringFlag{ Name: "environment", Aliases: []string{"e"}, @@ -1955,11 +1960,14 @@ func loginAPI(ctx context.Context, cmd *cli.Command) error { } // API URL can is needed if apiConfig.URL == "" { - fmt.Println("❌ API URL is required") - os.Exit(1) + urlParam := cmd.String("url") + if urlParam != "" { + apiConfig.URL = urlParam + } else { + fmt.Println("❌ API URL is required") + os.Exit(1) + } } - // Initialize API - osctrlAPI = CreateAPI(apiConfig, insecureFlag) // We need credentials username := cmd.String("username") if username == "" { @@ -1978,6 +1986,8 @@ func loginAPI(ctx context.Context, cmd *cli.Command) error { return fmt.Errorf("error reading password %w", err) } fmt.Println() + // Initialize API + osctrlAPI = CreateAPI(apiConfig, insecureFlag) apiResponse, err := osctrlAPI.PostLogin(env, username, string(passwordByte), expHours) if err != nil { return fmt.Errorf("error in login %w", err) diff --git a/tools/api_tester.py b/tools/api_tester.py index 3daf0821..6fdfcfc4 100755 --- a/tools/api_tester.py +++ b/tools/api_tester.py @@ -417,9 +417,11 @@ def run_all_tests(self, skip_auth: bool = False): if self.env_uuid: self.test("Get all queries", "GET", f"{API_PREFIX}/queries/{self.env_uuid}", + expected_status=[200, 404], skip_if_no_token=True) self.test("Get all queries (alt endpoint)", "GET", f"{API_PREFIX}/all-queries/{self.env_uuid}", + expected_status=[200, 404], skip_if_no_token=True) print() @@ -446,19 +448,37 @@ def run_all_tests(self, skip_auth: bool = False): self.print_summary() def print_summary(self): - """Print test summary""" + """Print test summary with emojis""" total = self.passed + self.failed + self.skipped - self.log(f"\n{Colors.BOLD}=== Test Summary ==={Colors.RESET}") - self.log(f"Total tests: {total}") - self.log(f"{Colors.GREEN}Passed: {self.passed}{Colors.RESET}") - self.log(f"{Colors.RED}Failed: {self.failed}{Colors.RESET}") - self.log(f"{Colors.YELLOW}Skipped: {self.skipped}{Colors.RESET}") + pass_rate = (self.passed / total * 100) if total > 0 else 0 + + self.log(f"\n{Colors.BOLD}{'='*50}{Colors.RESET}") + self.log(f"{Colors.BOLD}📊 Test Summary{Colors.RESET}") + self.log(f"{Colors.BOLD}{'='*50}{Colors.RESET}\n") + + self.log(f"📈 Total tests: {total}") + self.log(f"{Colors.GREEN}✅ Passed: {self.passed} ({pass_rate:.1f}%){Colors.RESET}") + self.log(f"{Colors.RED}❌ Failed: {self.failed}{Colors.RESET}") + self.log(f"{Colors.YELLOW}⏭️ Skipped: {self.skipped}{Colors.RESET}") if self.failed > 0: - self.log(f"\n{Colors.BOLD}Failed tests:{Colors.RESET}") + self.log(f"\n{Colors.BOLD}{'='*50}{Colors.RESET}") + self.log(f"{Colors.BOLD}❌ Failed tests:{Colors.RESET}") + self.log(f"{Colors.BOLD}{'='*50}{Colors.RESET}") for result in self.test_results: if result['status'] == 'failed': - self.log(f" - {result['name']}: {result['message']}", Colors.RED) + self.log(f" 🔴 {result['name']}", Colors.RED) + self.log(f" └─ {result['message']}", Colors.RED) + + # Overall result + self.log(f"\n{Colors.BOLD}{'='*50}{Colors.RESET}") + if self.failed == 0 and self.passed > 0: + self.log(f"{Colors.GREEN}{Colors.BOLD}🎉 All tests passed!{Colors.RESET}") + elif self.failed > 0: + self.log(f"{Colors.RED}{Colors.BOLD}⚠️ Some tests failed!{Colors.RESET}") + else: + self.log(f"{Colors.YELLOW}{Colors.BOLD}⚠️ No tests were run{Colors.RESET}") + self.log(f"{Colors.BOLD}{'='*50}{Colors.RESET}\n") # Exit with appropriate code if self.failed > 0: From fce42863ee3291e6234bb8e7972fd9c3247991e0 Mon Sep 17 00:00:00 2001 From: Javier Marcos <1271349+javuto@users.noreply.github.com> Date: Sun, 28 Dec 2025 15:46:37 +0100 Subject: [PATCH 2/2] Update cmd/cli/main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cmd/cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index f7103ab3..0e11cc5d 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -1958,7 +1958,7 @@ func loginAPI(ctx context.Context, cmd *cli.Command) error { showFlags(ctx, cmd) zerolog.SetGlobalLevel(zerolog.DebugLevel) } - // API URL can is needed + // API URL is needed if apiConfig.URL == "" { urlParam := cmd.String("url") if urlParam != "" {