1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the key chain."""
from __future__ import unicode_literals
import unittest
from dfvfs.credentials import keychain
from dfvfs.lib import definitions
from dfvfs.path import factory
from tests import test_lib as shared_test_lib
class KeychainTest(shared_test_lib.BaseTestCase):
"""Tests the key chain."""
# TODO: add tests for Empty
# TODO: add tests for ExtractCredentialsFromPathSpec
def testCredentialGetSet(self):
"""Tests the GetCredential and SetCredential functions."""
test_keychain = keychain.KeyChain()
fake_path_spec = factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_FAKE, location='/test')
bde_path_spec = factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_BDE, parent=fake_path_spec)
with self.assertRaises(AttributeError):
test_keychain.SetCredential(fake_path_spec, 'password', 'TEST')
test_keychain.SetCredential(bde_path_spec, 'password', 'TEST')
credential = test_keychain.GetCredential(fake_path_spec, 'password')
self.assertIsNone(credential)
credential = test_keychain.GetCredential(bde_path_spec, 'password')
self.assertEqual(credential, 'TEST')
credentials = test_keychain.GetCredentials(bde_path_spec)
self.assertEqual(credentials, {'password': 'TEST'})
if __name__ == '__main__':
unittest.main()
|