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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for the credentials manager."""
from __future__ import unicode_literals
import unittest
from dfvfs.credentials import apfs_credentials
from dfvfs.credentials import credentials
from dfvfs.credentials import manager
from dfvfs.path import apfs_container_path_spec
from dfvfs.path import fake_path_spec
from tests import test_lib as shared_test_lib
class TestCredentials(credentials.Credentials):
"""Credentials for testing."""
CREDENTIALS = frozenset(['password'])
TYPE_INDICATOR = 'test'
class CredentialsManagerTest(shared_test_lib.BaseTestCase):
"""Credentials manager tests."""
def testCredentialsRegistration(self):
"""Tests the DeregisterCredentials and DeregisterCredentials functions."""
# pylint: disable=protected-access
test_credentials = TestCredentials()
number_of_credentials = len(manager.CredentialsManager._credentials)
manager.CredentialsManager.RegisterCredentials(test_credentials)
self.assertEqual(
len(manager.CredentialsManager._credentials), number_of_credentials + 1)
with self.assertRaises(KeyError):
manager.CredentialsManager.RegisterCredentials(test_credentials)
manager.CredentialsManager.DeregisterCredentials(test_credentials)
self.assertEqual(
len(manager.CredentialsManager._credentials), number_of_credentials)
with self.assertRaises(KeyError):
manager.CredentialsManager.DeregisterCredentials(test_credentials)
def testGetCredentials(self):
"""Function to test the GetCredentials function."""
test_path_spec = fake_path_spec.FakePathSpec(location='/fake')
test_path_spec = apfs_container_path_spec.APFSContainerPathSpec(
location='/', parent=fake_path_spec)
credentials_object = manager.CredentialsManager.GetCredentials(
test_path_spec)
self.assertIsInstance(credentials_object, apfs_credentials.APFSCredentials)
test_path_spec = fake_path_spec.FakePathSpec(location='/fake')
credentials_object = manager.CredentialsManager.GetCredentials(
test_path_spec)
self.assertIsNone(credentials_object)
if __name__ == '__main__':
unittest.main()
|