5824: Merge branch 'master' into 5824-keep-web-workbench
[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   test "download from keep-web with a reader token" do
23     uuid = api_fixture('collections')['foo_file']['uuid']
24     token = api_fixture('api_client_authorizations')['active_all_collections']['api_token']
25     visit "/collections/download/#{uuid}/#{token}/"
26     within "#collection_files" do
27       click_link "foo"
28     end
29     data = nil
30     tries = 0
31     while tries < 20
32       sleep 0.1
33       tries += 1
34       data = File.read(DownloadHelper.path.join 'foo') rescue nil
35     end
36     assert_equal 'foo', data
37   end
38
39   # TODO(TC): test "view pages hosted by keep-web, using session
40   # token". We might persuade selenium to send
41   # "collection-uuid.dl.example" requests to localhost by configuring
42   # our test nginx server to work as its forward proxy. Until then,
43   # we're relying on the "Redirect to keep_web_url via #{id_type}"
44   # test in CollectionsControllerTest (and keep-web's tests).
45 end