Merge branch '16202-shell-suffix' refs #16202
[arvados.git] / apps / workbench / test / controllers / actions_controller_test.rb
index 26ef67bcb932afe545cc218f1c565fa10dc61a24..fbbffe87cb875e93528f84c3f29f3908ca996946 100644 (file)
@@ -1,9 +1,13 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class ActionsControllerTest < ActionController::TestCase
 
   test "send report" do
 require 'test_helper'
 
 class ActionsControllerTest < ActionController::TestCase
 
   test "send report" do
-    post :report_issue, {format: 'js'}, session_for(:admin)
+    post :report_issue, params: {format: 'js'}, session: session_for(:admin)
     assert_response :success
 
     found_email = false
     assert_response :success
 
     found_email = false
@@ -17,13 +21,13 @@ class ActionsControllerTest < ActionController::TestCase
   end
 
   test "combine files into new collection" do
   end
 
   test "combine files into new collection" do
-    post(:combine_selected_files_into_collection, {
+    post(:combine_selected_files_into_collection, params: {
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-ehbhgtheo8909or/bar',
                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
            format: "json"},
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-ehbhgtheo8909or/bar',
                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
            format: "json"},
-         session_for(:active))
+         session: session_for(:active))
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
@@ -42,7 +46,7 @@ class ActionsControllerTest < ActionController::TestCase
   end
 
   test "combine files  with repeated names into new collection" do
   end
 
   test "combine files  with repeated names into new collection" do
-    post(:combine_selected_files_into_collection, {
+    post(:combine_selected_files_into_collection, params: {
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-00000nonamecoll/foo',
                        'zzzzz-4zz18-abcd6fx123409f7/foo',
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-00000nonamecoll/foo',
                        'zzzzz-4zz18-abcd6fx123409f7/foo',
@@ -50,7 +54,7 @@ class ActionsControllerTest < ActionController::TestCase
                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
            format: "json"},
                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
            format: "json"},
-         session_for(:active))
+         session: session_for(:active))
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
@@ -70,13 +74,13 @@ class ActionsControllerTest < ActionController::TestCase
   end
 
   test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
   end
 
   test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
-    post(:combine_selected_files_into_collection, {
+    post(:combine_selected_files_into_collection, params: {
            selection: ['zzzzz-4zz18-duplicatenames1',
                        'zzzzz-4zz18-duplicatenames2',
                        'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-00000nonamecoll/foo',],
            format: "json"},
            selection: ['zzzzz-4zz18-duplicatenames1',
                        'zzzzz-4zz18-duplicatenames2',
                        'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-00000nonamecoll/foo',],
            format: "json"},
-         session_for(:active))
+         session: session_for(:active))
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
@@ -112,11 +116,11 @@ class ActionsControllerTest < ActionController::TestCase
   end
 
   test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
   end
 
   test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
-    post(:combine_selected_files_into_collection, {
+    post(:combine_selected_files_into_collection, params: {
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
                        'zzzzz-4zz18-foonbarfilesdir'],
            format: "json"},
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
                        'zzzzz-4zz18-foonbarfilesdir'],
            format: "json"},
-         session_for(:active))
+         session: session_for(:active))
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
@@ -140,11 +144,11 @@ class ActionsControllerTest < ActionController::TestCase
   end
 
   test "combine foo files from two different collection streams and expect proper filename suffixes" do
   end
 
   test "combine foo files from two different collection streams and expect proper filename suffixes" do
-    post(:combine_selected_files_into_collection, {
+    post(:combine_selected_files_into_collection, params: {
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
            format: "json"},
            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
                        'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
            format: "json"},
-         session_for(:active))
+         session: session_for(:active))
 
     assert_response 302   # collection created and redirected to new collection page
 
 
     assert_response 302   # collection created and redirected to new collection page
 
@@ -160,4 +164,43 @@ class ActionsControllerTest < ActionController::TestCase
     assert_includes(manifest_text, 'foo')
     assert_includes(manifest_text, 'foo(1)')
   end
     assert_includes(manifest_text, 'foo')
     assert_includes(manifest_text, 'foo(1)')
   end
+
+  [
+    ['collections', 'user_agreement_in_anonymously_accessible_project'],
+    ['groups', 'anonymously_accessible_project'],
+    ['jobs', 'running_job_in_publicly_accessible_project'],
+    ['pipeline_instances', 'pipeline_in_publicly_accessible_project'],
+    ['pipeline_templates', 'pipeline_template_in_publicly_accessible_project'],
+  ].each do |dm, fixture|
+    test "access show method for public #{dm} and expect to see page" do
+      Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
+      get(:show, params: {uuid: api_fixture(dm)[fixture]['uuid']})
+      assert_response :redirect
+      if dm == 'groups'
+        assert_includes @response.redirect_url, "projects/#{fixture['uuid']}"
+      else
+        assert_includes @response.redirect_url, "#{dm}/#{fixture['uuid']}"
+      end
+    end
+  end
+
+  [
+    ['collections', 'foo_collection_in_aproject', 404],
+    ['groups', 'subproject_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
+    ['jobs', 'job_with_latest_version', 404],
+    ['pipeline_instances', 'pipeline_owned_by_active_in_home', 404],
+    ['pipeline_templates', 'template_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
+    ['traits', 'owned_by_aproject_with_no_name', :redirect],
+  ].each do |dm, fixture, expected|
+    test "access show method for non-public #{dm} and expect #{expected}" do
+      Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
+      get(:show, params: {uuid: api_fixture(dm)[fixture]['uuid']})
+      assert_response expected
+      if expected == 404
+        assert_includes @response.inspect, 'Log in'
+      else
+        assert_match /\/users\/welcome/, @response.redirect_url
+      end
+    end
+  end
 end
 end