Merge branch 'master' into 3153-auto-setup-user
[arvados.git] / services / api / test / unit / user_test.rb
1 require 'test_helper'
2
3 class UserTest < ActiveSupport::TestCase
4   include CurrentApiClient
5
6   # The fixture services/api/test/fixtures/users.yml serves as the input for this test case
7   setup do
8     # Make sure system_user exists before making "pre-test users" list
9     system_user
10   end
11
12 =begin
13   test "check non-admin active user properties" do
14     @active_user = users(:active)     # get the active user
15     assert !@active_user.is_admin, 'is_admin should not be set for a non-admin user'
16     assert @active_user.is_active, 'user should be active'
17     assert @active_user.is_invited, 'is_invited should be set'
18     assert_not_nil @active_user.prefs, "user's preferences should be non-null, but may be size zero"
19     assert (@active_user.can? :read=>"#{@active_user.uuid}"), "user should be able to read own object"
20     assert (@active_user.can? :write=>"#{@active_user.uuid}"), "user should be able to write own object"
21     assert (@active_user.can? :manage=>"#{@active_user.uuid}"), "user should be able to manage own object"
22
23     assert @active_user.groups_i_can(:read).size > 0, "active user should be able read at least one group"
24
25     # non-admin user cannot manage or write other user objects
26     @uninvited_user = users(:inactive_uninvited)     # get the uninvited user
27     assert !(@active_user.can? :read=>"#{@uninvited_user.uuid}")
28     assert !(@active_user.can? :write=>"#{@uninvited_user.uuid}")
29     assert !(@active_user.can? :manage=>"#{@uninvited_user.uuid}")
30   end
31
32   test "check admin user properties" do
33     @admin_user = users(:admin)     # get the admin user
34     assert @admin_user.is_admin, 'is_admin should be set for admin user'
35     assert @admin_user.is_active, 'admin user cannot be inactive'
36     assert @admin_user.is_invited, 'is_invited should be set'
37     assert_not_nil @admin_user.uuid.size, "user's uuid should be non-null"
38     assert_not_nil @admin_user.prefs, "user's preferences should be non-null, but may be size zero"
39     assert @admin_user.identity_url.size > 0, "user's identity url is expected"
40     assert @admin_user.can? :read=>"#{@admin_user.uuid}"
41     assert @admin_user.can? :write=>"#{@admin_user.uuid}"
42     assert @admin_user.can? :manage=>"#{@admin_user.uuid}"
43
44     assert @admin_user.groups_i_can(:read).size > 0, "admin active user should be able read at least one group"
45     assert @admin_user.groups_i_can(:write).size > 0, "admin active user should be able write to at least one group"
46     assert @admin_user.groups_i_can(:manage).size > 0, "admin active user should be able manage at least one group"
47
48     # admin user can also write or manage other users
49     @uninvited_user = users(:inactive_uninvited)     # get the uninvited user
50     assert @admin_user.can? :read=>"#{@uninvited_user.uuid}"
51     assert @admin_user.can? :write=>"#{@uninvited_user.uuid}"
52     assert @admin_user.can? :manage=>"#{@uninvited_user.uuid}"
53   end
54
55   test "check inactive and uninvited user properties" do
56     @uninvited_user = users(:inactive_uninvited)     # get the uninvited user
57     assert !@uninvited_user.is_admin, 'is_admin should not be set for a non-admin user'
58     assert !@uninvited_user.is_active, 'user should be inactive'
59     assert !@uninvited_user.is_invited, 'is_invited should not be set'
60     assert @uninvited_user.can? :read=>"#{@uninvited_user.uuid}"
61     assert @uninvited_user.can? :write=>"#{@uninvited_user.uuid}"
62     assert @uninvited_user.can? :manage=>"#{@uninvited_user.uuid}"
63
64     assert @uninvited_user.groups_i_can(:read).size == 1, "inactive and uninvited user can only read anonymous user group"
65     assert @uninvited_user.groups_i_can(:read).first.ends_with? 'anonymouspublic' , "inactive and uninvited user can only read anonymous user group"
66     assert @uninvited_user.groups_i_can(:write).size == 0, "inactive and uninvited user should not be able write to any groups"
67     assert @uninvited_user.groups_i_can(:manage).size == 0, "inactive and uninvited user should not be able manage any groups"
68   end
69
70   test "find user method checks" do
71     User.find(:all).each do |user|
72       assert_not_nil user.uuid, "non-null uuid expected for " + user.full_name
73     end
74
75     user = users(:active)     # get the active user
76
77     found_user = User.find(user.id)   # find a user by the row id
78
79     assert_equal found_user.full_name, user.first_name + ' ' + user.last_name
80     assert_equal found_user.identity_url, user.identity_url
81   end
82
83   test "full name should not contain spurious whitespace" do
84     set_user_from_auth :admin
85
86     user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: 'foo@example.com' })
87
88     assert_equal '', user.full_name
89
90     user.first_name = 'John'
91     user.last_name = 'Smith'
92
93     assert_equal user.first_name + ' ' + user.last_name, user.full_name
94   end
95
96   test "create new user" do
97     set_user_from_auth :admin
98
99     @all_users = User.find(:all)
100
101     user = User.new
102     user.first_name = "first_name_for_newly_created_user"
103     user.save
104
105     # verify there is one extra user in the db now
106     assert_equal @all_users.size+1, User.find(:all).size
107
108     user = User.find(user.id)   # get the user back
109     assert_equal(user.first_name, 'first_name_for_newly_created_user')
110     assert_not_nil user.uuid, 'uuid should be set for newly created user'
111     assert_nil user.email, 'email should be null for newly created user, because it was not passed in'
112     assert_nil user.identity_url, 'identity_url should be null for newly created user, because it was not passed in'
113
114     user.first_name = 'first_name_for_newly_created_user_updated'
115     user.save
116     user = User.find(user.id)   # get the user back
117     assert_equal(user.first_name, 'first_name_for_newly_created_user_updated')
118   end
119
120   test "create new user with notifications" do
121     set_user_from_auth :admin
122
123     create_user_and_verify_setup_and_notifications true, 'active-notify-address@example.com', 'inactive-notify-address@example.com', nil, false
124     create_user_and_verify_setup_and_notifications true, 'active-notify-address@example.com', [], nil, false
125     create_user_and_verify_setup_and_notifications true, [], [], nil, false
126     create_user_and_verify_setup_and_notifications false, 'active-notify-address@example.com', 'inactive-notify-address@example.com', nil, false
127     create_user_and_verify_setup_and_notifications false, [], 'inactive-notify-address@example.com', nil, false
128     create_user_and_verify_setup_and_notifications false, [], [], nil, false
129   end
130 =end
131   [
132     [false, [], [], 'inactive-none@example.com', false, false, true],
133     [false, [], [], 'inactive-vm@example.com', true, false, true],
134     [false, [], [], 'inactive-repo@example.com', false, true, true],
135     [false, [], [], 'inactive-both@example.com', true, true, true],
136
137     [true, 'active-notify@example.com', 'inactive-notify@example.com', 'active-none@example.com', false, false, true],
138     [true, 'active-notify@example.com', 'inactive-notify@example.com', 'active-vm@example.com', true, false, true],
139     [true, 'active-notify@example.com', 'inactive-notify@example.com', 'active-repo@example.com', false, true, true],
140     [true, 'active-notify@example.com', 'inactive-notify@example.com', 'active-both@example.com', true, true, true],
141
142     [false, [], [], nil, true, true, false],
143
144     [false, [], [], 'arvados', true, true, false],
145     [false, [], [], 'arva_dos', true, true, false],
146     [false, [], [], 'arvados', false, false, true],   # since we are not creating repo and vm login, this blaklisted name is not a problem
147
148     [false, [], [], 'arvados@example.com', false, false, true],   # since we are not creating repo and vm login, this blaklisted name is not a problem
149     [false, [], [], 'arva_dos@example.com', false, false, true],  # since we are not creating repo and vm login, this blaklisted name is not a problem
150
151     [false, [], [], '@example.com', true, false, false],  # incorrect format
152     [false, [], [], '@example.com', false, true, false],
153     [false, [], [], '@example.com', false, false, true],  # no repo and vm login, so no issue with email format
154
155     [false, [], [], '^^incorrect_format@example.com', true, true, false],
156
157     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'foo@example.com', true, true, true],  # existing repository name 'foo'
158     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'foo@example.com', true, false, true],  # existing repository name 'foo'
159     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'foo@example.com', false, true, true],  # existing repository name 'foo'
160     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'foo@example.com', false, false, true],  # existing repository name 'foo', but we are not creating repo or login link
161
162     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', true, true, true], # existing vm login name
163     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', true, false, true], # existing vm login name
164     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', false, true, true], # existing vm login name
165     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', false, false, true], # existing vm login name, but we are not creating repo or login link
166
167     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'r_o_o_t@example.com', true, false, false], # blacklisted name after removing -._ characters
168     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'r_o.o-t@example.com', false, true, false], # blacklisted name after removing -._ characters
169
170     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'r_o_o_t@example.com', false, false, true], # blacklisted after removing -._, but ok because no repo and vm login
171
172     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'r_o. o-t@example.com', true, true, false], # invalid because of space character
173
174     [false, 'active-notify@example.com', 'inactive-notify@example.com', '*!*@example.com', true, false, false], # username is invalid format
175     [false, 'active-notify@example.com', 'inactive-notify@example.com', '*!*@example.com', false, false, true], # since no repo and vm login, username is ok (not validated)
176     [false, 'active-notify@example.com', 'inactive-notify@example.com', '4ad@example.com', true, true, false], # username is invalid format
177     [false, 'active-notify@example.com', 'inactive-notify@example.com', '4ad@example.com', false, false, true], # no repo or vm login, so format not checked
178     [false, 'active-notify@example.com', 'inactive-notify@example.com', '&4ad@example.com', true, true, false], # username is invalid format
179     [false, 'active-notify@example.com', 'inactive-notify@example.com', '&4ad@example.com', false, false, true], # no repo or vm login, so format not checked
180
181   ].each do |active, active_recipients, inactive_recipients, email, auto_setup_vm, auto_setup_repo, valid_username|
182     test "create new user with auto setup #{email} #{auto_setup_vm} #{auto_setup_repo}" do
183       auto_setup_new_users = Rails.configuration.auto_setup_new_users
184       auto_setup_new_users_with_vm_uuid = Rails.configuration.auto_setup_new_users_with_vm_uuid
185       auto_setup_new_users_with_repository = Rails.configuration.auto_setup_new_users_with_repository
186
187       begin
188         set_user_from_auth :admin
189
190         Rails.configuration.auto_setup_new_users = true
191
192         if auto_setup_vm
193           Rails.configuration.auto_setup_new_users_with_vm_uuid = virtual_machines(:testvm)['uuid']
194         else
195           Rails.configuration.auto_setup_new_users_with_vm_uuid = false
196         end
197
198         Rails.configuration.auto_setup_new_users_with_repository = auto_setup_repo
199
200         create_user_and_verify_setup_and_notifications active, active_recipients, inactive_recipients, email, valid_username
201       ensure
202         Rails.configuration.auto_setup_new_users = auto_setup_new_users
203         Rails.configuration.auto_setup_new_users_with_vm_uuid = auto_setup_new_users_with_vm_uuid
204         Rails.configuration.auto_setup_new_users_with_repository = auto_setup_new_users_with_repository
205       end
206     end
207   end
208 =begin
209   test "update existing user" do
210     set_user_from_auth :active    # set active user as current user
211
212     @active_user = users(:active)     # get the active user
213
214     @active_user.first_name = "first_name_changed"
215     @active_user.save
216
217     @active_user = User.find(@active_user.id)   # get the user back
218     assert_equal(@active_user.first_name, 'first_name_changed')
219
220     # admin user also should be able to update the "active" user info
221     set_user_from_auth :admin # set admin user as current user
222     @active_user.first_name = "first_name_changed_by_admin_for_active_user"
223     @active_user.save
224
225     @active_user = User.find(@active_user.id)   # get the user back
226     assert_equal(@active_user.first_name, 'first_name_changed_by_admin_for_active_user')
227   end
228
229   test "delete a user and verify" do
230     @active_user = users(:active)     # get the active user
231     active_user_uuid = @active_user.uuid
232
233     set_user_from_auth :admin
234     @active_user.delete
235
236     found_deleted_user = false
237     User.find(:all).each do |user|
238       if user.uuid == active_user_uuid
239         found_deleted_user = true
240         break
241       end
242     end
243     assert !found_deleted_user, "found deleted user: "+active_user_uuid
244
245   end
246
247   test "create new user as non-admin user" do
248     set_user_from_auth :active
249
250     begin
251       user = User.new
252       user.save
253     rescue ArvadosModel::PermissionDeniedError => e
254     end
255     assert (e.message.include? 'PermissionDeniedError'),
256         'Expected PermissionDeniedError'
257   end
258
259   test "setup new user" do
260     set_user_from_auth :admin
261
262     email = 'foo@example.com'
263     openid_prefix = 'http://openid/prefix'
264
265     user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: email})
266
267     vm = VirtualMachine.create
268
269     response = User.setup user, openid_prefix, 'test_repo', vm.uuid
270
271     resp_user = find_obj_in_resp response, 'User'
272     verify_user resp_user, email
273
274     oid_login_perm = find_obj_in_resp response, 'Link', 'arvados#user'
275
276     verify_link oid_login_perm, 'permission', 'can_login', resp_user[:email],
277         resp_user[:uuid]
278
279     assert_equal openid_prefix, oid_login_perm[:properties]['identity_url_prefix'],
280         'expected identity_url_prefix not found for oid_login_perm'
281
282     group_perm = find_obj_in_resp response, 'Link', 'arvados#group'
283     verify_link group_perm, 'permission', 'can_read', resp_user[:uuid], nil
284
285     repo_perm = find_obj_in_resp response, 'Link', 'arvados#repository'
286     verify_link repo_perm, 'permission', 'can_manage', resp_user[:uuid], nil
287
288     vm_perm = find_obj_in_resp response, 'Link', 'arvados#virtualMachine'
289     verify_link vm_perm, 'permission', 'can_login', resp_user[:uuid], vm.uuid
290   end
291
292   test "setup new user with junk in database" do
293     set_user_from_auth :admin
294
295     email = 'foo@example.com'
296     openid_prefix = 'http://openid/prefix'
297
298     user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: email})
299
300     vm = VirtualMachine.create
301
302     # Set up the bogus Link
303     bad_uuid = 'zzzzz-tpzed-xyzxyzxyzxyzxyz'
304
305     resp_link = Link.create ({tail_uuid: email, link_class: 'permission',
306         name: 'can_login', head_uuid: bad_uuid})
307     resp_link.save(validate: false)
308
309     verify_link resp_link, 'permission', 'can_login', email, bad_uuid
310
311     response = User.setup user, openid_prefix, 'test_repo', vm.uuid
312
313     resp_user = find_obj_in_resp response, 'User'
314     verify_user resp_user, email
315
316     oid_login_perm = find_obj_in_resp response, 'Link', 'arvados#user'
317
318     verify_link oid_login_perm, 'permission', 'can_login', resp_user[:email],
319         resp_user[:uuid]
320
321     assert_equal openid_prefix, oid_login_perm[:properties]['identity_url_prefix'],
322         'expected identity_url_prefix not found for oid_login_perm'
323
324     group_perm = find_obj_in_resp response, 'Link', 'arvados#group'
325     verify_link group_perm, 'permission', 'can_read', resp_user[:uuid], nil
326
327     repo_perm = find_obj_in_resp response, 'Link', 'arvados#repository'
328     verify_link repo_perm, 'permission', 'can_manage', resp_user[:uuid], nil
329
330     vm_perm = find_obj_in_resp response, 'Link', 'arvados#virtualMachine'
331     verify_link vm_perm, 'permission', 'can_login', resp_user[:uuid], vm.uuid
332   end
333
334
335
336   test "setup new user in multiple steps" do
337     set_user_from_auth :admin
338
339     email = 'foo@example.com'
340     openid_prefix = 'http://openid/prefix'
341
342     user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: email})
343
344     response = User.setup user, openid_prefix
345
346     resp_user = find_obj_in_resp response, 'User'
347     verify_user resp_user, email
348
349     oid_login_perm = find_obj_in_resp response, 'Link', 'arvados#user'
350     verify_link oid_login_perm, 'permission', 'can_login', resp_user[:email],
351         resp_user[:uuid]
352     assert_equal openid_prefix, oid_login_perm[:properties]['identity_url_prefix'],
353         'expected identity_url_prefix not found for oid_login_perm'
354
355     group_perm = find_obj_in_resp response, 'Link', 'arvados#group'
356     verify_link group_perm, 'permission', 'can_read', resp_user[:uuid], nil
357
358     # invoke setup again with repo_name
359     response = User.setup user, openid_prefix, 'test_repo'
360     resp_user = find_obj_in_resp response, 'User', nil
361     verify_user resp_user, email
362     assert_equal user.uuid, resp_user[:uuid], 'expected uuid not found'
363
364     group_perm = find_obj_in_resp response, 'Link', 'arvados#group'
365     verify_link group_perm, 'permission', 'can_read', resp_user[:uuid], nil
366
367     repo_perm = find_obj_in_resp response, 'Link', 'arvados#repository'
368     verify_link repo_perm, 'permission', 'can_manage', resp_user[:uuid], nil
369
370     # invoke setup again with a vm_uuid
371     vm = VirtualMachine.create
372
373     response = User.setup user, openid_prefix, 'test_repo', vm.uuid
374
375     resp_user = find_obj_in_resp response, 'User', nil
376     verify_user resp_user, email
377     assert_equal user.uuid, resp_user[:uuid], 'expected uuid not found'
378
379     group_perm = find_obj_in_resp response, 'Link', 'arvados#group'
380     verify_link group_perm, 'permission', 'can_read', resp_user[:uuid], nil
381
382     repo_perm = find_obj_in_resp response, 'Link', 'arvados#repository'
383     verify_link repo_perm, 'permission', 'can_manage', resp_user[:uuid], nil
384
385     vm_perm = find_obj_in_resp response, 'Link', 'arvados#virtualMachine'
386     verify_link vm_perm, 'permission', 'can_login', resp_user[:uuid], vm.uuid
387   end
388 =end
389   def find_obj_in_resp (response_items, object_type, head_kind=nil)
390     return_obj = nil
391     response_items.each { |x|
392       if !x
393         next
394       end
395
396       if object_type == 'User'
397         if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
398           return_obj = x
399           break
400         end
401       else  # looking for a link
402         if ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
403           return_obj = x
404           break
405         end
406       end
407     }
408     return return_obj
409   end
410
411   def verify_user (resp_user, email)
412     assert_not_nil resp_user, 'expected user object'
413     assert_not_nil resp_user['uuid'], 'expected user object'
414     assert_equal email, resp_user['email'], 'expected email not found'
415
416   end
417
418   def verify_link (link_object, link_class, link_name, tail_uuid, head_uuid)
419     assert_not_nil link_object, "expected link for #{link_class} #{link_name}"
420     assert_not_nil link_object[:uuid],
421         "expected non-nil uuid for link for #{link_class} #{link_name}"
422     assert_equal link_class, link_object[:link_class],
423         "expected link_class not found for #{link_class} #{link_name}"
424     assert_equal link_name, link_object[:name],
425         "expected link_name not found for #{link_class} #{link_name}"
426     assert_equal tail_uuid, link_object[:tail_uuid],
427         "expected tail_uuid not found for #{link_class} #{link_name}"
428     if head_uuid
429       assert_equal head_uuid, link_object[:head_uuid],
430           "expected head_uuid not found for #{link_class} #{link_name}"
431     end
432   end
433
434   def create_user_and_verify_setup_and_notifications (active, active_recipients, inactive_recipients, email, valid_username)
435     Rails.configuration.new_user_notification_recipients = active_recipients
436     Rails.configuration.new_inactive_user_notification_recipients = inactive_recipients
437
438     assert_equal active_recipients, Rails.configuration.new_user_notification_recipients
439     assert_equal inactive_recipients, Rails.configuration.new_inactive_user_notification_recipients
440
441     ActionMailer::Base.deliveries = []
442
443     user = User.new
444     user.first_name = "first_name_for_newly_created_user"
445     user.email = email
446     user.is_active = active
447     user.save!
448
449     # check user setup
450     group = Group.where(name: 'All users').select do |g|
451       g[:uuid].match /-f+$/
452     end.first
453
454     if !Rails.configuration.auto_setup_new_users || !valid_username
455       # verify that the user is not added to "All groups" by auto_setup
456       verify_link_exists false, group[:uuid], user.uuid, 'permission', 'can_read', nil, nil
457
458       # check oid login link not created by auto_setup
459       verify_link_exists false, user.uuid, user.email, 'permission', 'can_login', nil, nil
460     else
461       # verify that auto_setup took place
462       # verify that the user is added to "All groups"
463       verify_link_exists true, group[:uuid], user.uuid, 'permission', 'can_read', nil, nil
464
465       # check oid login link
466       verify_link_exists true, user.uuid, user.email, 'permission', 'can_login', nil, nil
467
468       username = user.email.partition('@')[0] if email
469       username = (username.gsub!(/[-._]/, '') || username) if username
470
471       # check vm uuid
472       vm_uuid = Rails.configuration.auto_setup_new_users_with_vm_uuid
473       if vm_uuid
474         verify_link_exists true, vm_uuid, user.uuid, 'permission', 'can_login', 'username', username
475       else
476         verify_link_exists false, vm_uuid, user.uuid, 'permission', 'can_login', 'username', username
477       end
478
479       # check repo
480       if Rails.configuration.auto_setup_new_users_with_repository
481         repos = Repository.where('name like ?', "%#{username}%")
482         assert_not_nil repos, 'repository not found'
483         assert_equal true, repos.any?, 'repository not found'
484         repo_uuids = []
485         repos.each do |repo|
486           repo_uuids << repo[:uuid]
487         end
488         verify_link_exists true, repo_uuids, user.uuid, 'permission', 'can_manage', nil, nil
489       end
490     end
491
492     # check email notifications
493     new_user_email = nil
494     new_inactive_user_email = nil
495
496     new_user_email_subject = "#{Rails.configuration.email_subject_prefix}New user created notification"
497     if Rails.configuration.auto_setup_new_users
498       new_user_email_subject = valid_username ? "#{Rails.configuration.email_subject_prefix}New user created and setup notification" : 
499                                                 "#{Rails.configuration.email_subject_prefix}New user created, but not setup notification"
500     end
501
502     ActionMailer::Base.deliveries.each do |d|
503       if d.subject == new_user_email_subject then
504         new_user_email = d
505       elsif d.subject == "#{Rails.configuration.email_subject_prefix}New inactive user notification" then
506         new_inactive_user_email = d
507       end
508     end
509
510     if not active
511       if not inactive_recipients.empty? then
512         assert_not_nil new_inactive_user_email, 'Expected new inactive user email after setup'
513         assert_equal Rails.configuration.user_notifier_email_from, new_inactive_user_email.from[0]
514         assert_equal inactive_recipients, new_inactive_user_email.to[0]
515         assert_equal "#{Rails.configuration.email_subject_prefix}New inactive user notification", new_inactive_user_email.subject
516       else
517         assert_nil new_inactive_user_email, 'Did not expect new inactive user email after setup'
518       end
519     end
520
521     if active
522       assert_nil new_inactive_user_email, 'Expected no inactive user email after setting up active user'
523       if not active_recipients.empty? then
524         assert_not_nil new_user_email, 'Expected new user email after setup'
525         assert_equal Rails.configuration.user_notifier_email_from, new_user_email.from[0]
526         assert_equal active_recipients, new_user_email.to[0]
527         assert_equal new_user_email_subject, new_user_email.subject
528       else
529         assert_nil new_user_email, 'Did not expect new user email after setup'
530       end
531     end
532     ActionMailer::Base.deliveries = []
533
534   end
535
536   def verify_link_exists link_exists, head_uuid, tail_uuid, link_class, link_name, property_name, property_value
537     all_links = Link.where(head_uuid: head_uuid,
538                            tail_uuid: tail_uuid,
539                            link_class: link_class,
540                            name: link_name)
541     assert_equal link_exists, all_links.any?, "Link #{'not' if link_exists} found for #{link_name} #{link_class} #{property_value}"
542     if link_exists && property_name && property_value
543       all_links.each do |link|
544         assert_equal true, all_links.first.properties[property_name].start_with?(property_value), 'Property not found in link'
545       end
546     end
547   end
548
549 end