Skip to content

Commit c234b92

Browse files
committed
Can't push apps with app manifests if routes were shared
Move app and route space match to common method
1 parent 0181fe7 commit c234b92

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

app/actions/manifest_route_update.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ def find_or_create_valid_route(app, manifest_route, user_audit_info)
9292
domain: existing_domain,
9393
manifest_triggered: true
9494
)
95-
elsif route.space.guid != app.space_guid
96-
# check if route is shared with space
97-
spaces = route.shared_spaces
98-
raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') if spaces.blank? || spaces.none? { |space| space.values[:id] == app.space.id }
95+
elsif route.app_spaces_no_match?(app)
96+
raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces')
9997
elsif manifest_route[:options] && route[:options] != manifest_route[:options]
10098
# remove nil values from options
10199
manifest_route[:options] = manifest_route[:options].compact

app/controllers/v3/routes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def validate_app_guids!(apps_hash, desired_app_guids)
362362
end
363363

364364
def validate_app_spaces!(apps_hash, route)
365-
return unless apps_hash.values.any? { |app| app.space != route.space && route.shared_spaces.exclude?(app.space) }
365+
return unless apps_hash.values.any? { |app| route.app_spaces_no_match?(app) }
366366

367367
unprocessable!("Routes destinations must be in either the route's space or the route's shared spaces")
368368
end

app/models/runtime/route.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ def self.user_visibility_filter(user)
194194
}
195195
end
196196

197+
def app_spaces_no_match?(app)
198+
app.space != space && shared_spaces.exclude?(app.space)
199+
end
200+
197201
delegate :in_suspended_org?, to: :space
198202

199203
def tcp?

spec/unit/models/runtime/route_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,5 +1570,35 @@ def assert_invalid_path(path)
15701570
end
15711571
end
15721572
end
1573+
1574+
describe 'app spaces and route shared spaces' do
1575+
let!(:domain) { SharedDomain.make }
1576+
1577+
context 'when app and route space not shared' do
1578+
let!(:app) { AppModel.make }
1579+
let!(:route) { Route.make(host: 'potato', domain: domain, path: '/some-path') }
1580+
1581+
it 'no space match and not shared and returns true' do
1582+
expect(route.app_spaces_no_match?(app)).to be(true)
1583+
end
1584+
1585+
it 'match space and returns false' do
1586+
route.space = app.space
1587+
expect(route.app_spaces_no_match?(app)).to be(false)
1588+
end
1589+
end
1590+
1591+
context 'when app and route space shared' do
1592+
let!(:app) { AppModel.make }
1593+
let!(:route_share) { RouteShare.new }
1594+
let(:user_audit_info) { instance_double(UserAuditInfo).as_null_object }
1595+
let!(:route) { Route.make(host: 'potato', domain: domain, path: '/some-path') }
1596+
let!(:shared_route) { route_share.create(route, [app.space], user_audit_info) }
1597+
1598+
it 'shared space match and returns false' do
1599+
expect(route.app_spaces_no_match?(app)).to be(false)
1600+
end
1601+
end
1602+
end
15731603
end
15741604
end

0 commit comments

Comments
 (0)