mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix device/test_http_client tests (#5309)
* update HTTPClient API usage skip the second POST as end() has different semantics and nulls the client pointer use bearssl in ssl tests add delay in python side when shutting down http web server so MacOS does not complain about address already in use * fix crash if GET/POST was called after end() without a new begin() update double POST test to insure no crash if POST called after end() test now are for both AxTLS and BearSSL * fix small comment typo
This commit is contained in:
parent
feb86cd4ff
commit
a42c3c399b
@ -1036,7 +1036,7 @@ bool HTTPClient::connect(void)
|
||||
}
|
||||
|
||||
#ifdef HTTPCLIENT_1_1_COMPATIBLE
|
||||
if(!_client) {
|
||||
if(!_client && _transportTraits) {
|
||||
_tcpDeprecated = _transportTraits->create();
|
||||
_client = _tcpDeprecated.get();
|
||||
}
|
||||
|
@ -24,8 +24,9 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
|
||||
{
|
||||
{
|
||||
// small request
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(getenv("SERVER_IP"), 8088, "/");
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/");
|
||||
auto httpCode = http.GET();
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
String payload = http.getString();
|
||||
@ -33,8 +34,9 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
|
||||
}
|
||||
{
|
||||
// request which returns 8000 bytes
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(getenv("SERVER_IP"), 8088, "/data?size=8000");
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/data?size=8000");
|
||||
auto httpCode = http.GET();
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
String payload = http.getString();
|
||||
@ -48,8 +50,9 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
|
||||
}
|
||||
{
|
||||
// can do two POST requests with one HTTPClient object (#1902)
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
http.begin(getenv("SERVER_IP"), 8088, "/");
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/");
|
||||
http.addHeader("Content-Type", "text/plain");
|
||||
auto httpCode = http.POST("foo");
|
||||
Serial.println(httpCode);
|
||||
@ -57,7 +60,8 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
|
||||
http.end();
|
||||
|
||||
httpCode = http.POST("bar");
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
// its not expected to work but should not crash
|
||||
REQUIRE(httpCode == HTTPC_ERROR_CONNECTION_REFUSED);
|
||||
http.end();
|
||||
}
|
||||
}
|
||||
@ -65,10 +69,15 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
|
||||
|
||||
TEST_CASE("HTTPS GET request", "[HTTPClient]")
|
||||
{
|
||||
//
|
||||
// Tests with BearSSL
|
||||
//
|
||||
{
|
||||
// small request
|
||||
BearSSL::WiFiClientSecure client;
|
||||
client.setFingerprint(fp);
|
||||
HTTPClient http;
|
||||
http.begin(getenv("SERVER_IP"), 8088, "/", fp);
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/", fp);
|
||||
auto httpCode = http.GET();
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
String payload = http.getString();
|
||||
@ -76,8 +85,39 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
|
||||
}
|
||||
{
|
||||
// request which returns 4000 bytes
|
||||
BearSSL::WiFiClientSecure client;
|
||||
client.setFingerprint(fp);
|
||||
HTTPClient http;
|
||||
http.begin(getenv("SERVER_IP"), 8088, "/data?size=4000", fp);
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/data?size=4000", fp);
|
||||
auto httpCode = http.GET();
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
String payload = http.getString();
|
||||
auto len = payload.length();
|
||||
REQUIRE(len == 4000);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (payload[i] != 'a') {
|
||||
REQUIRE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// Same tests with axTLS
|
||||
//
|
||||
{
|
||||
// small request
|
||||
axTLS::WiFiClientSecure client;
|
||||
HTTPClient http;
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/", fp);
|
||||
auto httpCode = http.GET();
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
String payload = http.getString();
|
||||
REQUIRE(payload == "hello!!!");
|
||||
}
|
||||
{
|
||||
// request which returns 4000 bytes
|
||||
axTLS::WiFiClientSecure client;
|
||||
HTTPClient http;
|
||||
http.begin(client, getenv("SERVER_IP"), 8088, "/data?size=4000", fp);
|
||||
auto httpCode = http.GET();
|
||||
REQUIRE(httpCode == HTTP_CODE_OK);
|
||||
String payload = http.getString();
|
||||
@ -89,7 +129,6 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -4,6 +4,7 @@ from threading import Thread
|
||||
import urllib2
|
||||
import os
|
||||
import ssl
|
||||
import time
|
||||
|
||||
@setup('HTTP GET & POST requests')
|
||||
def setup_http_get(e):
|
||||
@ -34,6 +35,7 @@ def setup_http_get(e):
|
||||
def teardown_http_get(e):
|
||||
response = urllib2.urlopen('http://localhost:8088/shutdown')
|
||||
html = response.read()
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
@setup('HTTPS GET request')
|
||||
|
Loading…
x
Reference in New Issue
Block a user