management.tests.test_pkcs11_private_keyΒΆ
Tests for PKCS#11 Pkcs11PrivateKey class.
ClassesΒΆ
Mock implementation of Pkcs11PrivateKey for testing. |
|
Test cases for the Pkcs11PrivateKey abstract base class. |
Module ContentsΒΆ
- class management.tests.test_pkcs11_private_key.MockPkcs11PrivateKey(lib_path, token_label, user_pin, key_label, slot_id=None)[source]ΒΆ
Bases:
management.pkcs11_util.Pkcs11PrivateKeyMock implementation of Pkcs11PrivateKey for testing.
- Parameters:
lib_path (str)
token_label (str)
user_pin (str)
key_label (str)
slot_id (int | None)
- sign(data, *args, **kwargs)[source]ΒΆ
Mock sign method.
- Parameters:
data (bytes)
args (Any)
kwargs (Any)
- Return type:
bytes
- class management.tests.test_pkcs11_private_key.TestPkcs11PrivateKey[source]ΒΆ
Test cases for the Pkcs11PrivateKey abstract base class.
- mock_token(mock_session)[source]ΒΆ
Mock PKCS#11 token.
- Parameters:
mock_session (unittest.mock.Mock)
- Return type:
unittest.mock.Mock
- mock_lib(mock_token)[source]ΒΆ
Mock PKCS#11 library.
- Parameters:
mock_token (unittest.mock.Mock)
- Return type:
unittest.mock.Mock
- pkcs11_key(mock_session)[source]ΒΆ
Create MockPkcs11PrivateKey instance with mocked dependencies.
- Parameters:
mock_session (unittest.mock.Mock)
- Return type:
- test_digest_mechanisms_mapping()[source]ΒΆ
Test that DIGEST_MECHANISMS contains expected mappings.
- Return type:
None
- test_digest_data_success(pkcs11_key, mock_session)[source]ΒΆ
Test digest_data method with successful operation.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_digest_data_unsupported_algorithm(pkcs11_key)[source]ΒΆ
Test digest_data with unsupported algorithm.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None
- test_copy_key_success(pkcs11_key, mock_session)[source]ΒΆ
Test copy_key method with successful operation.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_copy_key_with_template(pkcs11_key, mock_session)[source]ΒΆ
Test copy_key with additional template.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_destroy_object_success(pkcs11_key, mock_session)[source]ΒΆ
Test destroy_object method with successful operation.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_destroy_object_not_found(pkcs11_key, mock_session)[source]ΒΆ
Test destroy_object when object not found.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_key_exists_true(pkcs11_key, mock_session)[source]ΒΆ
Test _key_exists when key exists.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_key_exists_false(pkcs11_key, mock_session)[source]ΒΆ
Test _key_exists when key does not exist.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_destroy_key_success(pkcs11_key)[source]ΒΆ
Test destroy_key method with successful operation.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None
- test_destroy_key_no_key(pkcs11_key)[source]ΒΆ
Test destroy_key when no key exists.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None
- test_destroy_key_pkcs11_error(pkcs11_key)[source]ΒΆ
Test destroy_key when PKCS11Error occurs.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None
- test_close_with_session(pkcs11_key, mock_session)[source]ΒΆ
Test close method when session exists.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
mock_session (unittest.mock.Mock)
- Return type:
None
- test_context_manager(pkcs11_key)[source]ΒΆ
Test context manager functionality.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None
- test_mock_implementation_methods(pkcs11_key)[source]ΒΆ
Test that the mock implementation works correctly.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None
- test_initialization_success()[source]ΒΆ
Test successful initialization of Pkcs11PrivateKey.
- Return type:
None
- test_initialization_user_already_logged_in()[source]ΒΆ
Test initialization when user is already logged in.
- Return type:
None
- test_raise_methods(pkcs11_key)[source]ΒΆ
Test the private _raise methods work correctly.
- Parameters:
pkcs11_key (MockPkcs11PrivateKey)
- Return type:
None