Esempio n. 1
0
    def testWriteRead(self):
        a = Account("the_key")
        a.setNote("the note")
        a.setUsername("the username")
        a.setPassword("the password")

        path = os.path.join(tempfile.tempdir, "write_test")

        persistance.write(path, [a])
        self.assertTrue(os.path.isfile(path))

        accounts = persistance.read(path)
        self.assertEqual(len(accounts), 1)

        os.unlink(path)
Esempio n. 2
0
    def testWritefp(self):
        a = Account("the_key")
        a.setNote("the note")
        a.setUsername("the username")
        a.setEncryptedPassword("the password")

        f = tempfile.TemporaryFile()
        persistance.writefp(f, [a])
        f.seek(0)

        config = SafeConfigParser()
        config.readfp(f)

        self.assertEqual(config.sections(), ["the_key"])
        self.assertEqual(config.get("the_key", "note"), "the note")
        self.assertEqual(config.get("the_key", "username"), "the username")
        self.assertEqual(config.get("the_key", "password"), "the password")

        f.close
Esempio n. 3
0
 def testConstructor(self):
     a = Account('key')
     self.assertEqual(a.key(), 'key')
Esempio n. 4
0
    def testEncryption(self):
        a1 = Account('key', 'crypto')
        a1.setPassword('pass')

        # Check that the password is encrypted (or at least obscured)
        encrypted = a1.encryptedPassword()
        self.assertNotEqual(encrypted, None)
        self.assertNotEqual(encrypted, 'pass')

        # Make sure the password can be decrypted
        a2 = Account('key', 'crypto')
        a2.setEncryptedPassword(encrypted)
        self.assertEqual(a2.password(), 'pass')

        # Make sure the password can't be decrypted with the wrong key
        a3 = Account('key', 'wrong key')
        a3.setEncryptedPassword(encrypted)
        self.assertNotEqual(a3.password(), 'pass')
Esempio n. 5
0
    def testPassword(self):
        a = Account('key')
        self.assertEqual(a.password(), None)

        a.setPassword('a pass')
        self.assertEqual(a.password(), 'a pass')
Esempio n. 6
0
    def testUsername(self):
        a = Account('key')
        self.assertEqual(a.username(), None)

        a.setUsername('a user')
        self.assertEqual(a.username(), 'a user')
Esempio n. 7
0
    def testNote(self):
        a = Account('key')
        self.assertEqual(a.note(), None)

        a.setNote('a note')
        self.assertEqual(a.note(), 'a note')