|
| 1 | +"""Unit tests for TLSConfiguration model.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from models.config import ServiceConfiguration, TLSConfiguration |
| 8 | + |
| 9 | + |
| 10 | +def test_tls_configuration() -> None: |
| 11 | + """Test the TLS configuration.""" |
| 12 | + cfg = TLSConfiguration( |
| 13 | + tls_certificate_path=Path("tests/configuration/server.crt"), |
| 14 | + tls_key_path=Path("tests/configuration/server.key"), |
| 15 | + tls_key_password=Path("tests/configuration/password"), |
| 16 | + ) |
| 17 | + assert cfg is not None |
| 18 | + assert cfg.tls_certificate_path == Path("tests/configuration/server.crt") |
| 19 | + assert cfg.tls_key_path == Path("tests/configuration/server.key") |
| 20 | + assert cfg.tls_key_password == Path("tests/configuration/password") |
| 21 | + |
| 22 | + |
| 23 | +def test_tls_configuration_in_service_configuration() -> None: |
| 24 | + """Test the TLS configuration in service configuration.""" |
| 25 | + cfg = ServiceConfiguration( |
| 26 | + tls_config=TLSConfiguration( |
| 27 | + tls_certificate_path=Path("tests/configuration/server.crt"), |
| 28 | + tls_key_path=Path("tests/configuration/server.key"), |
| 29 | + tls_key_password=Path("tests/configuration/password"), |
| 30 | + ) |
| 31 | + ) |
| 32 | + assert cfg is not None |
| 33 | + assert cfg.tls_config is not None |
| 34 | + assert cfg.tls_config.tls_certificate_path == Path("tests/configuration/server.crt") |
| 35 | + assert cfg.tls_config.tls_key_path == Path("tests/configuration/server.key") |
| 36 | + assert cfg.tls_config.tls_key_password == Path("tests/configuration/password") |
| 37 | + |
| 38 | + |
| 39 | +def test_tls_configuration_wrong_certificate_path() -> None: |
| 40 | + """Test the TLS configuration loading when some path is broken.""" |
| 41 | + with pytest.raises(ValueError, match="Path does not point to a file"): |
| 42 | + TLSConfiguration( |
| 43 | + tls_certificate_path=Path("this-is-wrong"), |
| 44 | + tls_key_path=Path("tests/configuration/server.key"), |
| 45 | + tls_key_password=Path("tests/configuration/password"), |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +def test_tls_configuration_wrong_key_path() -> None: |
| 50 | + """Test the TLS configuration loading when some path is broken.""" |
| 51 | + with pytest.raises(ValueError, match="Path does not point to a file"): |
| 52 | + TLSConfiguration( |
| 53 | + tls_certificate_path=Path("tests/configurationserver.crt"), |
| 54 | + tls_key_path=Path("this-is-wrong"), |
| 55 | + tls_key_password=Path("tests/configuration/password"), |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +def test_tls_configuration_wrong_password_path() -> None: |
| 60 | + """Test the TLS configuration loading when some path is broken.""" |
| 61 | + with pytest.raises(ValueError, match="Path does not point to a file"): |
| 62 | + TLSConfiguration( |
| 63 | + tls_certificate_path=Path("tests/configurationserver.crt"), |
| 64 | + tls_key_path=Path("tests/configuration/server.key"), |
| 65 | + tls_key_password=Path("this-is-wrong"), |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def test_tls_configuration_certificate_path_to_directory() -> None: |
| 70 | + """Test the TLS configuration loading when some path points to a directory.""" |
| 71 | + with pytest.raises(ValueError, match="Path does not point to a file"): |
| 72 | + TLSConfiguration( |
| 73 | + tls_certificate_path=Path("tests/"), |
| 74 | + tls_key_path=Path("tests/configuration/server.key"), |
| 75 | + tls_key_password=Path("tests/configuration/password"), |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +def test_tls_configuration_key_path_to_directory() -> None: |
| 80 | + """Test the TLS configuration loading when some path points to a directory.""" |
| 81 | + with pytest.raises(ValueError, match="Path does not point to a file"): |
| 82 | + TLSConfiguration( |
| 83 | + tls_certificate_path=Path("tests/configurationserver.crt"), |
| 84 | + tls_key_path=Path("tests/"), |
| 85 | + tls_key_password=Path("tests/configuration/password"), |
| 86 | + ) |
| 87 | + |
| 88 | + |
| 89 | +def test_tls_configuration_password_path_to_directory() -> None: |
| 90 | + """Test the TLS configuration loading when some path points to a directory.""" |
| 91 | + with pytest.raises(ValueError, match="Path does not point to a file"): |
| 92 | + TLSConfiguration( |
| 93 | + tls_certificate_path=Path("tests/configurationserver.crt"), |
| 94 | + tls_key_path=Path("tests/configuration/server.key"), |
| 95 | + tls_key_password=Path("tests/"), |
| 96 | + ) |
0 commit comments