Gilles Peskine | 01def64 | 2025-04-25 18:30:47 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | """Test the configuration checks generated by generate_config_checks.py. |
| 3 | """ |
| 4 | |
| 5 | ## Copyright The Mbed TLS Contributors |
| 6 | ## SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 7 | |
| 8 | import unittest |
| 9 | |
| 10 | import scripts_path # pylint: disable=unused-import |
| 11 | from mbedtls_framework import unittest_config_checks |
| 12 | |
| 13 | |
| 14 | class MbedtlsTestConfigChecks(unittest_config_checks.TestConfigChecks): |
| 15 | """Mbed TLS unit tests for checks generated by config_checks_generator.""" |
| 16 | |
| 17 | #pylint: disable=invalid-name # uppercase letters make sense here |
| 18 | |
| 19 | PROJECT_CONFIG_C = 'library/mbedtls_config.c' |
| 20 | PROJECT_SPECIFIC_INCLUDE_DIRECTORIES = [ |
| 21 | 'tf-psa-crypto/include', |
| 22 | 'tf-psa-crypto/drivers/builtin/include', |
| 23 | ] |
| 24 | |
| 25 | @unittest.skip("At this time, mbedtls does not go through crypto's check_config.h.") |
| 26 | def test_crypto_no_fs_io(self) -> None: |
| 27 | """A sample error expected from crypto's check_config.h.""" |
| 28 | self.bad_case('#undef MBEDTLS_FS_IO', |
| 29 | None, |
| 30 | error=('MBEDTLS_PSA_ITS_FILE_C')) |
| 31 | |
| 32 | def test_mbedtls_no_session_tickets_for_early_data(self) -> None: |
| 33 | """An error expected from mbedtls_check_config.h based on the TLS configuration.""" |
| 34 | self.bad_case(None, |
| 35 | ''' |
| 36 | #define MBEDTLS_SSL_EARLY_DATA |
| 37 | #undef MBEDTLS_SSL_SESSION_TICKETS |
| 38 | ''', |
| 39 | error=('MBEDTLS_SSL_EARLY_DATA')) |
| 40 | |
| 41 | def test_mbedtls_no_ecdsa(self) -> None: |
| 42 | """An error expected from mbedtls_check_config.h based on crypto+TLS configuration.""" |
| 43 | self.bad_case(''' |
| 44 | #undef PSA_WANT_ALG_ECDSA |
| 45 | #undef PSA_WANT_ALG_DETERMINISTIC_ECDSA |
Gilles Peskine | 01def64 | 2025-04-25 18:30:47 +0200 | [diff] [blame] | 46 | ''', |
| 47 | ''' |
| 48 | #if defined(PSA_WANT_ALG_ECDSA) |
| 49 | #error PSA_WANT_ALG_ECDSA unexpected |
| 50 | #endif |
| 51 | #if defined(PSA_WANT_ALG_DETERMINSTIC_ECDSA) |
| 52 | #error PSA_WANT_ALG_DETERMINSTIC_ECDSA unexpected |
| 53 | #endif |
Gilles Peskine | 01def64 | 2025-04-25 18:30:47 +0200 | [diff] [blame] | 54 | ''', |
| 55 | error=('MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED')) |
| 56 | |
| 57 | |
| 58 | if __name__ == '__main__': |
| 59 | unittest.main() |