From f8ae7defd6bb4679c49ffd77d66349c42adf9c9a Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 23 Aug 2024 17:17:11 +0200 Subject: [PATCH 1/3] feat(modem): Added target test config with CHAP authentication Related to https://github.com/espressif/esp-protocols/issues/635 --- .github/workflows/modem__target-test.yml | 4 ++-- .../test/target/main/Kconfig.projbuild | 23 ++++++++++++++----- .../esp_modem/test/target/main/pppd_test.cpp | 4 ++++ .../esp_modem/test/target/pytest_pppd.py | 17 ++++++++++---- .../test/target/sdkconfig.ci.pppd_chap_auth | 4 ++++ .../esp_modem/test/target/sdkconfig.defaults | 3 +-- 6 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 components/esp_modem/test/target/sdkconfig.ci.pppd_chap_auth diff --git a/.github/workflows/modem__target-test.yml b/.github/workflows/modem__target-test.yml index 5681a5e05..4de01e6cb 100644 --- a/.github/workflows/modem__target-test.yml +++ b/.github/workflows/modem__target-test.yml @@ -15,7 +15,7 @@ jobs: matrix: idf_ver: ["latest"] idf_target: ["esp32c3"] - test: [ { app: pppd, path: test/target }, { app: sim800_c3, path: examples/pppos_client }, { app: sim800_cmux, path: examples/simple_cmux_client } ] + test: [ { app: pppd, path: test/target }, { app: pppd_chap_auth, path: test/target }, { app: sim800_c3, path: examples/pppos_client }, { app: sim800_cmux, path: examples/simple_cmux_client } ] include: - idf_ver: "latest" idf_target: "esp32s2" @@ -58,7 +58,7 @@ jobs: matrix: idf_ver: ["latest"] idf_target: ["esp32c3"] - test: [ { app: pppd, path: test/target }, { app: sim800_c3, path: examples/pppos_client }, { app: sim800_cmux, path: examples/simple_cmux_client } ] + test: [ { app: pppd, path: test/target }, { app: pppd_chap_auth, path: test/target }, { app: sim800_c3, path: examples/pppos_client }, { app: sim800_cmux, path: examples/simple_cmux_client } ] include: - idf_ver: "latest" idf_target: "esp32s2" diff --git a/components/esp_modem/test/target/main/Kconfig.projbuild b/components/esp_modem/test/target/main/Kconfig.projbuild index 8b32e0252..871f75485 100644 --- a/components/esp_modem/test/target/main/Kconfig.projbuild +++ b/components/esp_modem/test/target/main/Kconfig.projbuild @@ -27,12 +27,23 @@ menu "Test App Configuration" help Pin number of UART RX. - config TEST_APP_TCP_PORT - int "Port of test" - range 0 65535 - default 2222 + config TEST_APP_AUTH + bool "Use PPP authentication" + select LWIP_PPP_CHAP_SUPPORT + default n help - The remote port to which the client will connects to - once the PPP connection established + Set to true for the PPP client to use authentication + + config TEST_APP_AUTH_USERNAME + string "Set username for authentication" + default "myclient" + help + Username to authenticate the PPP connection. + + config TEST_APP_AUTH_PASSWORD + string "Set password for authentication" + default "mypassword" + help + Password to authenticate the PPP connection. endmenu diff --git a/components/esp_modem/test/target/main/pppd_test.cpp b/components/esp_modem/test/target/main/pppd_test.cpp index 06195215d..4d4860977 100644 --- a/components/esp_modem/test/target/main/pppd_test.cpp +++ b/components/esp_modem/test/target/main/pppd_test.cpp @@ -94,6 +94,10 @@ extern "C" void app_main(void) ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_modem_event, nullptr)); ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, nullptr)); +#if CONFIG_TEST_APP_AUTH + esp_netif_ppp_set_auth(ppp_netif, NETIF_PPP_AUTHTYPE_CHAP, CONFIG_TEST_APP_AUTH_USERNAME, CONFIG_TEST_APP_AUTH_PASSWORD); +#endif + modem_start_network(); Catch::Session session; int numFailed = session.run(); diff --git a/components/esp_modem/test/target/pytest_pppd.py b/components/esp_modem/test/target/pytest_pppd.py index 707936a54..d675e3c65 100644 --- a/components/esp_modem/test/target/pytest_pppd.py +++ b/components/esp_modem/test/target/pytest_pppd.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 from __future__ import print_function, unicode_literals @@ -9,14 +9,20 @@ from threading import Event, Thread import netifaces -def run_server(server_stop, port, server_ip, client_ip): +def run_server(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password): print('Starting PPP server on port: {}'.format(port)) try: arg_list = [ 'sudo', 'pppd', port, '115200', - '{}:{}'.format(server_ip, client_ip), 'modem', 'local', 'noauth', + '{}:{}'.format(server_ip, client_ip), 'modem', 'local', 'debug', 'nocrtscts', 'nodetach', '+ipv6' ] + if auth: + arg_list.extend(['auth', '+chap']) + subprocess.run(['sudo', 'rm', '/etc/ppp/chap-secrets']) + subprocess.run(f"echo '{auth_user} * {auth_password} *' | sudo tee -a /etc/ppp/chap-secrets", shell=True) + else: + arg_list.append('noauth') p = subprocess.Popen(arg_list, stdout=subprocess.PIPE, bufsize=1) while not server_stop.is_set(): if p.poll() is not None: @@ -51,6 +57,9 @@ def test_examples_protocol_pppos_connect(dut): try: server_ip = dut.app.sdkconfig.get('TEST_APP_PPP_SERVER_IP') client_ip = dut.app.sdkconfig.get('TEST_APP_PPP_CLIENT_IP') + auth = dut.app.sdkconfig.get('TEST_APP_AUTH') + auth_user = dut.app.sdkconfig.get('TEST_APP_AUTH_USERNAME') + auth_password = dut.app.sdkconfig.get('TEST_APP_AUTH_PASSWORD') except Exception: print( 'ENV_TEST_FAILURE: Some mandatory configuration not found in sdkconfig' @@ -63,7 +72,7 @@ def test_examples_protocol_pppos_connect(dut): # Start the PPP server server_stop = Event() t = Thread(target=run_server, - args=(server_stop, port, server_ip, client_ip)) + args=(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password)) t.start() try: ppp_server_timeout = time.time() + 30 diff --git a/components/esp_modem/test/target/sdkconfig.ci.pppd_chap_auth b/components/esp_modem/test/target/sdkconfig.ci.pppd_chap_auth new file mode 100644 index 000000000..23b587e9c --- /dev/null +++ b/components/esp_modem/test/target/sdkconfig.ci.pppd_chap_auth @@ -0,0 +1,4 @@ +CONFIG_COMPILER_CXX_EXCEPTIONS=y +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_LWIP_PPP_SUPPORT=y +CONFIG_TEST_APP_AUTH=y diff --git a/components/esp_modem/test/target/sdkconfig.defaults b/components/esp_modem/test/target/sdkconfig.defaults index 4af92e67d..28ae669b9 100644 --- a/components/esp_modem/test/target/sdkconfig.defaults +++ b/components/esp_modem/test/target/sdkconfig.defaults @@ -1,4 +1,3 @@ CONFIG_COMPILER_CXX_EXCEPTIONS=y -CONFIG_CXX_EXCEPTIONS=y -CONFIG_PPP_SUPPORT=y CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_LWIP_PPP_SUPPORT=y From f5c13b927fa56f7d2b18396c8a50183d968af8f7 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 28 Aug 2024 07:59:48 +0200 Subject: [PATCH 2/3] fix(modem): Examples: use local configs for MQTT topic/data To avoid issues in CI, as we're using public server and could receive data by people playing with the example --- .../simple_cmux_client/main/Kconfig.projbuild | 12 ++++++++++++ .../main/simple_cmux_client_main.cpp | 4 ++-- .../examples/simple_cmux_client/pytest_cmux.py | 15 ++++++++++++--- .../simple_cmux_client/sdkconfig.ci.sim800_cmux | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/components/esp_modem/examples/simple_cmux_client/main/Kconfig.projbuild b/components/esp_modem/examples/simple_cmux_client/main/Kconfig.projbuild index bf733a9ee..b7347303d 100644 --- a/components/esp_modem/examples/simple_cmux_client/main/Kconfig.projbuild +++ b/components/esp_modem/examples/simple_cmux_client/main/Kconfig.projbuild @@ -129,4 +129,16 @@ menu "Example Configuration" help URL of an mqtt broker which this example connects to. + config EXAMPLE_MQTT_TEST_TOPIC + string "MQTT topic to publish/subscribe" + default "/topic/esp-pppos" + help + MQTT topic, which we subscribe on and publish to. + + config EXAMPLE_MQTT_TEST_DATA + string "MQTT data to publish/receive" + default "esp32-pppos" + help + MQTT data message, which we publish and expect to receive. + endmenu diff --git a/components/esp_modem/examples/simple_cmux_client/main/simple_cmux_client_main.cpp b/components/esp_modem/examples/simple_cmux_client/main/simple_cmux_client_main.cpp index a1432b756..f1b8e8439 100644 --- a/components/esp_modem/examples/simple_cmux_client/main/simple_cmux_client_main.cpp +++ b/components/esp_modem/examples/simple_cmux_client/main/simple_cmux_client_main.cpp @@ -234,8 +234,8 @@ extern "C" void app_main(void) } std::cout << "Connected" << std::endl; - mqtt.subscribe("/topic/esp-modem"); - mqtt.publish("/topic/esp-modem", "Hello modem"); + mqtt.subscribe(CONFIG_EXAMPLE_MQTT_TEST_TOPIC); + mqtt.publish(CONFIG_EXAMPLE_MQTT_TEST_TOPIC, CONFIG_EXAMPLE_MQTT_TEST_DATA); if (!handler.wait_for(StatusHandler::MQTT_Data, 60000)) { ESP_LOGE(TAG, "Didn't receive published data within specified timeout... exiting"); return; diff --git a/components/esp_modem/examples/simple_cmux_client/pytest_cmux.py b/components/esp_modem/examples/simple_cmux_client/pytest_cmux.py index 208212838..af82e7798 100644 --- a/components/esp_modem/examples/simple_cmux_client/pytest_cmux.py +++ b/components/esp_modem/examples/simple_cmux_client/pytest_cmux.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 from __future__ import print_function, unicode_literals @@ -10,8 +10,17 @@ def test_cmux_connection(dut): 2. checks we get an IP 3. checks for the MQTT events """ + # Get topic and data from Kconfig + topic = '' + data = '' + try: + topic = dut.app.sdkconfig.get('EXAMPLE_MQTT_TEST_TOPIC') + data = dut.app.sdkconfig.get('EXAMPLE_MQTT_TEST_DATA') + except Exception: + print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig') + raise # Check the sequence of connecting, publishing, disconnecting dut.expect('Modem has correctly entered multiplexed') # Check for MQTT connection and the data event - dut.expect('TOPIC: /topic/esp-modem') - dut.expect('DATA: Hello modem') + dut.expect(f'TOPIC: {topic}') + dut.expect(f'DATA: {data}') diff --git a/components/esp_modem/examples/simple_cmux_client/sdkconfig.ci.sim800_cmux b/components/esp_modem/examples/simple_cmux_client/sdkconfig.ci.sim800_cmux index dcdb2f029..6bf623113 100644 --- a/components/esp_modem/examples/simple_cmux_client/sdkconfig.ci.sim800_cmux +++ b/components/esp_modem/examples/simple_cmux_client/sdkconfig.ci.sim800_cmux @@ -15,3 +15,4 @@ CONFIG_ESP32_PANIC_PRINT_HALT=y CONFIG_COMPILER_CXX_EXCEPTIONS=y CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 CONFIG_EXAMPLE_CLOSE_CMUX_AT_END=y +CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client" From fb7b0c201d98e581d66ca83b811906ced020152f Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 12 Sep 2024 09:37:03 +0200 Subject: [PATCH 3/3] ci(common): Fix clang-tidy job not use deprecated action --- .github/workflows/clang-tidy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index e77a31a6f..4708d7490 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -42,7 +42,7 @@ jobs: export PATH=$PWD:$PATH ./clang-tidy-sarif -o results.sarif.raw warnings.txt python3 filter_sarif.py -o results.sarif --include-prefix ${GITHUB_WORKSPACE}/ results.sarif.raw - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: path: | warnings.txt