Skip to content

Commit f8ae7de

Browse files
committed
feat(modem): Added target test config with CHAP authentication
Related to #635
1 parent 73c4830 commit f8ae7de

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

.github/workflows/modem__target-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
matrix:
1616
idf_ver: ["latest"]
1717
idf_target: ["esp32c3"]
18-
test: [ { app: pppd, path: test/target }, { app: sim800_c3, path: examples/pppos_client }, { app: sim800_cmux, path: examples/simple_cmux_client } ]
18+
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 } ]
1919
include:
2020
- idf_ver: "latest"
2121
idf_target: "esp32s2"
@@ -58,7 +58,7 @@ jobs:
5858
matrix:
5959
idf_ver: ["latest"]
6060
idf_target: ["esp32c3"]
61-
test: [ { app: pppd, path: test/target }, { app: sim800_c3, path: examples/pppos_client }, { app: sim800_cmux, path: examples/simple_cmux_client } ]
61+
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 } ]
6262
include:
6363
- idf_ver: "latest"
6464
idf_target: "esp32s2"

components/esp_modem/test/target/main/Kconfig.projbuild

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ menu "Test App Configuration"
2727
help
2828
Pin number of UART RX.
2929

30-
config TEST_APP_TCP_PORT
31-
int "Port of test"
32-
range 0 65535
33-
default 2222
30+
config TEST_APP_AUTH
31+
bool "Use PPP authentication"
32+
select LWIP_PPP_CHAP_SUPPORT
33+
default n
3434
help
35-
The remote port to which the client will connects to
36-
once the PPP connection established
35+
Set to true for the PPP client to use authentication
36+
37+
config TEST_APP_AUTH_USERNAME
38+
string "Set username for authentication"
39+
default "myclient"
40+
help
41+
Username to authenticate the PPP connection.
42+
43+
config TEST_APP_AUTH_PASSWORD
44+
string "Set password for authentication"
45+
default "mypassword"
46+
help
47+
Password to authenticate the PPP connection.
3748

3849
endmenu

components/esp_modem/test/target/main/pppd_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ extern "C" void app_main(void)
9494
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, on_modem_event, nullptr));
9595
ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, nullptr));
9696

97+
#if CONFIG_TEST_APP_AUTH
98+
esp_netif_ppp_set_auth(ppp_netif, NETIF_PPP_AUTHTYPE_CHAP, CONFIG_TEST_APP_AUTH_USERNAME, CONFIG_TEST_APP_AUTH_PASSWORD);
99+
#endif
100+
97101
modem_start_network();
98102
Catch::Session session;
99103
int numFailed = session.run();

components/esp_modem/test/target/pytest_pppd.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Unlicense OR CC0-1.0
33
from __future__ import print_function, unicode_literals
44

@@ -9,14 +9,20 @@
99
import netifaces
1010

1111

12-
def run_server(server_stop, port, server_ip, client_ip):
12+
def run_server(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password):
1313
print('Starting PPP server on port: {}'.format(port))
1414
try:
1515
arg_list = [
1616
'sudo', 'pppd', port, '115200',
17-
'{}:{}'.format(server_ip, client_ip), 'modem', 'local', 'noauth',
17+
'{}:{}'.format(server_ip, client_ip), 'modem', 'local',
1818
'debug', 'nocrtscts', 'nodetach', '+ipv6'
1919
]
20+
if auth:
21+
arg_list.extend(['auth', '+chap'])
22+
subprocess.run(['sudo', 'rm', '/etc/ppp/chap-secrets'])
23+
subprocess.run(f"echo '{auth_user} * {auth_password} *' | sudo tee -a /etc/ppp/chap-secrets", shell=True)
24+
else:
25+
arg_list.append('noauth')
2026
p = subprocess.Popen(arg_list, stdout=subprocess.PIPE, bufsize=1)
2127
while not server_stop.is_set():
2228
if p.poll() is not None:
@@ -51,6 +57,9 @@ def test_examples_protocol_pppos_connect(dut):
5157
try:
5258
server_ip = dut.app.sdkconfig.get('TEST_APP_PPP_SERVER_IP')
5359
client_ip = dut.app.sdkconfig.get('TEST_APP_PPP_CLIENT_IP')
60+
auth = dut.app.sdkconfig.get('TEST_APP_AUTH')
61+
auth_user = dut.app.sdkconfig.get('TEST_APP_AUTH_USERNAME')
62+
auth_password = dut.app.sdkconfig.get('TEST_APP_AUTH_PASSWORD')
5463
except Exception:
5564
print(
5665
'ENV_TEST_FAILURE: Some mandatory configuration not found in sdkconfig'
@@ -63,7 +72,7 @@ def test_examples_protocol_pppos_connect(dut):
6372
# Start the PPP server
6473
server_stop = Event()
6574
t = Thread(target=run_server,
66-
args=(server_stop, port, server_ip, client_ip))
75+
args=(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password))
6776
t.start()
6877
try:
6978
ppp_server_timeout = time.time() + 30
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_COMPILER_CXX_EXCEPTIONS=y
2+
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
3+
CONFIG_LWIP_PPP_SUPPORT=y
4+
CONFIG_TEST_APP_AUTH=y
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
CONFIG_COMPILER_CXX_EXCEPTIONS=y
2-
CONFIG_CXX_EXCEPTIONS=y
3-
CONFIG_PPP_SUPPORT=y
42
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
3+
CONFIG_LWIP_PPP_SUPPORT=y

0 commit comments

Comments
 (0)