Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Only pass the host to the router when registering an application.
Browse files Browse the repository at this point in the history
In produciton this was passing a full https url, which causes the router
clinet to register a backend_url with a port of 443.  This was wrong.
  • Loading branch information
alext committed Aug 2, 2012
1 parent 0177e50 commit f8c819c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 4 additions & 2 deletions app/models/routable_artefact.rb
Expand Up @@ -15,8 +15,10 @@ def router
end

def ensure_application_exists
backend_url = Plek.current.find(rendering_app)
router.update_application(rendering_app, backend_url)
backend_url = URI.parse Plek.current.find(rendering_app)
# Plek returns a full URL (https URL in production and preview).
# We only want to pass the host to the router.
router.update_application(rendering_app, backend_url.host)
end

def submit
Expand Down
2 changes: 1 addition & 1 deletion features/support/registration_info.rb
Expand Up @@ -40,7 +40,7 @@ def stub_search

def stub_router
WebMock.stub_request(:put, %r{^#{ROUTER_ROOT}/router/applications/.*$}).
with(:body => { "backend_url" => %r{^.*.test.gov.uk:80$} }).
with(:body => { "backend_url" => %r{^.*.test.gov.uk$} }).
to_return(:status => 200, :body => "{}", :headers => {})

# catch-all
Expand Down
22 changes: 17 additions & 5 deletions test/unit/routable_artefact_test.rb
Expand Up @@ -6,10 +6,22 @@ class RoutableArtefactTest < ActiveSupport::TestCase
@routable = RoutableArtefact.new(@artefact)
end

should "ensure that the application exists in the router" do
Router.any_instance.expects(:update_application).with("bee", "http://bee.test.gov.uk")
Router.any_instance.stubs(:create_route)
@routable.submit
context "registering the application" do
should "ensure that the application exists in the router" do
Router.any_instance.expects(:update_application).with("bee", "bee.test.gov.uk")
Router.any_instance.stubs(:create_route)
@routable.submit
end

should "strip the scheme from the URL returned by Plek" do
# Plek returns the external URL's for applications, this is the HTTPS version
# in preview and production. If an https URL is passed to the router, it gets confused.
Plek.any_instance.stubs(:find).with('bee').returns("https://bee.test.gov.uk")

Router.any_instance.expects(:update_application).with("bee", "bee.test.gov.uk")
Router.any_instance.stubs(:create_route)
@routable.submit
end
end

should "create a full route for the slug" do
Expand Down Expand Up @@ -64,7 +76,7 @@ class RoutableArtefactTest < ActiveSupport::TestCase
# Was previously using the publically visible hostname (www...) which was breaking things.
Plek.stubs(:current_env).returns('production')
@artefact.update_attributes!(:owning_app => 'frontend')
Router.any_instance.expects(:update_application).with("frontend", "https://frontend.production.alphagov.co.uk")
Router.any_instance.expects(:update_application).with("frontend", "frontend.production.alphagov.co.uk")
Router.any_instance.stubs(:create_route)
@routable.submit
end
Expand Down

0 comments on commit f8c819c

Please sign in to comment.