3 class LinkTest < ActiveSupport::TestCase
7 set_user_from_auth :admin_trustedclient
10 test "cannot delete an object referenced by unwritable links" do
11 ob = act_as_user users(:active) do
14 link = act_as_user users(:admin) do
15 Link.create(tail_uuid: users(:active).uuid,
20 assert_equal users(:admin).uuid, link.owner_uuid
21 assert_raises(ArvadosModel::PermissionDeniedError,
22 "should not delete #{ob.uuid} with link #{link.uuid}") do
23 act_as_user users(:active) do
27 act_as_user users(:admin) do
30 assert_empty Link.where(uuid: link.uuid)
33 def new_active_link_valid?(link_attrs)
34 set_user_from_auth :active
37 create({link_class: "permission",
39 head_uuid: groups(:aproject).uuid,
42 rescue ArvadosModel::PermissionDeniedError
47 test "non-admin project owner can make it public" do
48 assert(new_active_link_valid?(tail_uuid: groups(:anonymous_group).uuid),
49 "non-admin project owner can't make their project public")
52 test "link granting permission to nonexistent user is invalid" do
53 refute new_active_link_valid?(tail_uuid:
54 users(:active).uuid.sub(/-\w+$/, "-#{'z' * 15}"))
57 test "link granting non-project permission to unreadable user is invalid" do
58 refute new_active_link_valid?(tail_uuid: users(:admin).uuid,
59 head_uuid: collections(:bar_file).uuid)
62 test "user can't add a Collection to a Project without permission" do
63 refute new_active_link_valid?(link_class: "name",
64 name: "Permission denied test name",
65 tail_uuid: collections(:bar_file).uuid)
68 test "user can't add a User to a Project" do
69 # Users *can* give other users permissions to projects.
70 # This test helps ensure that that exception is specific to permissions.
71 refute new_active_link_valid?(link_class: "name",
72 name: "Permission denied test name",
73 tail_uuid: users(:admin).uuid)
76 test "link granting project permissions to unreadable user is invalid" do
77 refute new_active_link_valid?(tail_uuid: users(:admin).uuid)