Skip to content

Commit

Permalink
Merge pull request #682 from alphagov/ignore-asset-path
Browse files Browse the repository at this point in the history
Don't redirect assets paths to CKAN
  • Loading branch information
thomasleese authored Jun 11, 2019
2 parents d634f48 + 96ac191 commit 23aa6cd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@

# Route everything else to CKAN
if ENV["CKAN_REDIRECTION_URL"].present?
match '*path', to: redirect(domain: ENV['CKAN_REDIRECTION_URL'], subdomain: '', path: "/%{path}"), via: :all
match '*path',
to: redirect(domain: ENV['CKAN_REDIRECTION_URL'], subdomain: '', path: "/%{path}"),
via: :all,
constraints: { path: /(?!#{Regexp.quote(Rails.application.config.assets.prefix[1..-1])}).+/ }
end
end
43 changes: 43 additions & 0 deletions spec/requests/ckan_redirection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'
require 'securerandom'

RSpec.describe 'CKAN redirection', type: :request do
let(:path) { nil }

shared_examples "does redirect to CKAN" do
it "does redirect to CKAN" do
get path

expect(response).to have_http_status(:moved_permanently)
expect(response).to redirect_to("http://testdomain#{path}")
end
end

shared_examples "doesn't redirect to CKAN" do
it "doesn't redirect to CKAN" do
get path

expect(response).to_not have_http_status(:moved_permanently)
end
end

context "with a known path" do
let(:path) { "/dataset/#{SecureRandom.uuid}" }
include_examples "doesn't redirect to CKAN"
end

context "with an assets path" do
let(:path) { "/find-assets/application-#{SecureRandom.uuid}.js" }
include_examples "doesn't redirect to CKAN"
end

context "with an unknown path" do
let(:path) { "/an/unknown/path" }
include_examples "does redirect to CKAN"
end

context "with an unknown path that includes 'find-assets'" do
let(:path) { "/an/unknown/path/find-assets/application" }
include_examples "does redirect to CKAN"
end
end

0 comments on commit 23aa6cd

Please sign in to comment.