Conversation

andrewleech

Summary

Adds comprehensive multitests for BLE pairing and bonding functionality to the aioble library.

New Tests Added

1. ble_pair.py - Pairing without persistent bonding

  • Tests encryption with bond=False
  • Verifies temporary pairing that doesn't persist
  • Expected result: encrypted=1 authenticated=0 bonded=0

2. ble_bond.py - Pairing with persistent bonding

  • Tests encryption with bond=True
  • Verifies persistent bonding with secret storage
  • Expected result: encrypted=1 authenticated=0 bonded=1 + secrets_exist yes

Technical Implementation

  • Custom EncryptedCharacteristic: Extends aioble.Characteristic with _FLAG_READ_ENCRYPTED to require pairing for access
  • Cross-compatibility: Works with both BTstack and NimBLE implementations
  • State management: Proper timing and bond file management for deterministic testing
  • Comprehensive coverage: Tests pairing initiation, encryption, characteristic access, and bond persistence

Testing

Both tests pass consistently on BTstack-enabled MicroPython builds:

python ./tests/run-multitests.py -i pyb:/dev/ttyACM0 -i pyb:/dev/ttyACM1 -t -p2 micropython/bluetooth/aioble/multitests/ble_pair.py
python ./tests/run-multitests.py -i pyb:/dev/ttyACM0 -i pyb:/dev/ttyACM1 -t -p2 micropython/bluetooth/aioble/multitests/ble_bond.py

Motivation

These tests fill a critical gap in aioble testing coverage by providing:

  • Validation of security features (pairing/bonding)
  • Verification of encrypted characteristic access
  • Regression testing for BTstack pairing improvements
  • Examples for developers implementing secure BLE applications

The tests complement the recent BTstack pairing/bonding implementation and demonstrate that aioble's async API works correctly with the underlying security features.

🤖 Generated with Claude Code

@andrewleech

This was used to test micropython/micropython#17469 and was run with a RPI_PICO2_W and PYBD_SF^

Adds comprehensive tests for BLE pairing and bonding functionality:

- ble_pair.py: Tests encryption without persistent bonding (bond=False)
- ble_bond.py: Tests encryption with persistent bonding (bond=True)

Both tests verify:
- Encrypted characteristic access requiring pairing
- Proper connection state tracking (encrypted, authenticated, bonded)
- Cross-compatibility with BTstack implementation
- Bond storage via aioble.security module

Tests use custom EncryptedCharacteristic class to add _FLAG_READ_ENCRYPTED
requirement, ensuring pairing is mandatory for characteristic access.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andrew Leech <[email protected]>
Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

@andrewleech