21815: Remove UUID and hash columns from trigram indexes
[arvados.git] / services / api / test / helpers / users_test_helper.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 module UsersTestHelper
6   include CurrentApiClient
7
8   def verify_link(response_items, link_object_name, expect_link, link_class,
9         link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
10     link = find_obj_in_resp response_items, 'arvados#link', link_object_name
11
12     if !expect_link
13       assert_nil link, "Expected no link for #{link_object_name}"
14       return
15     end
16
17     assert_not_nil link, "Expected link for #{link_object_name}"
18
19     if fetch_object
20       object = Object.const_get(class_name).where(name: head_uuid)
21       assert [] != object, "expected #{class_name} with name #{head_uuid}"
22       head_uuid = object.first[:uuid]
23     end
24     assert_equal link_class, link['link_class'],
25         "did not find expected link_class for #{link_object_name}"
26
27     assert_equal link_name, link['name'],
28         "did not find expected link_name for #{link_object_name}"
29
30     assert_equal tail_uuid, link['tail_uuid'],
31         "did not find expected tail_uuid for #{link_object_name}"
32
33     assert_equal head_kind, link['head_kind'],
34         "did not find expected head_kind for #{link_object_name}"
35
36     assert_equal head_uuid, link['head_uuid'],
37         "did not find expected head_uuid for #{link_object_name}"
38   end
39
40   def verify_system_group_permission_link_for user_uuid
41     assert_equal 1, Link.where(link_class: 'permission',
42                                name: 'can_manage',
43                                tail_uuid: system_group_uuid,
44                                head_uuid: user_uuid).count
45   end
46
47   def verify_link_existence uuid, email, expect_oid_login_perms,
48       expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
49     # verify that all links are deleted for the user
50     oid_login_perms = Link.where(tail_uuid: email,
51                                  link_class: 'permission',
52                                  name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
53
54     # these don't get added any more!  they shouldn't appear ever.
55     assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
56
57     # these don't get added any more!  they shouldn't appear ever.
58     repo_perms = Link.where(tail_uuid: uuid,
59                             link_class: 'permission').where("head_uuid like ?", '_____-s0uqq-_______________')
60     assert !repo_perms.any?, "expected all repo_perms deleted"
61
62     vm_login_perms = Link.
63       where(tail_uuid: uuid,
64             link_class: 'permission',
65             name: 'can_login').
66       where("head_uuid like ?",
67             VirtualMachine.uuid_like_pattern).
68       where('uuid <> ?',
69             links(:auto_setup_vm_login_username_can_login_to_test_vm).uuid)
70     if expect_vm_perms
71       assert vm_login_perms.any?, "expected vm_login_perms"
72     else
73       assert !vm_login_perms.any?, "expected all vm_login_perms deleted"
74     end
75
76     group_write_perms = Link.where(tail_uuid: uuid,
77                                   head_uuid: all_users_group_uuid,
78                                   link_class: 'permission',
79                                   name: 'can_write')
80     if expect_group_perms
81       assert group_write_perms.any?, "expected all users group write perms"
82     else
83       assert !group_write_perms.any?, "expected all users group write perms deleted"
84     end
85
86     signed_uuids = Link.where(link_class: 'signature',
87                               tail_uuid: uuid)
88
89     if expect_signatures
90       assert signed_uuids.any?, "expected signatures"
91     else
92       assert !signed_uuids.any?, "expected all signatures deleted"
93     end
94
95   end
96
97 end