From 8581965c4c62fa4950c6e0957272016c7d0048ca Mon Sep 17 00:00:00 2001 From: Sriram Nookala Date: Thu, 8 May 2025 00:36:36 +0000 Subject: [PATCH 1/6] Can't push apps with app manifests if routes were shared Check if route shared with space and don't throw error if shared --- app/actions/manifest_route_update.rb | 8 ++++++-- spec/unit/actions/manifest_route_update_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/actions/manifest_route_update.rb b/app/actions/manifest_route_update.rb index d5fef841e5d..4978178c047 100644 --- a/app/actions/manifest_route_update.rb +++ b/app/actions/manifest_route_update.rb @@ -90,8 +90,12 @@ 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 - raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') + elsif route.space.guid != app.space_guid + # check if route is shared with space + spaces = route.shared_spaces + if (spaces.blank?) || (!spaces.any? { |space| space.values[:id] == app.space.id }) + raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') + end end return route diff --git a/spec/unit/actions/manifest_route_update_spec.rb b/spec/unit/actions/manifest_route_update_spec.rb index 51f0f4a693c..31eb6a20908 100644 --- a/spec/unit/actions/manifest_route_update_spec.rb +++ b/spec/unit/actions/manifest_route_update_spec.rb @@ -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 From ba67c2d14c60f5bb0f56d5d05010bb5651ae83b2 Mon Sep 17 00:00:00 2001 From: Sriram Nookala Date: Thu, 8 May 2025 01:56:08 +0000 Subject: [PATCH 2/6] Can't push apps with app manifests if routes were shared Fix robocop errors --- app/actions/manifest_route_update.rb | 6 ++---- spec/unit/actions/manifest_route_update_spec.rb | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/actions/manifest_route_update.rb b/app/actions/manifest_route_update.rb index 04cfa36ce91..3d833ffbfa2 100644 --- a/app/actions/manifest_route_update.rb +++ b/app/actions/manifest_route_update.rb @@ -92,12 +92,10 @@ 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.space.guid != app.space_guid # check if route is shared with space spaces = route.shared_spaces - if (spaces.blank?) || (!spaces.any? { |space| space.values[:id] == app.space.id }) - raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') - end + raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') if spaces.blank? || !spaces.any? { |space| space.values[:id] == app.space.id } elsif manifest_route[:options] && route[:options] != manifest_route[:options] # remove nil values from options manifest_route[:options] = manifest_route[:options].compact diff --git a/spec/unit/actions/manifest_route_update_spec.rb b/spec/unit/actions/manifest_route_update_spec.rb index 31eb6a20908..623aa6384b6 100644 --- a/spec/unit/actions/manifest_route_update_spec.rb +++ b/spec/unit/actions/manifest_route_update_spec.rb @@ -127,7 +127,7 @@ module VCAP::CloudController let!(:outside_app) { AppModel.make } let!(:shared_route) { route_share.create(route, [outside_app.space], user_audit_info) } - it 'succeeds after route share' do + it 'succeeds after route share' do expect do ManifestRouteUpdate.update(outside_app.guid, message, user_audit_info) end.not_to raise_error From 0181fe7b952eadbd0f26719f085bf6b553fb9931 Mon Sep 17 00:00:00 2001 From: Sriram Nookala Date: Thu, 8 May 2025 02:01:22 +0000 Subject: [PATCH 3/6] Can't push apps with app manifests if routes were shared Fix rubocop error --- app/actions/manifest_route_update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/actions/manifest_route_update.rb b/app/actions/manifest_route_update.rb index 3d833ffbfa2..507a42091e8 100644 --- a/app/actions/manifest_route_update.rb +++ b/app/actions/manifest_route_update.rb @@ -95,7 +95,7 @@ def find_or_create_valid_route(app, manifest_route, user_audit_info) elsif route.space.guid != app.space_guid # check if route is shared with space spaces = route.shared_spaces - raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') if spaces.blank? || !spaces.any? { |space| space.values[:id] == app.space.id } + raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') if spaces.blank? || spaces.none? { |space| space.values[:id] == app.space.id } elsif manifest_route[:options] && route[:options] != manifest_route[:options] # remove nil values from options manifest_route[:options] = manifest_route[:options].compact From c234b926a1b34e1ed3279e2ba79c197b5a8f9a4b Mon Sep 17 00:00:00 2001 From: Sriram Nookala Date: Fri, 9 May 2025 21:23:53 +0000 Subject: [PATCH 4/6] Can't push apps with app manifests if routes were shared Move app and route space match to common method --- app/actions/manifest_route_update.rb | 6 ++--- app/controllers/v3/routes_controller.rb | 2 +- app/models/runtime/route.rb | 4 ++++ spec/unit/models/runtime/route_spec.rb | 30 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/actions/manifest_route_update.rb b/app/actions/manifest_route_update.rb index 507a42091e8..016a450e807 100644 --- a/app/actions/manifest_route_update.rb +++ b/app/actions/manifest_route_update.rb @@ -92,10 +92,8 @@ 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 - # check if route is shared with space - spaces = route.shared_spaces - raise InvalidRoute.new('Routes cannot be mapped to destinations in different spaces') if spaces.blank? || spaces.none? { |space| space.values[:id] == app.space.id } + 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 manifest_route[:options] = manifest_route[:options].compact diff --git a/app/controllers/v3/routes_controller.rb b/app/controllers/v3/routes_controller.rb index 4d2220e761d..207decbbbe3 100644 --- a/app/controllers/v3/routes_controller.rb +++ b/app/controllers/v3/routes_controller.rb @@ -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 diff --git a/app/models/runtime/route.rb b/app/models/runtime/route.rb index 7ec7a0b2264..252d142612e 100644 --- a/app/models/runtime/route.rb +++ b/app/models/runtime/route.rb @@ -194,6 +194,10 @@ def self.user_visibility_filter(user) } end + def app_spaces_no_match?(app) + app.space != space && shared_spaces.exclude?(app.space) + end + delegate :in_suspended_org?, to: :space def tcp? diff --git a/spec/unit/models/runtime/route_spec.rb b/spec/unit/models/runtime/route_spec.rb index 173d4cf1234..69722e8e9c4 100644 --- a/spec/unit/models/runtime/route_spec.rb +++ b/spec/unit/models/runtime/route_spec.rb @@ -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 From cb5688ea33b9664212b43908bd1d19f495011a99 Mon Sep 17 00:00:00 2001 From: Sriram Nookala Date: Fri, 9 May 2025 21:45:29 +0000 Subject: [PATCH 5/6] Can't push apps with app manifests if routes were shared Fix rubocop errors --- app/models/runtime/route.rb | 2 +- spec/unit/models/runtime/route_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/runtime/route.rb b/app/models/runtime/route.rb index 252d142612e..7a5a8c439ca 100644 --- a/app/models/runtime/route.rb +++ b/app/models/runtime/route.rb @@ -195,7 +195,7 @@ def self.user_visibility_filter(user) end def app_spaces_no_match?(app) - app.space != space && shared_spaces.exclude?(app.space) + app.space != space && shared_spaces.exclude?(app.space) end delegate :in_suspended_org?, to: :space diff --git a/spec/unit/models/runtime/route_spec.rb b/spec/unit/models/runtime/route_spec.rb index 69722e8e9c4..b45e9aa07a3 100644 --- a/spec/unit/models/runtime/route_spec.rb +++ b/spec/unit/models/runtime/route_spec.rb @@ -1574,7 +1574,7 @@ def assert_invalid_path(path) describe 'app spaces and route shared spaces' do let!(:domain) { SharedDomain.make } - context 'when app and route space not shared' do + context 'when app and route space not shared' do let!(:app) { AppModel.make } let!(:route) { Route.make(host: 'potato', domain: domain, path: '/some-path') } From ebe5d1e3f8902fc43db79c5b9dba5fa88687c702 Mon Sep 17 00:00:00 2001 From: Sriram Nookala Date: Tue, 13 May 2025 20:27:26 +0000 Subject: [PATCH 6/6] Can't push apps with app manifests if routes were shared Rename method based on code review --- app/actions/manifest_route_update.rb | 2 +- app/controllers/v3/routes_controller.rb | 2 +- app/models/runtime/route.rb | 4 ++-- spec/unit/models/runtime/route_spec.rb | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/actions/manifest_route_update.rb b/app/actions/manifest_route_update.rb index 016a450e807..e00182e0295 100644 --- a/app/actions/manifest_route_update.rb +++ b/app/actions/manifest_route_update.rb @@ -92,7 +92,7 @@ def find_or_create_valid_route(app, manifest_route, user_audit_info) domain: existing_domain, manifest_triggered: true ) - elsif route.app_spaces_no_match?(app) + elsif !route.available_in_space?(app.space) 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 diff --git a/app/controllers/v3/routes_controller.rb b/app/controllers/v3/routes_controller.rb index 207decbbbe3..86f042dc3a7 100644 --- a/app/controllers/v3/routes_controller.rb +++ b/app/controllers/v3/routes_controller.rb @@ -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| route.app_spaces_no_match?(app) } + return unless apps_hash.values.any? { |app| !route.available_in_space?(app.space) } unprocessable!("Routes destinations must be in either the route's space or the route's shared spaces") end diff --git a/app/models/runtime/route.rb b/app/models/runtime/route.rb index 7a5a8c439ca..48bec5c9e42 100644 --- a/app/models/runtime/route.rb +++ b/app/models/runtime/route.rb @@ -194,8 +194,8 @@ def self.user_visibility_filter(user) } end - def app_spaces_no_match?(app) - app.space != space && shared_spaces.exclude?(app.space) + def available_in_space?(other_space) + other_space == space || shared_spaces.include?(other_space) end delegate :in_suspended_org?, to: :space diff --git a/spec/unit/models/runtime/route_spec.rb b/spec/unit/models/runtime/route_spec.rb index b45e9aa07a3..c97c3ad0a4d 100644 --- a/spec/unit/models/runtime/route_spec.rb +++ b/spec/unit/models/runtime/route_spec.rb @@ -1578,13 +1578,13 @@ def assert_invalid_path(path) 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) + it 'no space match and not shared and returns false' do + expect(route.available_in_space?(app.space)).to be(false) end - it 'match space and returns false' do + it 'match space and returns true' do route.space = app.space - expect(route.app_spaces_no_match?(app)).to be(false) + expect(route.available_in_space?(app.space)).to be(true) end end @@ -1595,8 +1595,8 @@ def assert_invalid_path(path) 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) + it 'shared space match and returns true' do + expect(route.available_in_space?(app.space)).to be(true) end end end