| 
									
										
										
										
											2017-10-10 10:48:57 +08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2021-01-08 16:56:28 +05:30
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 11:58:07 +08:00
										 |  |  | import ttfw_idf | 
					
						
							| 
									
										
										
										
											2021-01-08 16:56:28 +05:30
										 |  |  | from tiny_test_fw import Utility | 
					
						
							| 
									
										
										
										
											2017-10-10 10:48:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  | @ttfw_idf.idf_example_test(env_tag='Example_EthKitV1') | 
					
						
							| 
									
										
										
										
											2017-10-10 10:48:57 +08:00
										 |  |  | def test_examples_protocol_https_request(env, extra_data): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     steps: | | 
					
						
							|  |  |  |       1. join AP | 
					
						
							| 
									
										
										
										
											2021-01-08 16:56:28 +05:30
										 |  |  |       2. establish TLS connection to www.howsmyssl.com:443 with multiple | 
					
						
							|  |  |  |          certificate verification options | 
					
						
							| 
									
										
										
										
											2017-10-10 10:48:57 +08:00
										 |  |  |       3. send http request | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT) | 
					
						
							| 
									
										
										
										
											2017-11-11 15:17:00 +08:00
										 |  |  |     # check and log bin size | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin') | 
					
						
							| 
									
										
										
										
											2017-11-11 15:17:00 +08:00
										 |  |  |     bin_size = os.path.getsize(binary_file) | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024)) | 
					
						
							| 
									
										
										
										
											2021-01-08 16:56:28 +05:30
										 |  |  |     # start tes | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     Utility.console_log('Starting https_request simple test app') | 
					
						
							| 
									
										
										
										
											2017-10-10 10:48:57 +08:00
										 |  |  |     dut1.start_app() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 16:56:28 +05:30
										 |  |  |     # Check for connection using crt bundle | 
					
						
							|  |  |  |     Utility.console_log("Testing for \"https_request using crt bundle\"") | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08: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 16:56:28 +05:30
										 |  |  |     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-26 10:49:01 +08: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 16:56:28 +05:30
										 |  |  |     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-26 10:49:01 +08: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 16:56:28 +05:30
										 |  |  |     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-02 09:06:09 +05:30
										 |  |  |     # 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 16:56:28 +05:30
										 |  |  |     # Check for connection using crt bundle with mbedtls dynamic resource enabled | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn') | 
					
						
							| 
									
										
										
										
											2020-04-10 16:33:54 +08:00
										 |  |  |     # check and log bin size | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin') | 
					
						
							| 
									
										
										
										
											2020-04-10 16:33:54 +08:00
										 |  |  |     bin_size = os.path.getsize(binary_file) | 
					
						
							| 
									
										
										
										
											2021-01-26 10:49:01 +08:00
										 |  |  |     ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024)) | 
					
						
							| 
									
										
										
										
											2020-04-10 16:33:54 +08:00
										 |  |  |     # start test | 
					
						
							|  |  |  |     dut1.start_app() | 
					
						
							| 
									
										
										
										
											2021-01-08 16:56:28 +05:30
										 |  |  |     # 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-26 10:49:01 +08: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 16:56:28 +05:30
										 |  |  |     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 16:33:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 10:48:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     test_examples_protocol_https_request() |