+ test "non-admin project owner can make it public" do
+ assert(new_active_link_valid?(tail_uuid: groups(:anonymous_group).uuid),
+ "non-admin project owner can't make their project public")
+ end
+
+ test "link granting permission to nonexistent user is invalid" do
+ refute new_active_link_valid?(tail_uuid:
+ users(:active).uuid.sub(/-\w+$/, "-#{'z' * 15}"))
+ end
+
+ test "link granting permission to remote user is valid" do
+ refute new_active_link_valid?(tail_uuid:
+ users(:active).uuid.sub(/^\w+-/, "foooo-"))
+ Rails.configuration.RemoteClusters = Rails.configuration.RemoteClusters.merge({foooo: ActiveSupport::InheritableOptions.new({Host: "bar.com"})})
+ assert new_active_link_valid?(tail_uuid:
+ users(:active).uuid.sub(/^\w+-/, "foooo-"))
+ end
+
+ test "link granting non-project permission to unreadable user is invalid" do
+ refute new_active_link_valid?(tail_uuid: users(:admin).uuid,
+ head_uuid: collections(:bar_file).uuid)
+ end
+
+ test "user can't add a Collection to a Project without permission" do
+ refute new_active_link_valid?(link_class: "name",
+ name: "Permission denied test name",
+ tail_uuid: collections(:bar_file).uuid)
+ end
+
+ test "user can't add a User to a Project" do
+ # Users *can* give other users permissions to projects.
+ # This test helps ensure that that exception is specific to permissions.
+ refute new_active_link_valid?(link_class: "name",
+ name: "Permission denied test name",
+ tail_uuid: users(:admin).uuid)
+ end
+
+ test "link granting project permissions to unreadable user is invalid" do
+ refute new_active_link_valid?(tail_uuid: users(:admin).uuid)
+ end
+
+ test "permission link can't exist on past collection versions" do
+ refute new_active_link_valid?(tail_uuid: groups(:public).uuid,
+ head_uuid: collections(:w_a_z_file_version_1).uuid)
+ end
+
+ def create_overlapping_permissions(names=[], attrs={})
+ names.map do |name|
+ link = Link.create!({
+ link_class: "tmp",
+ tail_uuid: users(:active).uuid,
+ head_uuid: collections(:baz_file).uuid,
+ name: name,
+ }.merge(attrs).merge({name: name}))
+ ActiveRecord::Base.connection.execute "update links set link_class='permission' where uuid='#{link.uuid}'"
+ link.uuid