1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 require 'helpers/repository_stub_helper'
7 require 'helpers/share_object_helper'
9 class RepositoriesControllerTest < ActionController::TestCase
10 include RepositoryStubHelper
11 include ShareObjectHelper
17 test "#{user} shares repository with a user and group" do
18 uuid_list = [api_fixture("groups")["future_project_viewing_group"]["uuid"],
19 api_fixture("users")["future_project_user"]["uuid"]]
21 id: api_fixture("repositories")["foo"]["uuid"],
25 assert_response :success
26 assert_equal(uuid_list, json_response["success"])
30 test "user with repository read permission cannot add permissions" do
31 share_uuid = api_fixture("users")["project_viewer"]["uuid"]
33 id: api_fixture("repositories")["arvados"]["uuid"],
36 session_for(:spectator))
38 assert(json_response["errors"].andand.
39 any? { |msg| msg.start_with?("#{share_uuid}: ") },
40 "JSON response missing properly formatted sharing error")
43 test "admin can_manage repository" do
44 assert user_can_manage(:admin, api_fixture("repositories")["foo"])
47 test "owner can_manage repository" do
48 assert user_can_manage(:active, api_fixture("repositories")["foo"])
51 test "viewer cannot manage repository" do
52 refute user_can_manage(:spectator, api_fixture("repositories")["arvados"])
56 [:active, ['#Sharing', '#Advanced']],
57 [:admin, ['#Attributes', '#Sharing', '#Advanced']],
58 ].each do |user, expected_panes|
59 test "#{user} sees panes #{expected_panes}" do
61 id: api_fixture('repositories')['foo']['uuid']
63 assert_response :success
65 panes = css_select('[data-toggle=tab]').each do |pane|
66 pane_name = pane.attributes['href'].value
67 assert_includes expected_panes, pane_name
72 ### Browse repository content
74 [:active, :spectator].each do |user|
75 test "show tree to #{user}" do
76 reset_api_fixtures_after_test false
77 sha1, _, _ = stub_repo_content
79 id: api_fixture('repositories')['foo']['uuid'],
82 assert_response :success
83 assert_select 'tr td a', 'COPYING'
84 assert_select 'tr td', '625 bytes'
85 assert_select 'tr td a', 'apps'
86 assert_select 'tr td a', 'workbench'
87 assert_select 'tr td a', 'Gemfile'
88 assert_select 'tr td', '33.7 KiB'
91 test "show commit to #{user}" do
92 reset_api_fixtures_after_test false
93 sha1, commit, _ = stub_repo_content
95 id: api_fixture('repositories')['foo']['uuid'],
98 assert_response :success
99 assert_select 'pre', commit
102 test "show blob to #{user}" do
103 reset_api_fixtures_after_test false
104 sha1, _, filedata = stub_repo_content filename: 'COPYING'
106 id: api_fixture('repositories')['foo']['uuid'],
110 assert_response :success
111 assert_select 'pre', filedata
115 ['', '/'].each do |path|
116 test "show tree with path '#{path}'" do
117 reset_api_fixtures_after_test false
118 sha1, _, _ = stub_repo_content filename: 'COPYING'
120 id: api_fixture('repositories')['foo']['uuid'],
123 }, session_for(:active)
124 assert_response :success
125 assert_select 'tr td', 'COPYING'
129 test "get repositories lists linked as well as owned repositories" do
131 partial: :repositories_rows,
134 get :index, params, session_for(:active)
135 assert_response :success
136 repos = assigns(:objects)
138 assert_not_empty repos, "my_repositories should not be empty"
139 repo_uuids = repos.map(&:uuid)
140 assert_includes repo_uuids, api_fixture('repositories')['repository2']['uuid'] # owned by active
141 assert_includes repo_uuids, api_fixture('repositories')['repository4']['uuid'] # shared with active
142 assert_includes repo_uuids, api_fixture('repositories')['arvados']['uuid'] # shared with all_users