def test_without_name_without_comment(self): key = UserKey( user=self.user1, key=open(self.key2_path + '.pub').read(), ) key.full_clean() key.save()
def test_without_name_with_comment(self): key = UserKey( user=self.user1, key=open(self.key1_path + '.pub').read(), ) key.full_clean() key.save() self.assertEqual(key.name, 'comment')
def test_ed25519(self): key = UserKey( user=self.user1, name='name', key=open(self.key4_path + '.pub').read(), ) key.full_clean() key.save() self.assertEqual(key.keytype, 'ssh-ed25519')
def test_ecdsa(self): key = UserKey( user=self.user1, name='name', key=open(self.key3_path + '.pub').read(), ) key.full_clean() key.save() self.assertEqual(key.keytype, 'ecdsa-sha2-nistp256')
def test_empty_key(self): key = UserKey( user=self.user1, name='', key='', ) key.full_clean(exclude=['key']) key.save() self.assertEqual(key.key, '')
def test_import(self): key = UserKey( user=self.user1, name='name', key=open(self.key1_pem_path).read(), ) key.full_clean() key.save() self.assertEqual(key.key.split()[:2], open(self.key1_path + '.pub').read().split()[:2])
def test_import_without_comment(self): key = UserKey( user=self.user1, name='name', key=open(self.key2_rfc4716_path).read(), ) key.full_clean() key.save() self.assertEqual(key.key.split()[:2], open(self.key2_path + '.pub').read().split()[:2])
def test_fingerprint_md5(self): settings.SSHKEY_DEFAULT_HASH = 'md5' key = UserKey( user=self.user1, name='name', key=open(self.key1_path + '.pub').read(), ) key.full_clean() key.save() self.assertTrue(key.fingerprint.startswith('MD5:'))
def test_fingerprint_legacy(self): settings.SSHKEY_DEFAULT_HASH = 'legacy' fingerprint = ssh_fingerprint(self.key1_path + '.pub', hash='legacy') key = UserKey( user=self.user1, name='name', key=open(self.key1_path + '.pub').read(), ) key.full_clean() key.save() self.assertEqual(key.fingerprint, fingerprint)
def test_export(self): key = UserKey( user=self.user1, name='name', key=open(self.key1_path + '.pub').read(), ) key.full_clean() key.save() export_path = os.path.join(self.key_dir, 'export') import_path = os.path.join(self.key_dir, 'import') with open(export_path, 'w') as f: f.write(key.export('PEM')) ssh_key_import(export_path, import_path, 'PEM') self.assertEqual(open(import_path).read().split()[:2], open(self.key1_path + '.pub').read().split()[:2])
def test_same_key_different_user(self): key1 = UserKey( user=self.user1, name='name1', key=open(self.key1_path + '.pub').read(), ) key1.full_clean() key1.save() key2 = UserKey( user=self.user2, name='name2', key=open(self.key1_path + '.pub').read(), ) key2.full_clean() key2.save()
def test_same_name_same_user(self): key1 = UserKey( user=self.user1, name='name', key=open(self.key1_path + '.pub').read(), ) key1.full_clean() key1.save() key2 = UserKey( user=self.user1, name='name', key=open(self.key2_path + '.pub').read(), ) key2.full_clean() key2.save()