Skip to content

Commit

Permalink
feat: Add protocol field in route-registrar spec
Browse files Browse the repository at this point in the history
  • Loading branch information
b1tamara committed May 10, 2023
1 parent 090b03b commit 2cabec5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions jobs/route_registrar/spec
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ properties:
tls_port (required, integer, for http routes): Either `port` or `tls_port` are required; if both are provided, Gorouter will prefer tls_port.
Requests for associated URIs will be forwarded over TLS by the router to this port.
The IP is determined automatically from the host on which route-registrar is run.
protocol (optional, string): 'http1' or 'http2'. If not provided, Gorouter uses 'http1' as default.
route_service_url (optional, string, for http routes): When valid route service URL is provided, Gorouter will proxy requests received for the uris above to the specified route service URL.
server_cert_domain_san (conditional, string, for http routes): Required if tls_port is present.
Gorouter will validate that the TLS certificate presented by the destination host contains this as a Subject Alternative Name (SAN).
Expand Down
4 changes: 4 additions & 0 deletions jobs/route_registrar/templates/registrar_settings.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
raise "expected route_registrar.routes[#{index}].route.server_cert_domain_san when tls_port is provided"
end

if route['protocol'] != nil && (route['protocol'] != 'http1' && route['protocol'] != 'http2')
raise "expected route_registrar.routes[#{index}].route.protocol to be http1 or http2 when protocol is provided"
end

if route['prepend_instance_index']
route['uris'].map! { |uri| "#{spec.index}-#{uri}" }
end
Expand Down
14 changes: 14 additions & 0 deletions spec/route_registar_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@
expect { template.render(merged_manifest_properties, consumes: links) }.not_to raise_error
end
end

describe 'when protocol is provided' do
it 'uses configured protocol' do
merged_manifest_properties['route_registrar']['routes'][0]['protocol'] = 'http2'
rendered_hash = JSON.parse(template.render(merged_manifest_properties, consumes: links))
expect(rendered_hash['routes'][0]['protocol']).to eq('http2')
end
it 'raises error for invalid protocol' do
merged_manifest_properties['route_registrar']['routes'][0]['protocol'] = 'abc'
expect { template.render(merged_manifest_properties, consumes: links) }.to raise_error(
RuntimeError, 'expected route_registrar.routes[0].route.protocol to be http1 or http2 when protocol is provided'
)
end
end
end
end

Expand Down

0 comments on commit 2cabec5

Please sign in to comment.