Merge branch '20257-http-import' refs #20257
[arvados.git] / apps / workbench / test / controllers / disabled_api_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6 require 'helpers/share_object_helper'
7
8 class DisabledApiTest < ActionController::TestCase
9   reset_api_fixtures :after_each_test, false
10   reset_api_fixtures :after_suite, false
11
12   test "dashboard recent processes when pipeline_instance index API is disabled" do
13     @controller = ProjectsController.new
14
15     dd = ArvadosApiClient.new_or_current.discovery.deep_dup
16     dd[:resources][:pipeline_instances][:methods].delete(:index)
17     ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
18
19     get :index, params: {}, session: session_for(:active)
20     assert_includes @response.body, "zzzzz-xvhdp-cr4runningcntnr" # expect crs
21     assert_not_includes @response.body, "zzzzz-d1hrv-"   # expect no pipelines
22     assert_includes @response.body, "Run a process"
23   end
24
25   test "dashboard compute node status not shown when pipeline_instance index API is disabled" do
26     @controller = ProjectsController.new
27
28     dd = ArvadosApiClient.new_or_current.discovery.deep_dup
29     dd[:resources][:pipeline_instances][:methods].delete(:index)
30     ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
31
32     get :index, params: {}, session: session_for(:active)
33     assert_not_includes @response.body, "compute-node-summary-pane"
34   end
35
36   [
37     [:jobs, JobsController.new],
38     [:job_tasks, JobTasksController.new],
39     [:pipeline_instances, PipelineInstancesController.new],
40     [:pipeline_templates, PipelineTemplatesController.new],
41   ].each do |ctrl_name, ctrl|
42     test "#{ctrl_name} index page when API is disabled" do
43       @controller = ctrl
44
45       dd = ArvadosApiClient.new_or_current.discovery.deep_dup
46       dd[:resources][ctrl_name][:methods].delete(:index)
47       ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
48
49       get :index, params: {}, session: session_for(:active)
50       assert_response 404
51     end
52   end
53
54   [
55     :admin,
56     :active,
57     nil,
58   ].each do |user|
59     test "project tabs as user #{user} when pipeline related index APIs are disabled" do
60       @controller = ProjectsController.new
61
62       Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
63
64       dd = ArvadosApiClient.new_or_current.discovery.deep_dup
65       dd[:resources][:pipeline_templates][:methods].delete(:index)
66       ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
67
68       proj_uuid = api_fixture('groups')['anonymously_accessible_project']['uuid']
69
70       if user
71         get(:show, params: {id: proj_uuid}, session: session_for(user))
72       else
73         get(:show, params: {id: proj_uuid})
74       end
75
76       resp = @response.body
77       assert_includes resp, "href=\"#Data_collections\""
78       assert_includes resp, "href=\"#Pipelines_and_processes\""
79       assert_includes resp, "href=\"#Workflows\""
80       assert_not_includes resp, "href=\"#Pipeline_templates\""
81       assert_includes @response.body, "Run a process" if user == :admin
82     end
83   end
84 end