Exemple #1
0
def empty_db_file(rsa_pair):
    db = PasswordDatabase()
    db.recipients.append(Recipient(rsa_pair.public, ''))
    f = BytesIO()
    db.encrypt(f)
    f.seek(0)

    return namedtuple('EmptyDBFile', 'f rsa_pair')._make((f, rsa_pair))
Exemple #2
0
    def test_set(self):
        """Tests setting passwords using bracket notation and .set() method"""

        database = PasswordDatabase()

        database['my_password'] = '******'
        assert database._password_store['my_password'] == 'secret'

        database.set('more_password', 'more_secret')
        assert database._password_store['more_password'] == 'more_secret'
Exemple #3
0
    def test_symmerty(self, rsa_pair):
        """Ensures that encrypt/decrypt is symmentrical"""

        database = PasswordDatabase()
        database['my_password'] = '******'
        database.recipients.append(Recipient(rsa_pair.public, 'Test'))

        f = BytesIO()
        database.encrypt(f)

        f.seek(0)
        database2 = PasswordDatabase(f, rsa_pair.private)
        assert database._password_store == database2._password_store
        assert len(database2.recipients) == 1 and database2.recipients[0].comment == 'Test'
Exemple #4
0
    def test_get(self):
        """Tests getting passwords using bracket notation and .get() method"""

        database = PasswordDatabase()
        database['my_password'] = '******'

        assert database['my_password'] == 'secret'

        with pytest.raises(KeyError):
            database['foo']

        assert database.get('my_password') == 'secret'
        assert database.get('not_there') is None
        assert database.get('not_there', 'secret') == 'secret'