1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class LinkTest < ActiveSupport::TestCase
11 set_user_from_auth :admin_trustedclient
14 test "cannot delete an object referenced by unwritable links" do
15 ob = act_as_user users(:active) do
18 link = act_as_user users(:admin) do
19 Link.create(tail_uuid: users(:active).uuid,
24 assert_equal users(:admin).uuid, link.owner_uuid
25 assert_raises(ArvadosModel::PermissionDeniedError,
26 "should not delete #{ob.uuid} with link #{link.uuid}") do
27 act_as_user users(:active) do
31 act_as_user users(:admin) do
34 assert_empty Link.where(uuid: link.uuid)
37 def new_active_link_valid?(link_attrs)
38 set_user_from_auth :active
41 create({link_class: "permission",
43 head_uuid: groups(:aproject).uuid,
46 rescue ArvadosModel::PermissionDeniedError
51 test "non-admin project owner can make it public" do
52 assert(new_active_link_valid?(tail_uuid: groups(:anonymous_group).uuid),
53 "non-admin project owner can't make their project public")
56 test "link granting permission to nonexistent user is invalid" do
57 refute new_active_link_valid?(tail_uuid:
58 users(:active).uuid.sub(/-\w+$/, "-#{'z' * 15}"))
61 test "link granting non-project permission to unreadable user is invalid" do
62 refute new_active_link_valid?(tail_uuid: users(:admin).uuid,
63 head_uuid: collections(:bar_file).uuid)
66 test "user can't add a Collection to a Project without permission" do
67 refute new_active_link_valid?(link_class: "name",
68 name: "Permission denied test name",
69 tail_uuid: collections(:bar_file).uuid)
72 test "user can't add a User to a Project" do
73 # Users *can* give other users permissions to projects.
74 # This test helps ensure that that exception is specific to permissions.
75 refute new_active_link_valid?(link_class: "name",
76 name: "Permission denied test name",
77 tail_uuid: users(:admin).uuid)
80 test "link granting project permissions to unreadable user is invalid" do
81 refute new_active_link_valid?(tail_uuid: users(:admin).uuid)
84 test "permission link can't exist on past collection versions" do
85 refute new_active_link_valid?(tail_uuid: groups(:public).uuid,
86 head_uuid: collections(:w_a_z_file_version_1).uuid)