Skip to content

Commit 6328e5d

Browse files
authored
Merge pull request #769 from jmpsec/fix-api-cli-misc
Multiple fixes in `osctrl-cli` and `osctrl-api`
2 parents 7c29b2d + fce4286 commit 6328e5d

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

β€Žcmd/api/main.goβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ func osctrlAPIService() {
266266
muxAPI.HandleFunc("GET "+_apiPath(checksNoAuthPath), handlersApi.CheckHandlerNoAuth)
267267

268268
// ///////////////////////// UNAUTHENTICATED
269-
muxAPI.Handle(
270-
"POST "+_apiPath(apiLoginPath)+"/{env}",
271-
handlerAuthCheck(http.HandlerFunc(handlersApi.LoginHandler), flagParams.Service.Auth, flagParams.JWT.JWTSecret))
269+
muxAPI.HandleFunc("POST "+_apiPath(apiLoginPath)+"/{env}", handlersApi.LoginHandler)
272270
// ///////////////////////// AUTHENTICATED
273271
// API: check auth
274272
muxAPI.Handle(

β€Žcmd/cli/main.goβ€Ž

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,11 @@ func init() {
10561056
Aliases: []string{"u"},
10571057
Usage: "User to be used in login",
10581058
},
1059+
&cli.StringFlag{
1060+
Name: "url",
1061+
Aliases: []string{"U"},
1062+
Usage: "URL to be used in login",
1063+
},
10591064
&cli.StringFlag{
10601065
Name: "environment",
10611066
Aliases: []string{"e"},
@@ -1953,13 +1958,16 @@ func loginAPI(ctx context.Context, cmd *cli.Command) error {
19531958
showFlags(ctx, cmd)
19541959
zerolog.SetGlobalLevel(zerolog.DebugLevel)
19551960
}
1956-
// API URL can is needed
1961+
// API URL is needed
19571962
if apiConfig.URL == "" {
1958-
fmt.Println("❌ API URL is required")
1959-
os.Exit(1)
1963+
urlParam := cmd.String("url")
1964+
if urlParam != "" {
1965+
apiConfig.URL = urlParam
1966+
} else {
1967+
fmt.Println("❌ API URL is required")
1968+
os.Exit(1)
1969+
}
19601970
}
1961-
// Initialize API
1962-
osctrlAPI = CreateAPI(apiConfig, insecureFlag)
19631971
// We need credentials
19641972
username := cmd.String("username")
19651973
if username == "" {
@@ -1978,6 +1986,8 @@ func loginAPI(ctx context.Context, cmd *cli.Command) error {
19781986
return fmt.Errorf("error reading password %w", err)
19791987
}
19801988
fmt.Println()
1989+
// Initialize API
1990+
osctrlAPI = CreateAPI(apiConfig, insecureFlag)
19811991
apiResponse, err := osctrlAPI.PostLogin(env, username, string(passwordByte), expHours)
19821992
if err != nil {
19831993
return fmt.Errorf("error in login %w", err)

β€Žtools/api_tester.pyβ€Ž

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,11 @@ def run_all_tests(self, skip_auth: bool = False):
417417
if self.env_uuid:
418418
self.test("Get all queries", "GET",
419419
f"{API_PREFIX}/queries/{self.env_uuid}",
420+
expected_status=[200, 404],
420421
skip_if_no_token=True)
421422
self.test("Get all queries (alt endpoint)", "GET",
422423
f"{API_PREFIX}/all-queries/{self.env_uuid}",
424+
expected_status=[200, 404],
423425
skip_if_no_token=True)
424426
print()
425427

@@ -446,19 +448,37 @@ def run_all_tests(self, skip_auth: bool = False):
446448
self.print_summary()
447449

448450
def print_summary(self):
449-
"""Print test summary"""
451+
"""Print test summary with emojis"""
450452
total = self.passed + self.failed + self.skipped
451-
self.log(f"\n{Colors.BOLD}=== Test Summary ==={Colors.RESET}")
452-
self.log(f"Total tests: {total}")
453-
self.log(f"{Colors.GREEN}Passed: {self.passed}{Colors.RESET}")
454-
self.log(f"{Colors.RED}Failed: {self.failed}{Colors.RESET}")
455-
self.log(f"{Colors.YELLOW}Skipped: {self.skipped}{Colors.RESET}")
453+
pass_rate = (self.passed / total * 100) if total > 0 else 0
454+
455+
self.log(f"\n{Colors.BOLD}{'='*50}{Colors.RESET}")
456+
self.log(f"{Colors.BOLD}πŸ“Š Test Summary{Colors.RESET}")
457+
self.log(f"{Colors.BOLD}{'='*50}{Colors.RESET}\n")
458+
459+
self.log(f"πŸ“ˆ Total tests: {total}")
460+
self.log(f"{Colors.GREEN}βœ… Passed: {self.passed} ({pass_rate:.1f}%){Colors.RESET}")
461+
self.log(f"{Colors.RED}❌ Failed: {self.failed}{Colors.RESET}")
462+
self.log(f"{Colors.YELLOW}⏭️ Skipped: {self.skipped}{Colors.RESET}")
456463

457464
if self.failed > 0:
458-
self.log(f"\n{Colors.BOLD}Failed tests:{Colors.RESET}")
465+
self.log(f"\n{Colors.BOLD}{'='*50}{Colors.RESET}")
466+
self.log(f"{Colors.BOLD}❌ Failed tests:{Colors.RESET}")
467+
self.log(f"{Colors.BOLD}{'='*50}{Colors.RESET}")
459468
for result in self.test_results:
460469
if result['status'] == 'failed':
461-
self.log(f" - {result['name']}: {result['message']}", Colors.RED)
470+
self.log(f" πŸ”΄ {result['name']}", Colors.RED)
471+
self.log(f" └─ {result['message']}", Colors.RED)
472+
473+
# Overall result
474+
self.log(f"\n{Colors.BOLD}{'='*50}{Colors.RESET}")
475+
if self.failed == 0 and self.passed > 0:
476+
self.log(f"{Colors.GREEN}{Colors.BOLD}πŸŽ‰ All tests passed!{Colors.RESET}")
477+
elif self.failed > 0:
478+
self.log(f"{Colors.RED}{Colors.BOLD}⚠️ Some tests failed!{Colors.RESET}")
479+
else:
480+
self.log(f"{Colors.YELLOW}{Colors.BOLD}⚠️ No tests were run{Colors.RESET}")
481+
self.log(f"{Colors.BOLD}{'='*50}{Colors.RESET}\n")
462482

463483
# Exit with appropriate code
464484
if self.failed > 0:

0 commit comments

Comments
Β (0)