Skip to content

Commit bc40e76

Browse files
authored
Merge pull request lightspeed-core#1748 from tisnik/lcore-2260-tls-config
LCORE-2260: Fixed TLS config unit tests, added new tests, enhanced negative test cases
2 parents 2c1c408 + 901747f commit bc40e76

1 file changed

Lines changed: 113 additions & 4 deletions

File tree

tests/unit/models/config/test_tls_configuration.py

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,17 @@ def test_tls_configuration_wrong_key_path() -> None:
5959
"""Test the TLS configuration loading when some path is broken."""
6060
with pytest.raises(ValueError, match="Path does not point to a file"):
6161
TLSConfiguration(
62-
tls_certificate_path=Path("tests/configurationserver.crt"),
62+
tls_certificate_path=Path("tests/configuration/server.crt"),
63+
tls_key_path=Path("this-is-wrong"),
64+
tls_key_password=Path("tests/configuration/password"),
65+
)
66+
67+
68+
def test_tls_configuration_wrong_certificate_and_key_paths() -> None:
69+
"""Test the TLS configuration loading when some paths are broken."""
70+
with pytest.raises(ValueError, match="Path does not point to a file"):
71+
TLSConfiguration(
72+
tls_certificate_path=Path("this-is-wrong"),
6373
tls_key_path=Path("this-is-wrong"),
6474
tls_key_password=Path("tests/configuration/password"),
6575
)
@@ -77,12 +87,42 @@ def test_tls_configuration_wrong_password_path() -> None:
7787
"""
7888
with pytest.raises(ValueError, match="Path does not point to a file"):
7989
TLSConfiguration(
80-
tls_certificate_path=Path("tests/configurationserver.crt"),
90+
tls_certificate_path=Path("tests/configuration/server.crt"),
8191
tls_key_path=Path("tests/configuration/server.key"),
8292
tls_key_password=Path("this-is-wrong"),
8393
)
8494

8595

96+
def test_tls_configuration_wrong_password_and_certificate_paths() -> None:
97+
"""Test the TLS configuration loading when some path are broken."""
98+
with pytest.raises(ValueError, match="Path does not point to a file"):
99+
TLSConfiguration(
100+
tls_certificate_path=Path("this-is-wrong"),
101+
tls_key_path=Path("tests/configuration/server.key"),
102+
tls_key_password=Path("this-is-wrong"),
103+
)
104+
105+
106+
def test_tls_configuration_wrong_password_and_key_paths() -> None:
107+
"""Test the TLS configuration loading when some path are broken."""
108+
with pytest.raises(ValueError, match="Path does not point to a file"):
109+
TLSConfiguration(
110+
tls_certificate_path=Path("tests/configuration/server.crt"),
111+
tls_key_path=Path("this-is-wrong"),
112+
tls_key_password=Path("this-is-wrong"),
113+
)
114+
115+
116+
def test_tls_configuration_wrong_all_paths() -> None:
117+
"""Test the TLS configuration loading when some paths are broken."""
118+
with pytest.raises(ValueError, match="Path does not point to a file"):
119+
TLSConfiguration(
120+
tls_certificate_path=Path("this-is-wrong"),
121+
tls_key_path=Path("this-is-wrong"),
122+
tls_key_password=Path("this-is-wrong"),
123+
)
124+
125+
86126
def test_tls_configuration_certificate_path_to_directory() -> None:
87127
"""Test the TLS configuration loading when some path points to a directory.
88128
@@ -104,7 +144,7 @@ def test_tls_configuration_key_path_to_directory() -> None:
104144
"""Test the TLS configuration loading when some path points to a directory."""
105145
with pytest.raises(ValueError, match="Path does not point to a file"):
106146
TLSConfiguration(
107-
tls_certificate_path=Path("tests/configurationserver.crt"),
147+
tls_certificate_path=Path("tests/configuration/server.crt"),
108148
tls_key_path=Path("tests/"),
109149
tls_key_password=Path("tests/configuration/password"),
110150
)
@@ -114,7 +154,76 @@ def test_tls_configuration_password_path_to_directory() -> None:
114154
"""Test the TLS configuration loading when some path points to a directory."""
115155
with pytest.raises(ValueError, match="Path does not point to a file"):
116156
TLSConfiguration(
117-
tls_certificate_path=Path("tests/configurationserver.crt"),
157+
tls_certificate_path=Path("tests/configuration/server.crt"),
118158
tls_key_path=Path("tests/configuration/server.key"),
119159
tls_key_password=Path("tests/"),
120160
)
161+
162+
163+
def test_tls_configuration_certificate_path_is_empty() -> None:
164+
"""Test the TLS configuration loading when some path is empty."""
165+
with pytest.raises(ValueError, match="Path does not point to a file"):
166+
TLSConfiguration(
167+
tls_certificate_path=Path(""),
168+
tls_key_path=Path("tests/configuration/server.key"),
169+
tls_key_password=Path("tests/configuration/password"),
170+
)
171+
172+
173+
def test_tls_configuration_key_path_is_empty() -> None:
174+
"""Test the TLS configuration loading when some path is empty."""
175+
with pytest.raises(ValueError, match="Path does not point to a file"):
176+
TLSConfiguration(
177+
tls_certificate_path=Path("tests/configuration/server.crt"),
178+
tls_key_path=Path(""),
179+
tls_key_password=Path("tests/configuration/password"),
180+
)
181+
182+
183+
def test_tls_configuration_password_path_is_empty() -> None:
184+
"""Test the TLS configuration loading when some path is empty."""
185+
with pytest.raises(ValueError, match="Path does not point to a file"):
186+
TLSConfiguration(
187+
tls_certificate_path=Path("tests/configuration/server.crt"),
188+
tls_key_path=Path("tests/configuration/server.key"),
189+
tls_key_password=Path(""),
190+
)
191+
192+
193+
def test_tls_configuration_certificate_path_is_none() -> None:
194+
"""Test the TLS configuration loading when some path is None."""
195+
cfg = TLSConfiguration(
196+
tls_certificate_path=None,
197+
tls_key_path=Path("tests/configuration/server.key"),
198+
tls_key_password=Path("tests/configuration/password"),
199+
)
200+
assert cfg is not None
201+
assert cfg.tls_certificate_path is None
202+
assert cfg.tls_key_path == Path("tests/configuration/server.key")
203+
assert cfg.tls_key_password == Path("tests/configuration/password")
204+
205+
206+
def test_tls_configuration_key_path_is_none() -> None:
207+
"""Test the TLS configuration loading when some path is None."""
208+
cfg = TLSConfiguration(
209+
tls_certificate_path=Path("tests/configuration/server.crt"),
210+
tls_key_path=None,
211+
tls_key_password=Path("tests/configuration/password"),
212+
)
213+
assert cfg is not None
214+
assert cfg.tls_key_path is None
215+
assert cfg.tls_certificate_path == Path("tests/configuration/server.crt")
216+
assert cfg.tls_key_password == Path("tests/configuration/password")
217+
218+
219+
def test_tls_configuration_password_path_is_none() -> None:
220+
"""Test the TLS configuration loading when some path is None."""
221+
cfg = TLSConfiguration(
222+
tls_certificate_path=Path("tests/configuration/server.crt"),
223+
tls_key_path=Path("tests/configuration/server.key"),
224+
tls_key_password=None,
225+
)
226+
assert cfg is not None
227+
assert cfg.tls_key_password is None
228+
assert cfg.tls_certificate_path == Path("tests/configuration/server.crt")
229+
assert cfg.tls_key_path == Path("tests/configuration/server.key")

0 commit comments

Comments
 (0)