def test_users_have_only_unique_keys(self): db = AuthorizedKeysDB(self.dir) db.add_key_from_str("tester", "tester ssh-rsa duplicatekey comment foobar") db.add_key_from_str("tester", "tester ssh-rsa duplicatekey different comment") db.commit() db.close() db = AuthorizedKeysDB(self.dir) tester = db.subusers["tester"] self.assertEqual(len(tester.pubkeys), 1)
def test_get_key_owner(self): db = AuthorizedKeysDB(self.dir) db.add_key_from_str("tester", "tester ssh-rsa justakey comment foobar") db.commit() db.close() db = AuthorizedKeysDB(self.dir) user = db.get_key_owner("justakey") self.assertEqual(user.username, "tester")
def test_different_users_cant_have_same_keys(self): """ This is stupid thing to do on clients part... """ duplicate_key = "tester ssh-rsa duplicatekey comment foobar" db = AuthorizedKeysDB(self.dir) db.add_key_from_str("user1", duplicate_key) db.commit() db.close() db = AuthorizedKeysDB(self.dir) self.assertRaises(AuthorizedKeysException, db.add_key_from_str, "user2", duplicate_key) db.close()
def test_preserve_manually_created_keys(self): db = AuthorizedKeysDB(self.dir) manual_keys_before_adding = len(db.custom_key_lines) db.add_key_from_str("tester", "tester ssh-rsa dummykey comment foobar") db.commit() db.close() db = AuthorizedKeysDB(self.dir) self.assertEquals(len(db.custom_key_lines), manual_keys_before_adding)
def test_add_key(self): db = AuthorizedKeysDB(self.dir) self.assertRaises(KeyError, lambda: db.subusers["tester"]) key_str = "tester ssh-rsa dummykey comment foobar" db.add_key_from_str("tester", key_str) db.commit() db.close() db = AuthorizedKeysDB(self.dir) db.subusers["tester"] self.assert_(db.subusers["tester"].has_key_str(key_str))