3 class LinkTest < ActiveSupport::TestCase
7 set_user_from_auth :admin_trustedclient
10 test "cannot delete an object referenced by links" do
12 link = Link.create(tail_uuid: users(:active).uuid,
16 assert_equal users(:admin).uuid, link.owner_uuid
17 assert_raises(ActiveRecord::DeleteRestrictionError,
18 "should not delete #{ob.uuid} with link #{link.uuid}") do
23 def new_active_link_valid?(link_attrs)
24 set_user_from_auth :active
27 create({link_class: "permission",
29 head_uuid: groups(:aproject).uuid,
32 rescue ArvadosModel::PermissionDeniedError
37 test "non-admin project owner can make it public" do
38 assert(new_active_link_valid?(tail_uuid: groups(:anonymous_group).uuid),
39 "non-admin project owner can't make their project public")
42 test "link granting permission to nonexistent user is invalid" do
43 refute new_active_link_valid?(tail_uuid:
44 users(:active).uuid.sub(/-\w+$/, "-#{'z' * 15}"))
47 test "link granting non-project permission to unreadable user is invalid" do
48 refute new_active_link_valid?(tail_uuid: users(:admin).uuid,
49 head_uuid: collections(:bar_file).uuid)
52 test "user can't add a Collection to a Project without permission" do
53 refute new_active_link_valid?(link_class: "name",
54 name: "Permission denied test name",
55 tail_uuid: collections(:bar_file).uuid)
58 test "user can't add a User to a Project" do
59 # Users *can* give other users permissions to projects.
60 # This test helps ensure that that exception is specific to permissions.
61 refute new_active_link_valid?(link_class: "name",
62 name: "Permission denied test name",
63 tail_uuid: users(:admin).uuid)
66 test "link granting project permissions to unreadable user is invalid" do
67 refute new_active_link_valid?(tail_uuid: users(:admin).uuid)