4759: Add functional tests for timestamp precision.
[arvados.git] / services / api / test / helpers / users_test_helper.rb
1 module UsersTestHelper
2   def verify_link(response_items, link_object_name, expect_link, link_class,
3         link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
4     link = find_obj_in_resp response_items, 'arvados#link', link_object_name
5
6     if !expect_link
7       assert_nil link, "Expected no link for #{link_object_name}"
8       return
9     end
10
11     assert_not_nil link, "Expected link for #{link_object_name}"
12
13     if fetch_object
14       object = Object.const_get(class_name).where(name: head_uuid)
15       assert [] != object, "expected #{class_name} with name #{head_uuid}"
16       head_uuid = object.first[:uuid]
17     end
18     assert_equal link_class, link['link_class'],
19         "did not find expected link_class for #{link_object_name}"
20
21     assert_equal link_name, link['name'],
22         "did not find expected link_name for #{link_object_name}"
23
24     assert_equal tail_uuid, link['tail_uuid'],
25         "did not find expected tail_uuid for #{link_object_name}"
26
27     assert_equal head_kind, link['head_kind'],
28         "did not find expected head_kind for #{link_object_name}"
29
30     assert_equal head_uuid, link['head_uuid'],
31         "did not find expected head_uuid for #{link_object_name}"
32   end
33
34   def verify_system_group_permission_link_for user_uuid
35     assert_equal 1, Link.where(link_class: 'permission',
36                                name: 'can_manage',
37                                tail_uuid: system_group_uuid,
38                                head_uuid: user_uuid).count
39   end
40
41   def verify_link_existence uuid, email, expect_oid_login_perms,
42       expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
43     # verify that all links are deleted for the user
44     oid_login_perms = Link.where(tail_uuid: email,
45                                  link_class: 'permission',
46                                  name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
47     if expect_oid_login_perms
48       assert oid_login_perms.any?, "expected oid_login_perms"
49     else
50       assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
51     end
52
53     repo_perms = Link.where(tail_uuid: uuid,
54                             link_class: 'permission',
55                             name: 'can_manage').where("head_uuid like ?", Repository.uuid_like_pattern)
56     if expect_repo_perms
57       assert repo_perms.any?, "expected repo_perms"
58     else
59       assert !repo_perms.any?, "expected all repo_perms deleted"
60     end
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 = Group.where(name: 'All users').select do |g|
77       g[:uuid].match /-f+$/
78     end.first
79     group_read_perms = Link.where(tail_uuid: uuid,
80                                   head_uuid: group[:uuid],
81                                   link_class: 'permission',
82                                   name: 'can_read')
83     if expect_group_perms
84       assert group_read_perms.any?, "expected all users group read perms"
85     else
86       assert !group_read_perms.any?, "expected all users group perm deleted"
87     end
88
89     signed_uuids = Link.where(link_class: 'signature',
90                               tail_uuid: uuid)
91
92     if expect_signatures
93       assert signed_uuids.any?, "expected signatures"
94     else
95       assert !signed_uuids.any?, "expected all signatures deleted"
96     end
97
98   end
99
100 end