X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/76e20e694fbe708e17e57a2e0b1c36aca6e8d7d0..0632129bf7861a6ca3ef4ff4e21006a5f11e8be0:/services/api/test/unit/group_test.rb diff --git a/services/api/test/unit/group_test.rb b/services/api/test/unit/group_test.rb index 6b419ad64a..4672acd097 100644 --- a/services/api/test/unit/group_test.rb +++ b/services/api/test/unit/group_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class GroupTest < ActiveSupport::TestCase @@ -5,19 +9,20 @@ class GroupTest < ActiveSupport::TestCase test "cannot set owner_uuid to object with existing ownership cycle" do set_user_from_auth :active_trustedclient - # First make sure we have lots of permission on the bad group + # First make sure we have lots of permission on the bad group by + # renaming it to "{current name} is mine all mine" g = groups(:bad_group_has_ownership_cycle_b) - g.name += " xyz" + g.name += " is mine all mine" assert g.save, "active user should be able to modify group #{g.uuid}" # Use the group as the owner of a new object s = Specimen. create(owner_uuid: groups(:bad_group_has_ownership_cycle_b).uuid) - assert s.valid?, "ownership should pass validation" + assert s.valid?, "ownership should pass validation #{s.errors.messages}" assert_equal false, s.save, "should not save object with #{g.uuid} as owner" # Use the group as the new owner of an existing object - s = specimens(:in_afolder) + s = specimens(:in_aproject) s.owner_uuid = groups(:bad_group_has_ownership_cycle_b).uuid assert s.valid?, "ownership should pass validation" assert_equal false, s.save, "should not save object with #{g.uuid} as owner" @@ -26,11 +31,8 @@ class GroupTest < ActiveSupport::TestCase test "cannot create a new ownership cycle" do set_user_from_auth :active_trustedclient - g_foo = Group.create(name: "foo") - g_foo.save! - - g_bar = Group.create(name: "bar") - g_bar.save! + g_foo = Group.create!(name: "foo") + g_bar = Group.create!(name: "bar") g_foo.owner_uuid = g_bar.uuid assert g_foo.save, lambda { g_foo.errors.messages } @@ -43,11 +45,11 @@ class GroupTest < ActiveSupport::TestCase test "cannot create a single-object ownership cycle" do set_user_from_auth :active_trustedclient - g_foo = Group.create(name: "foo") + g_foo = Group.create!(name: "foo") assert g_foo.save # Ensure I have permission to manage this group even when its owner changes - perm_link = Link.create(tail_uuid: users(:active).uuid, + perm_link = Link.create!(tail_uuid: users(:active).uuid, head_uuid: g_foo.uuid, link_class: 'permission', name: 'can_manage') @@ -58,4 +60,109 @@ class GroupTest < ActiveSupport::TestCase assert g_foo.errors.messages[:owner_uuid].join(" ").match(/ownership cycle/) end + test "delete group hides contents" do + set_user_from_auth :active_trustedclient + + g_foo = Group.create!(name: "foo") + col = Collection.create!(owner_uuid: g_foo.uuid) + + assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? + g_foo.update! is_trashed: true + assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty? + assert Collection.readable_by(users(:active), {:include_trash => true}).where(uuid: col.uuid).any? + g_foo.update! is_trashed: false + assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? + end + + test "delete group" do + set_user_from_auth :active_trustedclient + + g_foo = Group.create!(name: "foo") + g_bar = Group.create!(name: "bar", owner_uuid: g_foo.uuid) + g_baz = Group.create!(name: "baz", owner_uuid: g_bar.uuid) + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + g_foo.update! is_trashed: true + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any? + end + + + test "delete subgroup" do + set_user_from_auth :active_trustedclient + + g_foo = Group.create!(name: "foo") + g_bar = Group.create!(name: "bar", owner_uuid: g_foo.uuid) + g_baz = Group.create!(name: "baz", owner_uuid: g_bar.uuid) + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + g_bar.update! is_trashed: true + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any? + end + + test "delete subsubgroup" do + set_user_from_auth :active_trustedclient + + g_foo = Group.create!(name: "foo") + g_bar = Group.create!(name: "bar", owner_uuid: g_foo.uuid) + g_baz = Group.create!(name: "baz", owner_uuid: g_bar.uuid) + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + g_baz.update! is_trashed: true + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + assert Group.readable_by(users(:active), {:include_trash => true}).where(uuid: g_baz.uuid).any? + end + + + test "delete group propagates to subgroups" do + set_user_from_auth :active_trustedclient + + g_foo = groups(:trashed_project) + g_bar = groups(:trashed_subproject) + g_baz = groups(:trashed_subproject3) + col = collections(:collection_in_trashed_subproject) + + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty? + + set_user_from_auth :admin + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).empty? + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + assert Collection.readable_by(users(:active)).where(uuid: col.uuid).empty? + + set_user_from_auth :active_trustedclient + g_foo.update! is_trashed: false + assert Group.readable_by(users(:active)).where(uuid: g_foo.uuid).any? + assert Group.readable_by(users(:active)).where(uuid: g_bar.uuid).any? + assert Collection.readable_by(users(:active)).where(uuid: col.uuid).any? + + # this one should still be deleted. + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).empty? + + g_baz.update! is_trashed: false + assert Group.readable_by(users(:active)).where(uuid: g_baz.uuid).any? + end + end