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..0e11cc5d 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"}, @@ -1953,13 +1958,16 @@ 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 == "" { - 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: