util.tests.test_encrypted_fieldsΒΆ

Tests for encrypted fields module.

ClassesΒΆ

TestEncryptedTextField

Test cases for EncryptedTextField.

TestEncryptedCharField

Test cases for EncryptedCharField.

TestEncryptionDecryptionIntegration

Integration tests for encryption/decryption functionality.

Module ContentsΒΆ

class util.tests.test_encrypted_fields.TestEncryptedTextField(methodName='runTest')[source]ΒΆ

Bases: django.test.TestCase

Test cases for EncryptedTextField.

setUp()[source]ΒΆ

Set up test fixtures.

test_init()[source]ΒΆ

Test field initialization.

test_raise_validation_error()[source]ΒΆ

Test raise_validation_error method.

test_should_encrypt_softhsm(mock_config)[source]ΒΆ

Test should_encrypt returns True for SoftHSM storage type.

test_should_encrypt_physical_hsm(mock_config)[source]ΒΆ

Test should_encrypt returns True for Physical HSM storage type.

Parameters:

mock_config (unittest.mock.Mock)

test_should_encrypt_software_storage(mock_config)[source]ΒΆ

Test should_encrypt returns False for software storage type.

test_should_encrypt_no_config(mock_config)[source]ΒΆ

Test should_encrypt raises ValidationError when no config found.

test_should_encrypt_database_error(mock_config)[source]ΒΆ

Test should_encrypt handles database errors.

test_get_dek_from_cache(mock_token_model)[source]ΒΆ

Test get_dek returns cached DEK when available.

test_get_dek_from_token(mock_token_model)[source]ΒΆ

Test get_dek retrieves DEK from token when cache is empty.

test_get_dek_no_token(mock_token_model)[source]ΒΆ

Test get_dek raises ValidationError when no token configured.

test_get_dek_token_error(mock_token_model)[source]ΒΆ

Test get_dek handles token retrieval errors.

test_encrypt_value_success(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test successful encryption of a value.

test_encrypt_value_no_encryption(mock_should_encrypt)[source]ΒΆ

Test encrypt_value returns original value when encryption disabled.

test_encrypt_value_empty_string()[source]ΒΆ

Test encrypt_value handles empty strings.

test_encrypt_value_none()[source]ΒΆ

Test encrypt_value handles None values.

test_encrypt_value_dek_error(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test encrypt_value handles DEK retrieval errors.

test_decrypt_value_success(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test successful decryption of a value.

test_decrypt_value_no_encryption(mock_should_encrypt)[source]ΒΆ

Test decrypt_value returns original value when encryption disabled.

test_decrypt_value_empty_string()[source]ΒΆ

Test decrypt_value handles empty strings.

test_decrypt_value_none()[source]ΒΆ

Test decrypt_value handles None values.

test_decrypt_value_invalid_data(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test decrypt_value handles invalid encrypted data.

test_decrypt_value_wrong_dek(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test decrypt_value handles decryption with wrong DEK.

test_from_db_value(mock_decrypt)[source]ΒΆ

Test from_db_value method.

test_from_db_value_none()[source]ΒΆ

Test from_db_value with None value.

test_to_python_string()[source]ΒΆ

Test to_python with string value.

test_to_python_none()[source]ΒΆ

Test to_python with None value.

test_to_python_non_string()[source]ΒΆ

Test to_python with non-string value.

test_get_prep_value(mock_encrypt)[source]ΒΆ

Test get_prep_value method.

test_get_prep_value_none()[source]ΒΆ

Test get_prep_value with None value.

test_get_prep_value_non_string(mock_encrypt)[source]ΒΆ

Test get_prep_value with non-string value.

class util.tests.test_encrypted_fields.TestEncryptedCharField(methodName='runTest')[source]ΒΆ

Bases: django.test.TestCase

Test cases for EncryptedCharField.

setUp()[source]ΒΆ

Set up test fixtures.

test_init_with_max_length()[source]ΒΆ

Test field initialization with max_length parameter.

test_init_without_max_length()[source]ΒΆ

Test field initialization without max_length parameter.

test_max_length_calculation()[source]ΒΆ

Test that max_length is correctly calculated for encryption overhead.

test_raise_validation_error()[source]ΒΆ

Test raise_validation_error method.

test_should_encrypt_inherits_from_textfield(mock_config)[source]ΒΆ

Test that EncryptedCharField should_encrypt works like EncryptedTextField.

test_encrypt_decrypt_roundtrip(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test complete encrypt/decrypt roundtrip for EncryptedCharField.

test_from_db_value_charfield(mock_decrypt)[source]ΒΆ

Test from_db_value method for EncryptedCharField.

test_to_python_charfield()[source]ΒΆ

Test to_python method for EncryptedCharField.

test_get_prep_value_charfield(mock_encrypt)[source]ΒΆ

Test get_prep_value method for EncryptedCharField.

class util.tests.test_encrypted_fields.TestEncryptionDecryptionIntegration(methodName='runTest')[source]ΒΆ

Bases: django.test.TestCase

Integration tests for encryption/decryption functionality.

setUp()[source]ΒΆ

Set up test fixtures.

test_encrypt_decrypt_various_texts(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test encryption/decryption with various text inputs.

test_encryption_produces_different_outputs(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test that encryption produces different outputs for same input (due to random nonce).

test_encrypted_data_format(mock_get_dek, mock_should_encrypt)[source]ΒΆ

Test that encrypted data has correct format (nonce + tag + ciphertext).