14716: Sets empty anonymous token on failing wb integration tests.
[arvados.git] / apps / workbench / test / integration / jobs_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'fileutils'
6 require 'tmpdir'
7
8 require 'integration_helper'
9
10 class JobsTest < ActionDispatch::IntegrationTest
11   setup do
12       need_javascript
13   end
14
15   def fakepipe_with_log_data
16     content =
17       "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 1\n" +
18       "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 2\n" +
19       "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 3\n"
20     StringIO.new content, 'r'
21   end
22
23   test "add job description" do
24     job = api_fixture('jobs')['nearly_finished_job']
25     visit page_with_token("active", "/jobs/#{job['uuid']}")
26
27     # edit job description
28     within('.arv-description-as-subtitle') do
29       find('.fa-pencil').click
30       find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
31       find('.editable-submit').click
32     end
33
34     # Verify edited description
35     assert_no_text '*Textile description for job*'
36     assert_text 'Textile description for job'
37     assert_selector 'a[href="/"]', text: 'Go to dashboard'
38   end
39
40   test 'view partial job log' do
41     need_selenium 'to be able to see the CORS response headers (PhantomJS 1.9.8 does not)'
42
43     # This config will be restored during teardown by ../test_helper.rb:
44     Rails.configuration.Workbench.LogViewerMaxBytes = 100
45
46     logdata = fakepipe_with_log_data.read
47     job_uuid = api_fixture('jobs')['running']['uuid']
48     logcollection = upload_data_and_get_collection(logdata, 'active', "#{job_uuid}.log.txt")
49     job = nil
50     use_token 'active' do
51       job = Job.find job_uuid
52       job.update_attributes log: logcollection.portable_data_hash
53     end
54     visit page_with_token 'active', '/jobs/'+job.uuid
55     find('a[href="#Log"]').click
56     wait_for_ajax
57     assert_text 'Showing only 100 bytes of this log'
58   end
59
60   test 'view log via keep-web redirect' do
61     token = api_token('active')
62     logdata = fakepipe_with_log_data.read
63     logblock = `echo -n #{logdata.shellescape} | ARVADOS_API_TOKEN=#{token.shellescape} arv-put --no-progress --raw -`.strip
64     assert $?.success?, $?
65
66     job = nil
67     use_token 'active' do
68       job = Job.find api_fixture('jobs')['running']['uuid']
69       mtxt = ". #{logblock} 0:#{logdata.length}:#{job.uuid}.log.txt\n"
70       logcollection = Collection.create(manifest_text: mtxt)
71       job.update_attributes log: logcollection.portable_data_hash
72     end
73     visit page_with_token 'active', '/jobs/'+job.uuid
74     find('a[href="#Log"]').click
75     assert_text 'log message 1'
76   end
77
78   [
79     ['foobar', false, false],
80     ['job_with_latest_version', true, false],
81     ['job_with_latest_version', true, true],
82   ].each do |job_name, expect_options, use_latest|
83     test "Rerun #{job_name} job, expect options #{expect_options},
84           and use latest version option #{use_latest}" do
85       job = api_fixture('jobs')[job_name]
86       visit page_with_token 'active', '/jobs/'+job['uuid']
87
88       if expect_options
89         assert_text 'supplied_script_version: master'
90       else
91         assert_no_text 'supplied_script_version'
92       end
93
94       assert_triggers_dom_event 'shown.bs.modal' do
95         find('a,button', text: 'Re-run job...').click
96       end
97       within('.modal-dialog') do
98         assert_selector 'a,button', text: 'Cancel'
99         if use_latest
100           page.choose("job_script_version_#{job['supplied_script_version']}")
101         end
102         click_on "Run now"
103       end
104
105       # Re-running jobs doesn't currently work because the test API
106       # server has no git repository to check against.  For now, check
107       # that the error message says something appropriate for that
108       # situation.
109       if expect_options && use_latest
110         assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
111       else
112         assert_text "Script version #{job['script_version']} does not resolve to a commit"
113       end
114     end
115   end
116
117   [
118     ['active', true],
119     ['job_reader2', false],
120   ].each do |user, readable|
121     test "view job with components as #{user} user" do
122       Rails.configuration.Users.AnonymousUserToken = ""
123       job = api_fixture('jobs')['running_job_with_components']
124       component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
125       component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
126       component2_child1 = api_fixture('jobs')['previous_job_run']
127       component2_child2 = api_fixture('jobs')['running']
128
129       visit page_with_token(user, "/jobs/#{job['uuid']}")
130       assert page.has_text? job['script_version']
131       assert page.has_no_text? 'script_parameters'
132
133       # The job_reader2 is allowed to read job, component2, and component2_child1,
134       # and component2_child2 only as a component of the pipeline component2
135       if readable
136         assert page.has_link? 'component1'
137         assert page.has_link? 'component2'
138       else
139         assert page.has_no_link? 'component1'
140         assert page.has_link? 'component2'
141       end
142
143       if readable
144         click_link('component1')
145         within('.panel-collapse') do
146           assert(has_text? component1['uuid'])
147           assert(has_text? component1['script_version'])
148           assert(has_text? 'script_parameters')
149         end
150         click_link('component1')
151       end
152
153       click_link('component2')
154       within('.panel-collapse') do
155         assert(has_text? component2['uuid'])
156         assert(has_text? component2['script_version'])
157         assert(has_no_text? 'script_parameters')
158         assert(has_link? 'previous')
159         assert(has_link? 'running')
160
161         click_link('previous')
162         within('.panel-collapse') do
163           assert(has_text? component2_child1['uuid'])
164           assert(has_text? component2_child1['script_version'])
165         end
166         click_link('previous')
167
168         click_link('running')
169         within('.panel-collapse') do
170           assert(has_text? component2_child2['uuid'])
171           if readable
172             assert(has_text? component2_child2['script_version'])
173           else
174             assert(has_no_text? component2_child2['script_version'])
175           end
176         end
177       end
178     end
179   end
180 end