Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 15 additions & 5 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -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)
Expand Down
36 changes: 28 additions & 8 deletions tools/api_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down
Loading