Skip to content

Commit cf25e2a

Browse files
committed
Add script for CBMA unittests and fix tests
Jira-Id: SECO-7805 Signed-off-by: Mika Joenpera <[email protected]>
1 parent 72c6e22 commit cf25e2a

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

modules/sc-mesh-secure-deployment/src/nats/cbma/unittests/test_certificate_handler.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def test_openssl_certificate() -> None:
2323
end_data: datetime = certificate.get_end_date()
2424
assert end_data
2525

26-
assert '64:73:81:83:B3:F1:72:AD:28:6D:BE:9B:0F:A1:D9:D4:7F:75:72:C2' == str(skid)
27-
assert '04:14:64:73:81:83:b3:f1:72:ad:28:6d:be:9b:0f:a1:d9:d4:7f:75:72:c2' == skid.hex(':')
28-
assert '2024-05-13 09:16:24' == str(end_data)
29-
assert ('keyid:64:73:81:83:B3:F1:72:AD:28:6D:BE:9B:0F:A1:D9:D4:7F:75:72:C2\n'
30-
'DirName:/CN=Stop-Gap Insecure CA\n'
31-
'serial:13:51:37:43:26:0A:A9:DE:32:FD:1C:EF:18:F2:9B:E7:A6:16:54:EF') == str(akid)
26+
assert '04:14:75:05:b3:00:68:0b:9c:d0:c0:46:e5:b5:aa:58:cb:8b:44:a2:92:d5' == skid.hex(':')
27+
assert '2024-03-17 08:21:07' == str(end_data)
28+
assert '30:16:80:14:14:38:d5:36:b1:5d:ab:f3:30:83:23:f0:6f:5b:c7:bf:2b:51:f5:9c' == akid.hex(':')
29+
30+
31+

modules/sc-mesh-secure-deployment/src/nats/cbma/unittests/test_secure_socket.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, cert_paths: CBMACertificates, tls_method: int) -> None:
2626
def verify(self, conn, cert, errnum, depth, ok) -> bool:
2727
return True
2828

29-
secure_socket = TestSecureSocket(cert_paths, SSL.TLS_SERVER_METHOD)
29+
secure_socket = TestSecureSocket(cert_paths, SSL.SSLv23_METHOD)
3030
try:
3131
secure_socket.create_ssl_context()
3232
assert True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
============================= test session starts ==============================
2+
platform linux -- Python 3.10.12, pytest-8.0.0, pluggy-1.4.0 -- /home/mika/work/nix/mesh_com/modules/sc-mesh-secure-deployment/src/nats/unittest_cbma/bin/python3
3+
cachedir: .pytest_cache
4+
rootdir: /home/mika/work/nix/mesh_com/modules/sc-mesh-secure-deployment/src/nats
5+
plugins: cov-5.0.0
6+
collecting ... collected 2 items
7+
8+
cbma/unittests/test_certificate_handler.py::test_openssl_certificate PASSED [ 50%]
9+
cbma/unittests/test_secure_socket.py::TestCreateSSLContext::test_certificate_loading PASSED [100%]
10+
11+
---------- coverage: platform linux, python 3.10.12-final-0 ----------
12+
Name Stmts Miss Cover Missing
13+
------------------------------------------------------------------------------
14+
cbma/cbma.py 134 134 0% 1-207
15+
cbma/certificates/certificates.py 29 3 90% 20, 28, 44
16+
cbma/controller.py 122 122 0% 1-169
17+
cbma/models/certificates.py 19 3 84% 17, 21, 25
18+
cbma/models/secure_socket/secure_connection.py 28 8 71% 10, 15, 20, 25, 30, 35, 40, 45
19+
cbma/models/secure_socket/secure_context.py 8 1 88% 13
20+
cbma/models/secure_socket/verification.py 11 1 91% 19
21+
cbma/secure_socket/__init__.py 0 0 100%
22+
cbma/secure_socket/client.py 79 79 0% 1-127
23+
cbma/secure_socket/secure_connection.py 47 28 40% 27-30, 34, 38, 42-46, 50-56, 60-70
24+
cbma/secure_socket/secure_context.py 34 7 79% 58-61, 65-68
25+
cbma/secure_socket/secure_socket.py 11 2 82% 14-16
26+
cbma/secure_socket/server.py 73 73 0% 1-105
27+
cbma/secure_socket/verification.py 78 54 31% 43-54, 58-68, 72-76, 80-103, 107-114, 128-145
28+
cbma/standalone.py 106 106 0% 1-175
29+
cbma/unittests/test_certificate_handler.py 19 0 100%
30+
cbma/unittests/test_secure_socket.py 24 3 88% 27, 33-34
31+
cbma/utils/__init__.py 0 0 100%
32+
cbma/utils/certificates.py 22 14 36% 18-33
33+
cbma/utils/common.py 38 29 24% 12-28, 33-48, 52, 56, 60-61
34+
cbma/utils/logging.py 132 73 45% 29, 49, 58-60, 68-69, 87-123, 127-136, 145, 154-159, 169-199
35+
cbma/utils/macsec.py 81 81 0% 1-125
36+
cbma/utils/multicast.py 2 2 0% 3-8
37+
cbma/utils/networking.py 30 21 30% 13-16, 20-25, 29-40, 44-49
38+
------------------------------------------------------------------------------
39+
TOTAL 1127 844 25%
40+
41+
42+
============================== 2 passed in 0.22s ===============================
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# preconditions
4+
if [ ! -f "$(pwd)/$(basename $0)" ]; then
5+
echo "Script is not being executed in the same folder"
6+
exit 1
7+
fi
8+
9+
# python virtualenv
10+
python3 -m venv unittest_cbma
11+
source unittest_cbma/bin/activate
12+
13+
# install dependencies to virtualenv
14+
pip install -r ./cbma/requirements.txt
15+
pip install -r ./requirements.txt
16+
# install testing only related dependencies
17+
pip install pytest pytest-cov
18+
19+
# discover and run unittests
20+
pytest --cov=cbma --cov-report term-missing -v --ignore=lucius/unittests --ignore=debug_tests --ignore=cbma/unittest --ignore=cbma/tests --ignore=tests |& tee ./cbma_coverage_report.txt
21+
22+
## deactivate virtualenv
23+
deactivate
24+
25+
# Clean up __pycache__ directories
26+
find . -type d -name '__pycache__' -exec rm -rf {} +
27+
# Clean up unittest venv
28+
rm -rf unittest_cbma
29+
# Clean up coverage tool's SQL database
30+
rm -f .coverage
31+

0 commit comments

Comments
 (0)