Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device/test_http_client tests #5309

Merged
merged 5 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ bool HTTPClient::connect(void)
}

#ifdef HTTPCLIENT_1_1_COMPATIBLE
if(!_client) {
if(!_client && _transportTraits) {
_tcpDeprecated = _transportTraits->create();
_client = _tcpDeprecated.get();
}
Expand Down
53 changes: 46 additions & 7 deletions tests/device/test_http_client/test_http_client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ 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();
REQUIRE(payload == "hello!!!");
}
{
// 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();
Expand All @@ -48,36 +50,74 @@ 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);
REQUIRE(httpCode == HTTP_CODE_OK);
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();
}
}


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();
REQUIRE(payload == "hello!!!");
}
{
// 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();
Expand All @@ -89,7 +129,6 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
}
}
}

}

void loop()
Expand Down
2 changes: 2 additions & 0 deletions tests/device/test_http_client/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import urllib2
import os
import ssl
import time

@setup('HTTP GET & POST requests')
def setup_http_get(e):
Expand Down Expand Up @@ -34,6 +35,7 @@ def flaskThread():
def teardown_http_get(e):
response = urllib2.urlopen('http://localhost:8088/shutdown')
html = response.read()
time.sleep(30)


@setup('HTTPS GET request')
Expand Down