2017-10-09 22:48:57 -04:00
|
|
|
import os
|
2021-01-08 06:26:28 -05:00
|
|
|
import re
|
2021-01-25 21:49:01 -05:00
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
import ttfw_idf
|
2021-01-08 06:26:28 -05:00
|
|
|
from tiny_test_fw import Utility
|
2017-10-09 22:48:57 -04:00
|
|
|
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
|
2017-10-09 22:48:57 -04:00
|
|
|
def test_examples_protocol_https_request(env, extra_data):
|
|
|
|
"""
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
2021-01-08 06:26:28 -05:00
|
|
|
2. establish TLS connection to www.howsmyssl.com:443 with multiple
|
|
|
|
certificate verification options
|
2017-10-09 22:48:57 -04:00
|
|
|
3. send http request
|
|
|
|
"""
|
2021-01-25 21:49:01 -05:00
|
|
|
dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT)
|
2017-11-11 02:17:00 -05:00
|
|
|
# check and log bin size
|
2021-01-25 21:49:01 -05:00
|
|
|
binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
|
2017-11-11 02:17:00 -05:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2021-01-25 21:49:01 -05:00
|
|
|
ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024))
|
2021-01-08 06:26:28 -05:00
|
|
|
# start tes
|
2021-01-25 21:49:01 -05:00
|
|
|
Utility.console_log('Starting https_request simple test app')
|
2017-10-09 22:48:57 -04:00
|
|
|
dut1.start_app()
|
|
|
|
|
2021-01-08 06:26:28 -05:00
|
|
|
# Check for connection using crt bundle
|
|
|
|
Utility.console_log("Testing for \"https_request using crt bundle\"")
|
|
|
|
try:
|
2021-01-25 21:49:01 -05:00
|
|
|
dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
|
|
|
|
dut1.expect_all('Certificate validated',
|
|
|
|
'Connection established...',
|
|
|
|
'Reading HTTP response...',
|
|
|
|
'HTTP/1.1 200 OK',
|
|
|
|
re.compile('connection closed'))
|
2021-01-08 06:26:28 -05:00
|
|
|
except Exception:
|
|
|
|
Utility.console_log("Failed the test for \"https_request using crt bundle\"")
|
|
|
|
raise
|
|
|
|
Utility.console_log("Passed the test for \"https_request using crt bundle\"")
|
|
|
|
|
|
|
|
# Check for connection using cacert_buf
|
|
|
|
Utility.console_log("Testing for \"https_request using cacert_buf\"")
|
|
|
|
try:
|
2021-01-25 21:49:01 -05:00
|
|
|
dut1.expect(re.compile('https_request using cacert_buf'), timeout=20)
|
|
|
|
dut1.expect_all('Connection established...',
|
|
|
|
'Reading HTTP response...',
|
|
|
|
'HTTP/1.1 200 OK',
|
|
|
|
re.compile('connection closed'))
|
2021-01-08 06:26:28 -05:00
|
|
|
except Exception:
|
|
|
|
Utility.console_log("Passed the test for \"https_request using cacert_buf\"")
|
|
|
|
raise
|
|
|
|
Utility.console_log("Passed the test for \"https_request using cacert_buf\"")
|
|
|
|
|
|
|
|
# Check for connection using global ca_store
|
|
|
|
Utility.console_log("Testing for \"https_request using global ca_store\"")
|
|
|
|
try:
|
2021-01-25 21:49:01 -05:00
|
|
|
dut1.expect(re.compile('https_request using global ca_store'), timeout=20)
|
|
|
|
dut1.expect_all('Connection established...',
|
|
|
|
'Reading HTTP response...',
|
|
|
|
'HTTP/1.1 200 OK',
|
|
|
|
re.compile('connection closed'))
|
2021-01-08 06:26:28 -05:00
|
|
|
except Exception:
|
|
|
|
Utility.console_log("Failed the test for \"https_request using global ca_store\"")
|
|
|
|
raise
|
|
|
|
Utility.console_log("Passed the test for \"https_request using global ca_store\"")
|
|
|
|
|
2021-09-01 23:36:09 -04:00
|
|
|
# Check for connection using already saved client session
|
|
|
|
Utility.console_log("Testing for \"https_request using saved client session\"")
|
|
|
|
try:
|
|
|
|
dut1.expect(re.compile('https_request using saved client session'), timeout=20)
|
|
|
|
dut1.expect_all('Connection established...',
|
|
|
|
'Reading HTTP response...',
|
|
|
|
'HTTP/1.1 200 OK',
|
|
|
|
re.compile('connection closed'))
|
|
|
|
except Exception:
|
|
|
|
Utility.console_log("Failed the test for \"https_request using saved client session\"")
|
|
|
|
raise
|
|
|
|
Utility.console_log("Passed the test for \"https_request using saved client session\"")
|
|
|
|
|
2021-01-08 06:26:28 -05:00
|
|
|
# Check for connection using crt bundle with mbedtls dynamic resource enabled
|
2021-01-25 21:49:01 -05:00
|
|
|
dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
2020-04-10 04:33:54 -04:00
|
|
|
# check and log bin size
|
2021-01-25 21:49:01 -05:00
|
|
|
binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
|
2020-04-10 04:33:54 -04:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2021-01-25 21:49:01 -05:00
|
|
|
ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024))
|
2020-04-10 04:33:54 -04:00
|
|
|
# start test
|
|
|
|
dut1.start_app()
|
2021-01-08 06:26:28 -05:00
|
|
|
# only check if one connection is established
|
|
|
|
Utility.console_log("Testing for \"https_request using crt bundle\" with mbedtls dynamic resource enabled")
|
|
|
|
try:
|
2021-01-25 21:49:01 -05:00
|
|
|
dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
|
|
|
|
dut1.expect_all('Connection established...',
|
|
|
|
'Reading HTTP response...',
|
|
|
|
'HTTP/1.1 200 OK',
|
|
|
|
re.compile('connection closed'))
|
2021-01-08 06:26:28 -05:00
|
|
|
except Exception:
|
|
|
|
Utility.console_log("Failed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
|
|
|
|
raise
|
|
|
|
Utility.console_log("Passed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
|
2020-04-10 04:33:54 -04:00
|
|
|
|
2017-10-09 22:48:57 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_examples_protocol_https_request()
|