Skip to content

Commit

Permalink
Merge pull request #342 from chrysn-pull-requests/python-test-logging
Browse files Browse the repository at this point in the history
python/tests: Add basic test for logging
  • Loading branch information
geonnave authored Feb 5, 2025
2 parents 747368a + c1035ac commit 9abafd2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lakers-python/test/test_lakers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import io
import logging
import lakers
import cbor2
import pytest
from lakers import CredentialTransfer, EdhocInitiator, EdhocResponder

# This needs to be early, thus top-level: Once Lakers objects are created, the
# log level is fixed.
LOGSTREAM = io.StringIO()
logging.basicConfig(stream=LOGSTREAM, level=0, force=True)

# values from RFC9529, but CRED_I shortened so that passing by value is possible in a 256 byte message
CRED_I = bytes.fromhex("A202617808A101A5010202412B2001215820AC75E9ECE3E50BFC8ED60399889522405C47BF16DF96660A41298CB4307F7EB62258206E5DE611388A4B8A8211334AC7D37ECB52A387D257E6DB3C2A93DF21FF3AFFC8")
I = bytes.fromhex("fb13adeb6518cee5f88417660841142e830a81fe334380a953406a1305e8706b")
Expand Down Expand Up @@ -98,6 +105,15 @@ def test_buffer_error():
_ = initiator.parse_message_2(cbor2.dumps(bytes([1] * 10000)))
assert str(err.value) == "MessageBufferError::SliceTooLong"

def test_logging():
LOGSTREAM.truncate(0)
LOGSTREAM.seek(0)

test_handshake_credential_transfer_by(CredentialTransfer.ByValue, CredentialTransfer.ByValue)

# So far we don't test much, but that is currently in it an shows that log messages get through.
assert 'Initializing EdhocInitiator' in LOGSTREAM.getvalue()

@pytest.mark.parametrize("cred_r_transfer", [CredentialTransfer.ByReference, CredentialTransfer.ByValue])
@pytest.mark.parametrize("cred_i_transfer", [CredentialTransfer.ByReference, CredentialTransfer.ByValue])
def test_handshake_credential_transfer_by(cred_r_transfer, cred_i_transfer):
Expand Down

0 comments on commit 9abafd2

Please sign in to comment.