-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2467 from alphagov/fix-broken-asset-redirect
Fix redirecting to incorrect assets domain
- Loading branch information
Showing
4 changed files
with
11 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 7 additions & 19 deletions
26
test/controllers/asset_manager_redirect_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
require "test_helper" | ||
|
||
class AssetManagerRedirectControllerTest < ActionController::TestCase | ||
setup do | ||
Plek.any_instance.stubs(:asset_root).returns("http://asset-host.com") | ||
Plek.any_instance.stubs(:external_url_for).returns("http://draft-asset-host.com") | ||
end | ||
|
||
test "sets the cache-control max-age to 1 day" do | ||
request.host = "some-host.com" | ||
get :show, params: { path: "asset.txt" } | ||
|
||
assert_equal @response.headers["Cache-Control"], "max-age=86400, public" | ||
end | ||
|
||
test "redirects asset requests made via public host to the public asset host" do | ||
request.host = "some-host.com" | ||
get :show, params: { path: "asset.txt" } | ||
|
||
assert_redirected_to "http://asset-host.com/government/uploads/asset.txt" | ||
end | ||
|
||
test "redirects asset requests made via draft host to the draft asset host" do | ||
request.host = "draft-some-host.com" | ||
test "redirects asset requests to the assets hostname" do | ||
get :show, params: { path: "asset.txt" } | ||
|
||
assert_redirected_to "http://draft-asset-host.com/government/uploads/asset.txt" | ||
assert_redirected_to "http://assets.test.gov.uk/government/uploads/asset.txt" | ||
end | ||
|
||
test "redirects asset preview requests made via public host to the public asset host" do | ||
request.host = "some-host.com" | ||
get :show, params: { path: "asset.csv/preview" } | ||
test "redirects to assets hostname respect the draft stack" do | ||
ClimateControl.modify PLEK_HOSTNAME_PREFIX: "draft-" do | ||
get :show, params: { path: "asset.txt" } | ||
|
||
assert_redirected_to "http://asset-host.com/government/uploads/asset.csv/preview" | ||
assert_redirected_to "http://draft-assets.test.gov.uk/government/uploads/asset.txt" | ||
end | ||
end | ||
end |