Skip to content
Open
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
33 changes: 33 additions & 0 deletions command/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package command

import (
"encoding/json"
"fmt"
)

type LoginCommand struct {
Format string
Method string
}

func (c *LoginCommand) Run(args []string) int {
// Dummy implementation of login logic
var err error

// Simulate an error for OIDC failure
err = fmt.Errorf("OIDC authentication failed")

if err != nil {
if c.Format == "json" {
// Print JSON error payload
errJSON, _ := json.Marshal(map[string]string{"error": err.Error()})
fmt.Println(string(errJSON))
// Fix: Return non-zero status code for JSON format errors
return 1
}
fmt.Printf("Error: %v\n", err)
return 1
}

return 0
}
17 changes: 17 additions & 0 deletions command/login_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package command

import (
"testing"
)

func TestLoginCommand_Run(t *testing.T) {
cmd := &LoginCommand{
Format: "json",
Method: "oidc",
}

code := cmd.Run([]string{})
if code == 0 {
t.Fatalf("expected non-zero exit code on failure, got %d", code)
}
}