Skip to content

Commit 4b6445b

Browse files
committed
Fix: reject --source-org with --source-app when --source-space is missing
When a user specifies --source-org with --source-app but omits --source-space, validateSourceFlags() previously passed (treating --source-app as the sole primary flag), and resolveSource() silently ignored --source-org, resolving the app in the currently targeted space. Add a pre-check in validateSourceFlags() that returns RequiredFlagsError (--source-org and --source-space must be used together) whenever --source-org is combined with --source-app but --source-space is absent.
1 parent b711bd9 commit 4b6445b

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

command/v7/add_route_policy_command_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ var _ = Describe("add-route-policy Command", func() {
8080
})
8181
})
8282

83+
When("--source-org is used with --source-app but without --source-space", func() {
84+
BeforeEach(func() {
85+
cmd.RoutePolicySourceFlags = RoutePolicySourceFlags{
86+
SourceApp: "my-app",
87+
SourceOrg: "my-org",
88+
}
89+
})
90+
91+
It("returns a RequiredFlagsError for --source-space", func() {
92+
Expect(executeErr).To(MatchError(translatableerror.RequiredFlagsError{
93+
Arg1: "--source-org",
94+
Arg2: "--source-space",
95+
}))
96+
})
97+
})
98+
8399
When("checking the target fails", func() {
84100
BeforeEach(func() {
85101
fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: "faceman"})

command/v7/remove_route_policy_command_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ var _ = Describe("remove-route-policy Command", func() {
8181
})
8282
})
8383

84+
When("--source-org is used with --source-app but without --source-space", func() {
85+
BeforeEach(func() {
86+
cmd.RoutePolicySourceFlags = RoutePolicySourceFlags{
87+
SourceApp: "my-app",
88+
SourceOrg: "my-org",
89+
}
90+
})
91+
92+
It("returns a RequiredFlagsError for --source-space", func() {
93+
Expect(executeErr).To(MatchError(translatableerror.RequiredFlagsError{
94+
Arg1: "--source-org",
95+
Arg2: "--source-space",
96+
}))
97+
})
98+
})
99+
84100
When("checking the target fails", func() {
85101
BeforeEach(func() {
86102
fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: "faceman"})

command/v7/route_policy_source_flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func (f RoutePolicySourceFlags) validateSourceFlags() error {
3939
sourceFlags = append(sourceFlags, "--source-any")
4040
}
4141

42+
// --source-org requires --source-space when used with --source-app
43+
if f.SourceOrg != "" && f.SourceApp != "" && f.SourceSpace == "" {
44+
return translatableerror.RequiredFlagsError{
45+
Arg1: "--source-org",
46+
Arg2: "--source-space",
47+
}
48+
}
49+
4250
if len(sourceFlags) == 0 {
4351
return translatableerror.RequiredArgumentError{
4452
ArgumentName: "one of: --source-app, --source-space, --source-org, --source-any, or --source",

0 commit comments

Comments
 (0)