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
14 changes: 9 additions & 5 deletions cmd/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func UpdateTargetCmd(cfg config.Config, newTarget string, log cli.Logger) error
}
cfg.AddTarget(target)

api := GetUnauthenticatedAPIFromConfig(cfg)
_, err := api.GetInfo()

if err != nil {
return errors.New(fmt.Sprintf("The target %s could not be set: %v", newTarget, err.Error()))
if !forceTarget {
api := GetUnauthenticatedAPIFromConfig(cfg)
_, err := api.GetInfo()
if err != nil {
return errors.New(fmt.Sprintf("The target %s could not be set: %v", newTarget, err.Error()))
}
}
Comment on lines +48 to 54
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With --force, the code skips api.GetInfo() entirely, which also means we no longer validate that newTarget is a syntactically valid URL. This can result in persisting an invalid target (e.g., missing scheme/host) that later causes panics/failures when creating a UAA client. Consider adding a lightweight URL parse/validation step that always runs (even when --force), while still skipping the network /info call.

Copilot uses AI. Check for mistakes.

config.WriteConfig(cfg)
Expand Down Expand Up @@ -77,9 +78,12 @@ var targetCmd = &cobra.Command{
},
}

var forceTarget bool

func init() {
RootCmd.AddCommand(targetCmd)
targetCmd.Flags().BoolVarP(&skipSSLValidation, "skip-ssl-validation", "k", false, "Disable security validation on requests to this target")
targetCmd.Flags().BoolVarP(&forceTarget, "force", "f", false, "Set target without verifying connectivity")
targetCmd.Annotations = make(map[string]string)
targetCmd.Annotations[INTRO_CATEGORY] = "true"
}
26 changes: 26 additions & 0 deletions cmd/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ var _ = Describe("Target", func() {
})
})

Describe("when --force is set", func() {
It("saves the target without making a connectivity check", func() {
// No handler registered — any real request would cause the test server to fail.
// We verify no /info call is made by not registering a handler and still expecting success.
session := runCommand("target", server.URL(), "--force")

Eventually(session).Should(Exit(0))
Eventually(session.Out).Should(Say("Target set to " + server.URL()))
Expect(config.ReadConfig().GetActiveTarget().BaseUrl).To(Equal(server.URL()))
})

It("saves the target even when the UAA is unreachable", func() {
session := runCommand("target", "http://does-not-exist.invalid", "--force")

Eventually(session).Should(Exit(0))
Eventually(session.Out).Should(Say("Target set to http://does-not-exist.invalid"))
Expect(config.ReadConfig().GetActiveTarget().BaseUrl).To(Equal("http://does-not-exist.invalid"))
})

It("respects --skip-ssl-validation together with --force", func() {
runCommand("target", server.URL(), "--force", "--skip-ssl-validation")

Comment on lines +141 to +142
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test relies on runCommand(...) succeeding but doesn't assert the exit code. Adding an explicit Eventually(session).Should(Exit(0)) (and capturing the session) would make failures clearer and ensure the combined --force + --skip-ssl-validation path is actually exercised successfully.

Suggested change
runCommand("target", server.URL(), "--force", "--skip-ssl-validation")
session := runCommand("target", server.URL(), "--force", "--skip-ssl-validation")
Eventually(session).Should(Exit(0))

Copilot uses AI. Check for mistakes.
Expect(config.ReadConfig().GetActiveTarget().SkipSSLValidation).To(BeTrue())
})
})

Describe("when the UAA cannot be reached", func() {
BeforeEach(func() {
server.RouteToHandler("GET", "/info",
Expand Down
4 changes: 4 additions & 0 deletions docs/commands/target.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ When called with no arguments, displays the currently targeted UAA URL and its s
| Flag | Short | Default | Description |
|------|-------|---------|-------------|
| `--skip-ssl-validation` | `-k` | `false` | Disable SSL certificate validation for requests to this target |
| `--force` | `-f` | `false` | Save the target without verifying connectivity (skip the `/info` check) |

## Global Flags

Expand All @@ -36,6 +37,9 @@ uaa target https://uaa.example.com
# Set a target, skipping SSL validation
uaa target https://uaa.example.com --skip-ssl-validation

# Set a target without checking connectivity (useful for unreachable or not-yet-running UAAs)
uaa target https://uaa.example.com --force

# Display the current target
uaa target
```
Expand Down
Loading