example_test.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import os
  2. import re
  3. import ttfw_idf
  4. from tiny_test_fw import Utility
  5. @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
  6. def test_examples_protocol_https_request(env, extra_data):
  7. """
  8. steps: |
  9. 1. join AP
  10. 2. establish TLS connection to www.howsmyssl.com:443 with multiple
  11. certificate verification options
  12. 3. send http request
  13. """
  14. dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT)
  15. # check and log bin size
  16. binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
  17. bin_size = os.path.getsize(binary_file)
  18. ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024))
  19. # start tes
  20. Utility.console_log('Starting https_request simple test app')
  21. dut1.start_app()
  22. # Check for connection using crt bundle
  23. Utility.console_log("Testing for \"https_request using crt bundle\"")
  24. try:
  25. dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
  26. dut1.expect_all('Certificate validated',
  27. 'Connection established...',
  28. 'Reading HTTP response...',
  29. 'HTTP/1.1 200 OK',
  30. re.compile('connection closed'))
  31. except Exception:
  32. Utility.console_log("Failed the test for \"https_request using crt bundle\"")
  33. raise
  34. Utility.console_log("Passed the test for \"https_request using crt bundle\"")
  35. # Check for connection using cacert_buf
  36. Utility.console_log("Testing for \"https_request using cacert_buf\"")
  37. try:
  38. dut1.expect(re.compile('https_request using cacert_buf'), timeout=20)
  39. dut1.expect_all('Connection established...',
  40. 'Reading HTTP response...',
  41. 'HTTP/1.1 200 OK',
  42. re.compile('connection closed'))
  43. except Exception:
  44. Utility.console_log("Passed the test for \"https_request using cacert_buf\"")
  45. raise
  46. Utility.console_log("Passed the test for \"https_request using cacert_buf\"")
  47. # Check for connection using global ca_store
  48. Utility.console_log("Testing for \"https_request using global ca_store\"")
  49. try:
  50. dut1.expect(re.compile('https_request using global ca_store'), timeout=20)
  51. dut1.expect_all('Connection established...',
  52. 'Reading HTTP response...',
  53. 'HTTP/1.1 200 OK',
  54. re.compile('connection closed'))
  55. except Exception:
  56. Utility.console_log("Failed the test for \"https_request using global ca_store\"")
  57. raise
  58. Utility.console_log("Passed the test for \"https_request using global ca_store\"")
  59. # Check for connection using crt bundle with mbedtls dynamic resource enabled
  60. dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
  61. # check and log bin size
  62. binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
  63. bin_size = os.path.getsize(binary_file)
  64. ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024))
  65. # start test
  66. dut1.start_app()
  67. # only check if one connection is established
  68. Utility.console_log("Testing for \"https_request using crt bundle\" with mbedtls dynamic resource enabled")
  69. try:
  70. dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
  71. dut1.expect_all('Connection established...',
  72. 'Reading HTTP response...',
  73. 'HTTP/1.1 200 OK',
  74. re.compile('connection closed'))
  75. except Exception:
  76. Utility.console_log("Failed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
  77. raise
  78. Utility.console_log("Passed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
  79. if __name__ == '__main__':
  80. test_examples_protocol_https_request()