1 require 'integration_helper'
2 require 'helpers/download_helper'
4 class DownloadTest < ActionDispatch::IntegrationTest
6 portfile = File.expand_path '../../../../../tmp/keep-web-ssl.port', __FILE__
7 @kwport = File.read portfile
8 Rails.configuration.keep_web_url = "https://localhost:#{@kwport}/c=%{uuid_or_pdh}"
9 CollectionsController.any_instance.expects(:file_enumerator).never
11 # Make sure Capybara can download files.
12 need_selenium 'for downloading', :selenium_with_download
15 # Keep data isn't populated by fixtures, so we have to write any
16 # data we expect to read.
17 unless /^acbd/ =~ `echo -n foo | arv-put --no-progress --raw -` && $?.success?
22 ['uuid', 'portable_data_hash'].each do |id_type|
23 test "download from keep-web by #{id_type} using a reader token" do
24 uuid_or_pdh = api_fixture('collections')['foo_file'][id_type]
25 token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
26 visit "/collections/download/#{uuid_or_pdh}/#{token}/"
27 within "#collection_files" do
30 wait_for_download 'foo', 'foo'
34 def wait_for_download filename, expect_data
40 data = File.read(DownloadHelper.path.join filename) rescue nil
42 assert_equal expect_data, data
45 # TODO(TC): test "view pages hosted by keep-web, using session
46 # token". We might persuade selenium to send
47 # "collection-uuid.dl.example" requests to localhost by configuring
48 # our test nginx server to work as its forward proxy. Until then,
49 # we're relying on the "Redirect to keep_web_url via #{id_type}"
50 # test in CollectionsControllerTest (and keep-web's tests).