Exemple #1
0
 def test_copy(self):
     user1 = factory.make_user()
     key1 = factory.make_sshkey(user1)
     user2 = factory.make_user()
     copy_ssh_keys(user1, user2)
     user2s_ssh_keys = SSHKey.objects.filter(user=user2)
     self.assertSetEqual(
         {key1.key}, {ssh_key.key for ssh_key in user2s_ssh_keys})
Exemple #2
0
 def test_copy_is_idempotent(self):
     # When the destination user already has a key, copy_ssh_keys() is a
     # noop for that key.
     user1 = factory.make_user()
     key1 = factory.make_sshkey(user1)
     user2 = factory.make_user()
     key2 = factory.make_sshkey(user2, key1.key)
     copy_ssh_keys(user1, user2)
     user2s_ssh_keys = SSHKey.objects.filter(user=user2)
     self.assertSetEqual(
         {key2.key}, {ssh_key.key for ssh_key in user2s_ssh_keys})
Exemple #3
0
 def test_copy_does_not_clobber(self):
     # When the destination user already has some keys, copy_ssh_keys()
     # adds to them; it does not remove them.
     user1 = factory.make_user()
     key1 = factory.make_sshkey(user1, get_ssh_key_string(1))
     user2 = factory.make_user()
     key2 = factory.make_sshkey(user2, get_ssh_key_string(2))
     copy_ssh_keys(user1, user2)
     user2s_ssh_keys = SSHKey.objects.filter(user=user2)
     self.assertSetEqual(
         {key1.key, key2.key},
         {ssh_key.key for ssh_key in user2s_ssh_keys})
Exemple #4
0
 def test_noop_when_there_are_no_keys(self):
     user1 = factory.make_user()
     user2 = factory.make_user()
     copy_ssh_keys(user1, user2)
     ssh_keys = SSHKey.objects.filter(user__in={user1, user2})
     self.assertEqual([], list(ssh_keys))