Skip to content

Commit d288041

Browse files
authored
Merge pull request #640 from david-cermak/feat/ppp_chap_test
[modem]: Added CHAP authentication test
2 parents 8e4d43e + fb7b0c2 commit d288041

File tree

11 files changed

+69
-20
lines changed

11 files changed

+69
-20
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
export PATH=$PWD:$PATH
4343
./clang-tidy-sarif -o results.sarif.raw warnings.txt
4444
python3 filter_sarif.py -o results.sarif --include-prefix ${GITHUB_WORKSPACE}/ results.sarif.raw
45-
- uses: actions/upload-artifact@v2
45+
- uses: actions/upload-artifact@v4
4646
with:
4747
path: |
4848
warnings.txt

.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/examples/simple_cmux_client/main/Kconfig.projbuild

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,16 @@ menu "Example Configuration"
129129
help
130130
URL of an mqtt broker which this example connects to.
131131

132+
config EXAMPLE_MQTT_TEST_TOPIC
133+
string "MQTT topic to publish/subscribe"
134+
default "/topic/esp-pppos"
135+
help
136+
MQTT topic, which we subscribe on and publish to.
137+
138+
config EXAMPLE_MQTT_TEST_DATA
139+
string "MQTT data to publish/receive"
140+
default "esp32-pppos"
141+
help
142+
MQTT data message, which we publish and expect to receive.
143+
132144
endmenu

components/esp_modem/examples/simple_cmux_client/main/simple_cmux_client_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ extern "C" void app_main(void)
234234
}
235235
std::cout << "Connected" << std::endl;
236236

237-
mqtt.subscribe("/topic/esp-modem");
238-
mqtt.publish("/topic/esp-modem", "Hello modem");
237+
mqtt.subscribe(CONFIG_EXAMPLE_MQTT_TEST_TOPIC);
238+
mqtt.publish(CONFIG_EXAMPLE_MQTT_TEST_TOPIC, CONFIG_EXAMPLE_MQTT_TEST_DATA);
239239
if (!handler.wait_for(StatusHandler::MQTT_Data, 60000)) {
240240
ESP_LOGE(TAG, "Didn't receive published data within specified timeout... exiting");
241241
return;

components/esp_modem/examples/simple_cmux_client/pytest_cmux.py

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

@@ -10,8 +10,17 @@ def test_cmux_connection(dut):
1010
2. checks we get an IP
1111
3. checks for the MQTT events
1212
"""
13+
# Get topic and data from Kconfig
14+
topic = ''
15+
data = ''
16+
try:
17+
topic = dut.app.sdkconfig.get('EXAMPLE_MQTT_TEST_TOPIC')
18+
data = dut.app.sdkconfig.get('EXAMPLE_MQTT_TEST_DATA')
19+
except Exception:
20+
print('ENV_TEST_FAILURE: Cannot find broker url in sdkconfig')
21+
raise
1322
# Check the sequence of connecting, publishing, disconnecting
1423
dut.expect('Modem has correctly entered multiplexed')
1524
# Check for MQTT connection and the data event
16-
dut.expect('TOPIC: /topic/esp-modem')
17-
dut.expect('DATA: Hello modem')
25+
dut.expect(f'TOPIC: {topic}')
26+
dut.expect(f'DATA: {data}')

components/esp_modem/examples/simple_cmux_client/sdkconfig.ci.sim800_cmux

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ CONFIG_ESP32_PANIC_PRINT_HALT=y
1515
CONFIG_COMPILER_CXX_EXCEPTIONS=y
1616
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
1717
CONFIG_EXAMPLE_CLOSE_CMUX_AT_END=y
18+
CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"

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

0 commit comments

Comments
 (0)