summaryrefslogtreecommitdiff
path: root/src/tests/test_configverify.py
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-07-03 16:01:19 +0300
committerYuriy Andamasov <yuriy@vyos.io>2026-07-03 16:01:19 +0300
commite736bccd74630a8119638e6a2a30040851d91803 (patch)
treec2830d30ddc9d7699260ff6ce490e541b93890ac /src/tests/test_configverify.py
parent7ec5405e5024f3f360d0d87fd753f15276fd5e54 (diff)
downloadvyos-1x-fix/T8859-dh-keysize-validation.tar.gz
vyos-1x-fix/T8859-dh-keysize-validation.zip
python: T8859: raise TypeError/ValueError on invalid min_keysizefix/T8859-dh-keysize-validation
Per dmbaturin's review on https://github.com/vyos/vyos-1x/pull/5194: the only callers of verify_diffie_hellman_length() are its own unit tests, so the contract can change freely. An invalid min_keysize indicates a logic error in the calling script and should fail loudly instead of silently returning False: - signature is now verify_diffie_hellman_length(file: str, min_keysize: int) - non-integer min_keysize raises TypeError (bool explicitly rejected) - non-positive min_keysize raises ValueError - regex pattern converted to a raw string (invalid escape sequence) - openssl invoked with list arguments instead of an interpolated command string, so the file path never hits a shell (CodeRabbit) Tests updated to pass integer keysizes and extended to cover both exception paths. 🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src/tests/test_configverify.py')
-rw-r--r--src/tests/test_configverify.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/tests/test_configverify.py b/src/tests/test_configverify.py
index 8f80365d7..a3a94fa50 100644
--- a/src/tests/test_configverify.py
+++ b/src/tests/test_configverify.py
@@ -18,14 +18,26 @@ from vyos.utils.process import cmd
dh_file = '/tmp/dh.pem'
-class TestDictSearch(TestCase):
+class TestVerifyDiffieHellmanLength(TestCase):
def setUp(self):
pass
def test_dh_key_none(self):
- self.assertFalse(verify_diffie_hellman_length('/tmp/non_existing_file', '1024'))
+ self.assertFalse(verify_diffie_hellman_length('/tmp/non_existing_file', 1024))
def test_dh_key_512(self):
- key_len = '512'
+ key_len = 512
cmd(f'openssl dhparam -out {dh_file} {key_len}')
self.assertTrue(verify_diffie_hellman_length(dh_file, key_len))
+
+ def test_dh_keysize_not_integer(self):
+ with self.assertRaises(TypeError):
+ verify_diffie_hellman_length(dh_file, '1024')
+ with self.assertRaises(TypeError):
+ verify_diffie_hellman_length(dh_file, True)
+
+ def test_dh_keysize_not_positive(self):
+ with self.assertRaises(ValueError):
+ verify_diffie_hellman_length(dh_file, -512)
+ with self.assertRaises(ValueError):
+ verify_diffie_hellman_length(dh_file, 0)