Skip to content

Commit 2b16d2a

Browse files
committed
fix remaining tests
1 parent e9bfdbf commit 2b16d2a

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

app/messages/manifest_routes_update_message.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'messages/base_message'
2+
require 'messages/route_options_message'
23
require 'cloud_controller/app_manifest/manifest_route'
34

45
module VCAP::CloudController
@@ -36,6 +37,10 @@ def contains_invalid_route_options?(routes)
3637
next unless r[:options]
3738

3839
return true unless r[:options].is_a?(Hash)
40+
41+
return false if r[:options].empty?
42+
43+
return r[:options].keys.all? { |key| RouteOptionsMessage::VALID_MANIFEST_ROUTE_OPTIONS.exclude?(key) }
3944
end
4045
end
4146

app/messages/route_options_message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module VCAP::CloudController
44
class RouteOptionsMessage < BaseMessage
55

6+
VALID_MANIFEST_ROUTE_OPTIONS = %i[loadbalancing-algorithm].freeze
7+
VALID_ROUTE_OPTIONS = %i[lb_algo].freeze
68
VALID_LOADBALANCING_ALGORITHMS = %w[round-robin least-connections].freeze
79

810
register_allowed_keys %i[lb_algo]

app/presenters/v3/app_manifest_presenters/route_properties_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def to_hash(route_mappings:, app:, **_)
1212

1313
if route_mapping.route.options
1414
route_hash[:options] = {}
15-
route_hash[:options]['loadbalancing-algorithm'] = route_mapping.route.options['lb_algo'] if route_mapping.route.options['lb_algo']
15+
route_hash[:options][:'loadbalancing-algorithm'] = route_mapping.route.options[:lb_algo] if route_mapping.route.options[:lb_algo]
1616
end
1717

1818
route_hash

lib/cloud_controller/app_manifest/manifest_route.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ManifestRoute
66
SUPPORTED_TCP_SCHEMES = %w[tcp unspecified].freeze
77
WILDCARD_HOST = '*'.freeze
88

9-
def self.parse(route, options=nil)
9+
def self.parse(route, options = nil)
1010
parsed_uri = Addressable::URI.heuristic_parse(route, scheme: 'unspecified')
1111

1212
attrs = if parsed_uri.nil?
@@ -26,6 +26,11 @@ def self.parse(route, options=nil)
2626
end
2727

2828
def valid?
29+
if @attrs[:options] && !@attrs[:options].empty?
30+
return false if @attrs[:options].keys.any? { |key| RouteOptionsMessage::VALID_ROUTE_OPTIONS.exclude?(key) }
31+
return false if @attrs[:options][:lb_algo] && RouteOptionsMessage::VALID_LOADBALANCING_ALGORITHMS.exclude?(@attrs[:options][:lb_algo])
32+
end
33+
2934
return false if @attrs[:host].blank?
3035

3136
return SUPPORTED_TCP_SCHEMES.include?(@attrs[:scheme]) if @attrs[:port]

spec/request/space_manifests_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@
668668
post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header)
669669

670670
expect(last_response).to have_status_code(422)
671-
expect(last_response).to have_error_message('Routes contains an invalid loadbalancing-algorithm option')
671+
expect(last_response).to have_error_message('Routes contains invalid route options')
672672
end
673673
end
674674

spec/unit/lib/cloud_controller/app_manifest/manifest_route_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module VCAP::CloudController
119119

120120
context 'when there is an invalid loadbalancing-algorithm' do
121121
let(:route) { 'http://example.com' }
122-
let(:options) { { 'loadbalancing-algorithm' => 'invalid' } }
122+
let(:options) { { :'loadbalancing-algorithm' => 'invalid' } }
123123

124124
it 'is invalid' do
125125
manifest_route = ManifestRoute.parse(route, options)

spec/unit/messages/manifest_routes_update_message_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ module VCAP::CloudController
225225
end
226226
end
227227

228+
context 'when a route contains invalid route options' do
229+
let(:body) do
230+
{ 'routes' =>
231+
[
232+
{ 'route' => 'existing.example.com',
233+
'options' => {'invalid' => 'invalid'} }
234+
] }
235+
end
236+
237+
it 'returns true' do
238+
msg = ManifestRoutesUpdateMessage.new(body)
239+
240+
expect(msg.valid?).to be(false)
241+
end
242+
end
243+
228244
context 'when a route contains a valid loadbalancing-algorithm' do
229245
let(:body) do
230246
{ 'routes' =>

0 commit comments

Comments
 (0)