Merge branch '5824-keep-web-workbench' refs #5824
[arvados.git] / apps / workbench / test / integration / download_test.rb
1 require 'integration_helper'
2 require 'helpers/download_helper'
3
4 class DownloadTest < ActionDispatch::IntegrationTest
5   setup do
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
10
11     # Make sure Capybara can download files.
12     need_selenium 'for downloading', :selenium_with_download
13     DownloadHelper.clear
14
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?
18       raise $?.to_s
19     end
20   end
21
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
28         click_link "foo"
29       end
30       wait_for_download 'foo', 'foo'
31     end
32   end
33
34   def wait_for_download filename, expect_data
35     data = nil
36     tries = 0
37     while tries < 20
38       sleep 0.1
39       tries += 1
40       data = File.read(DownloadHelper.path.join filename) rescue nil
41     end
42     assert_equal expect_data, data
43   end
44
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).
51 end