Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for CBMA unittests and fix tests #486

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_openssl_certificate() -> None:
end_data: datetime = certificate.get_end_date()
assert end_data

assert '64:73:81:83:B3:F1:72:AD:28:6D:BE:9B:0F:A1:D9:D4:7F:75:72:C2' == str(skid)
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(':')
assert '2024-05-13 09:16:24' == str(end_data)
assert ('keyid:64:73:81:83:B3:F1:72:AD:28:6D:BE:9B:0F:A1:D9:D4:7F:75:72:C2\n'
'DirName:/CN=Stop-Gap Insecure CA\n'
'serial:13:51:37:43:26:0A:A9:DE:32:FD:1C:EF:18:F2:9B:E7:A6:16:54:EF') == str(akid)
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(':')
assert '2024-03-17 08:21:07' == str(end_data)
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(':')



Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, cert_paths: CBMACertificates, tls_method: int) -> None:
def verify(self, conn, cert, errnum, depth, ok) -> bool:
return True

secure_socket = TestSecureSocket(cert_paths, SSL.TLS_SERVER_METHOD)
secure_socket = TestSecureSocket(cert_paths, SSL.SSLv23_METHOD)
try:
secure_socket.create_ssl_context()
assert True
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
============================= test session starts ==============================
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
cachedir: .pytest_cache
rootdir: /home/mika/work/nix/mesh_com/modules/sc-mesh-secure-deployment/src/nats
plugins: cov-5.0.0
collecting ... collected 2 items

cbma/unittests/test_certificate_handler.py::test_openssl_certificate PASSED [ 50%]
cbma/unittests/test_secure_socket.py::TestCreateSSLContext::test_certificate_loading PASSED [100%]

---------- coverage: platform linux, python 3.10.12-final-0 ----------
Name Stmts Miss Cover Missing
------------------------------------------------------------------------------
cbma/cbma.py 134 134 0% 1-207
cbma/certificates/certificates.py 29 3 90% 20, 28, 44
cbma/controller.py 122 122 0% 1-169
cbma/models/certificates.py 19 3 84% 17, 21, 25
cbma/models/secure_socket/secure_connection.py 28 8 71% 10, 15, 20, 25, 30, 35, 40, 45
cbma/models/secure_socket/secure_context.py 8 1 88% 13
cbma/models/secure_socket/verification.py 11 1 91% 19
cbma/secure_socket/__init__.py 0 0 100%
cbma/secure_socket/client.py 79 79 0% 1-127
cbma/secure_socket/secure_connection.py 47 28 40% 27-30, 34, 38, 42-46, 50-56, 60-70
cbma/secure_socket/secure_context.py 34 7 79% 58-61, 65-68
cbma/secure_socket/secure_socket.py 11 2 82% 14-16
cbma/secure_socket/server.py 73 73 0% 1-105
cbma/secure_socket/verification.py 78 54 31% 43-54, 58-68, 72-76, 80-103, 107-114, 128-145
cbma/standalone.py 106 106 0% 1-175
cbma/unittests/test_certificate_handler.py 19 0 100%
cbma/unittests/test_secure_socket.py 24 3 88% 27, 33-34
cbma/utils/__init__.py 0 0 100%
cbma/utils/certificates.py 22 14 36% 18-33
cbma/utils/common.py 38 29 24% 12-28, 33-48, 52, 56, 60-61
cbma/utils/logging.py 132 73 45% 29, 49, 58-60, 68-69, 87-123, 127-136, 145, 154-159, 169-199
cbma/utils/macsec.py 81 81 0% 1-125
cbma/utils/multicast.py 2 2 0% 3-8
cbma/utils/networking.py 30 21 30% 13-16, 20-25, 29-40, 44-49
------------------------------------------------------------------------------
TOTAL 1127 844 25%


============================== 2 passed in 0.22s ===============================
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# preconditions
if [ ! -f "$(pwd)/$(basename $0)" ]; then
echo "Script is not being executed in the same folder"
exit 1
fi

# python virtualenv
python3 -m venv unittest_cbma
source unittest_cbma/bin/activate

# install dependencies to virtualenv
pip install -r ./cbma/requirements.txt
pip install -r ./requirements.txt
# install testing only related dependencies
pip install pytest pytest-cov

# discover and run unittests
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

## deactivate virtualenv
deactivate

# Clean up __pycache__ directories
find . -type d -name '__pycache__' -exec rm -rf {} +
# Clean up unittest venv
rm -rf unittest_cbma
# Clean up coverage tool's SQL database
rm -f .coverage

Loading