예제 #1
0
 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')
예제 #2
0
 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')
예제 #3
0
 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])
예제 #4
0
 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])
예제 #5
0
 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])
예제 #6
0
 def test_fingerprint(self):
     fingerprint = ssh_fingerprint(self.key1_path + '.pub')
     key = UserKey(
         user=self.user1,
         name='name',
         key=open(self.key1_path + '.pub').read(),
     )
     key.full_clean()
     key.save()
     self.assertEqual(key.fingerprint, fingerprint)
예제 #7
0
 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])
예제 #8
0
 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:'))
예제 #9
0
 def test_fingerprint(self):
   fingerprint = ssh_fingerprint(self.key1_path+'.pub')
   key = UserKey(
     user = self.user1,
     name = 'name',
     key = open(self.key1_path+'.pub').read(),
   )
   key.full_clean()
   key.save()
   self.assertEqual(key.fingerprint, fingerprint)
예제 #10
0
 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)
예제 #11
0
 def test_touch(self):
     import datetime
     key = UserKey(
         user=self.user1,
         name='name',
         key=open(self.key1_path + '.pub').read(),
     )
     key.full_clean()
     key.save()
     self.assertIsNone(key.last_used)
     key.touch()
     key.save()
     self.assertIsInstance(key.last_used, datetime.datetime)
     key.touch()
예제 #12
0
 def test_touch(self):
   import datetime
   key = UserKey(
     user=self.user1,
     name='name',
     key=open(self.key1_path + '.pub').read(),
   )
   key.full_clean()
   key.save()
   self.assertIsNone(key.last_used)
   key.touch()
   key.save()
   self.assertIsInstance(key.last_used, datetime.datetime)
   key.touch()
예제 #13
0
 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])
예제 #14
0
 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(),
     )
     self.assertRaises(ValidationError, key2.full_clean)
예제 #15
0
 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(),
   )
   self.assertRaises(ValidationError, key2.full_clean)
예제 #16
0
 def test_same_name_different_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.user2,
     name='name',
     key=open(self.key2_path + '.pub').read(),
   )
   key2.full_clean()
   key2.save()
예제 #17
0
 def test_same_name_different_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.user2,
         name='name',
         key=open(self.key2_path + '.pub').read(),
     )
     key2.full_clean()
     key2.save()
예제 #18
0
 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])