1
0
mirror of https://github.com/esphome/esphome.git synced 2025-07-14 11:03:30 +01:00
Files
.devcontainer
.github
.vscode
docker
esphome
script
tests
component_tests
components
dashboard
integration
fixtures
README.md
__init__.py
conftest.py
const.py
test_api_conditional_memory.py
test_api_custom_services.py
test_api_message_size_batching.py
test_api_reboot_timeout.py
test_api_vv_logging.py
test_areas_and_devices.py
test_batch_delay_zero_rapid_transitions.py
test_device_id_in_state.py
test_duplicate_entities.py
test_entity_icon.py
test_host_mode_basic.py
test_host_mode_batch_delay.py
test_host_mode_empty_string_options.py
test_host_mode_entity_fields.py
test_host_mode_fan_preset.py
test_host_mode_many_entities.py
test_host_mode_many_entities_multiple_connections.py
test_host_mode_noise_encryption.py
test_host_mode_reconnect.py
test_host_mode_sensor.py
test_large_message_batching.py
test_legacy_area.py
test_light_calls.py
test_loop_disable_enable.py
test_scheduler_bulk_cleanup.py
test_scheduler_defer_cancel.py
test_scheduler_defer_cancel_regular.py
test_scheduler_defer_fifo_simple.py
test_scheduler_defer_stress.py
test_scheduler_heap_stress.py
test_scheduler_null_name.py
test_scheduler_rapid_cancellation.py
test_scheduler_recursive_timeout.py
test_scheduler_simultaneous_callbacks.py
test_scheduler_string_lifetime.py
test_scheduler_string_name_stress.py
test_scheduler_string_test.py
types.py
script
test_build_components
test_packages
unit_tests
.gitignore
README.md
custom.h
dummy_main.cpp
pnglogo.png
.clang-format
.clang-tidy
.clang-tidy.hash
.coveragerc
.dockerignore
.editorconfig
.flake8
.gitattributes
.gitignore
.pre-commit-config.yaml
.yamllint
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Doxyfile
LICENSE
MANIFEST.in
README.md
netlify.toml
platformio.ini
pyproject.toml
requirements.txt
requirements_dev.txt
requirements_test.txt
sdkconfig.defaults
esphome/tests/integration/test_host_mode_noise_encryption.py
2025-05-26 21:31:32 -05:00

54 lines
1.9 KiB
Python

"""Integration test for Host mode with noise encryption."""
from __future__ import annotations
from aioesphomeapi import InvalidEncryptionKeyAPIError
import pytest
from .types import APIClientConnectedFactory, RunCompiledFunction
# The API key for noise encryption
NOISE_KEY = "N4Yle5YirwZhPiHHsdZLdOA73ndj/84veVaLhTvxCuU="
@pytest.mark.asyncio
async def test_host_mode_noise_encryption(
yaml_config: str,
run_compiled: RunCompiledFunction,
api_client_connected: APIClientConnectedFactory,
) -> None:
"""Test Host mode with noise encryption enabled."""
# Write, compile and run the ESPHome device, then connect to API
# The API client should handle noise encryption automatically
async with (
run_compiled(yaml_config),
api_client_connected(noise_psk=NOISE_KEY) as client,
):
# If we can get device info, the encryption is working
device_info = await client.device_info()
assert device_info is not None
assert device_info.name == "host-noise-test"
# List entities to ensure the encrypted connection is fully functional
entities = await client.list_entities_services()
assert entities is not None
@pytest.mark.asyncio
async def test_host_mode_noise_encryption_wrong_key(
yaml_config: str,
run_compiled: RunCompiledFunction,
api_client_connected: APIClientConnectedFactory,
) -> None:
"""Test that connection fails with wrong encryption key."""
# Write, compile and run the ESPHome device
async with run_compiled(yaml_config):
# Try to connect with wrong key - should fail with InvalidEncryptionKeyAPIError
with pytest.raises(InvalidEncryptionKeyAPIError):
async with api_client_connected(
noise_psk="wrong_key_that_should_not_work",
timeout=5, # Shorter timeout for expected failure
) as client:
# This should not be reached
await client.device_info()