Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion app/actions/manifest_route_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def find_or_create_valid_route(app, manifest_route, user_audit_info)
domain: existing_domain,
manifest_triggered: true
)
elsif route.space.guid != app.space_guid
elsif route.app_spaces_no_match?(app)
raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces')
elsif manifest_route[:options] && route[:options] != manifest_route[:options]
# remove nil values from options
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v3/routes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def validate_app_guids!(apps_hash, desired_app_guids)
end

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

unprocessable!("Routes destinations must be in either the route's space or the route's shared spaces")
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/runtime/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def self.user_visibility_filter(user)
}
end

def app_spaces_no_match?(app)
Comment thread
nookala marked this conversation as resolved.
Outdated
app.space != space && shared_spaces.exclude?(app.space)
end

delegate :in_suspended_org?, to: :space

def tcp?
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/actions/manifest_route_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ module VCAP::CloudController
'Routes cannot be mapped to destinations in different spaces')
end
end

context 'when the route is shared' do
let!(:route_share) { RouteShare.new }
let!(:outside_app) { AppModel.make }
let!(:shared_route) { route_share.create(route, [outside_app.space], user_audit_info) }

it 'succeeds after route share' do
expect do
ManifestRouteUpdate.update(outside_app.guid, message, user_audit_info)
end.not_to raise_error
end
end
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/unit/models/runtime/route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1570,5 +1570,35 @@ def assert_invalid_path(path)
end
end
end

describe 'app spaces and route shared spaces' do
let!(:domain) { SharedDomain.make }

context 'when app and route space not shared' do
let!(:app) { AppModel.make }
let!(:route) { Route.make(host: 'potato', domain: domain, path: '/some-path') }

it 'no space match and not shared and returns true' do
expect(route.app_spaces_no_match?(app)).to be(true)
end

it 'match space and returns false' do
route.space = app.space
expect(route.app_spaces_no_match?(app)).to be(false)
end
end

context 'when app and route space shared' do
let!(:app) { AppModel.make }
let!(:route_share) { RouteShare.new }
let(:user_audit_info) { instance_double(UserAuditInfo).as_null_object }
let!(:route) { Route.make(host: 'potato', domain: domain, path: '/some-path') }
let!(:shared_route) { route_share.create(route, [app.space], user_audit_info) }

it 'shared space match and returns false' do
expect(route.app_spaces_no_match?(app)).to be(false)
end
end
end
end
end