8567: Adjust job container resolve test now that images are filtered based on
[arvados.git] / services / api / test / unit / authorized_key_test.rb
1 require 'test_helper'
2
3 class AuthorizedKeyTest < ActiveSupport::TestCase
4   TEST_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCf5aTI55uyWr44TckP/ELUAyPsdnf5fTZDcSDN4qiMZYAL7TYV2ixwnbPObLObM0GmHSSFLV1KqsuFICUPgkyKoHbAH6XPgmtfOLU60VkGf1v5uxQ/kXCECRCJmPb3K9dIXGEw+1DXPdOV/xG7rJNvo4a9WK9iqqZr8p+VGKM6C017b8BDLk0tuEEjZ5jXcT/ka/hTScxWkKgF6auPOVQ79OA5+0VaYm4uQLzVUdgwVUPWQQecRrtnc08XYM1htpcLDIAbWfUNK7uE6XR3/OhtrJGf05FGbtGguPgi33F9W3Q3yw6saOK5Y3TfLbskgFaEdLgzqK/QSBRk2zBF49Tj test@localhost"
5
6   test 'create and update key' do
7     u1 = users(:active)
8     act_as_user u1 do
9       ak = AuthorizedKey.new(name: "foo", public_key: TEST_KEY, authorized_user_uuid: u1.uuid)
10       assert ak.save, ak.errors.full_messages.to_s
11       ak.name = "bar"
12       assert ak.valid?, ak.errors.full_messages.to_s
13       assert ak.save, ak.errors.full_messages.to_s
14     end
15   end
16
17   test 'duplicate key not permitted' do
18     u1 = users(:active)
19     act_as_user u1 do
20       ak = AuthorizedKey.new(name: "foo", public_key: TEST_KEY, authorized_user_uuid: u1.uuid)
21       assert ak.save
22     end
23     u2 = users(:spectator)
24     act_as_user u2 do
25       ak2 = AuthorizedKey.new(name: "bar", public_key: TEST_KEY, authorized_user_uuid: u2.uuid)
26       refute ak2.valid?
27       refute ak2.save
28       assert_match(/already exists/, ak2.errors.full_messages.to_s)
29     end
30   end
31
32   test 'attach key to wrong user account' do
33     act_as_user users(:active) do
34       ak = AuthorizedKey.new(name: "foo", public_key: TEST_KEY)
35       ak.authorized_user_uuid = users(:spectator).uuid
36       refute ak.save
37       ak.uuid = nil
38       ak.authorized_user_uuid = users(:admin).uuid
39       refute ak.save
40       ak.uuid = nil
41       ak.authorized_user_uuid = users(:active).uuid
42       assert ak.save, ak.errors.full_messages.to_s
43       ak.authorized_user_uuid = users(:admin).uuid
44       refute ak.save
45     end
46   end
47 end