Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HTTPClient-SSL
Dependents: mtsas mtsas mtsas mtsas_lat3
Test/TestHTTPS.h
- Committer:
- Vanger
- Date:
- 2015-03-11
- Revision:
- 35:c85bea9cb713
- Child:
- 36:b6e47b4cdb6d
File content as of revision 35:c85bea9cb713:
#ifndef TESTHTTPS_H
#define TESTHTTPS_H
#include "mtsas.h"
#include <string>
#include "httpbinCert.h"
using namespace mts;
class TestHTTPS : public TestCollection
{
public:
TestHTTPS();
virtual void run();
private:
MTSSerialFlowControl* io;
Cellular* radio;
HTTPClient* http;
char rbuf[1024];
HTTPMap* send;
HTTPText* receive;
};
TestHTTPS::TestHTTPS() : TestCollection("TestHTTPS") {}
void TestHTTPS::run() {
string url;
string secure_url = "https://httpbin.org:443";
string url_get = "/get";
string url_put = "/put";
string url_post = "/post";
string url_del = "/delete";
string url_stream = "/stream/20";
string url_auth = "/basic-auth/:user/:passwd";
MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
Test::start("Setup");
io = new MTSSerialFlowControl(D8, D2, D3, D6);
io->baud(115200);
radio = CellularFactory::create(io);
if (! radio) {
Test::assertTrue(false);
}
radio->configureSignals(D4, D7, RESET);
Transport::setTransport(radio);
http = new HTTPClient();
send = new HTTPMap();
receive = new HTTPText(rbuf);
for (int i = 0; i < 10; i++) {
if (i >= 10) {
Test::assertTrue(false);
}
if (radio->setApn(APN) == MTS_SUCCESS) {
break;
} else {
wait(1);
}
}
for (int i = 0; i < 3; i++) {
if (i >= 3) {
Test::assertTrue(false);
}
if (radio->connect()) {
break;
} else {
wait(1);
}
}
for (int i = 0; i < 5; i++) {
if (i >= 5) {
Test::assertTrue(false);
}
if (radio->ping()) {
break;
} else {
wait(1);
}
}
if (http->addRootCACertificate(CERTIFICATE) == HTTP_OK) {
Test::assertTrue(false);
}
Test::end();
url = secure_url + url_get;
Test::start("HTTPS GET");
Test::assertTrue(http->get(url.c_str(), receive, 10000) == HTTP_OK);
Test::end();
url = secure_url + url_put;
Test::start("HTTPS PUT");
send->put("testing", "put");
Test::assertTrue(http->put(url.c_str(), *send, receive, 10000) == HTTP_OK);
Test::end();
url = secure_url + url_post;
Test::start("HTTPS POST");
send->put("testing", "put");
Test::assertTrue(http->post(url.c_str(), *send, receive, 10000) == HTTP_OK);
Test::end();
url = secure_url + url_del;
Test::start("HTTPS DELETE");
Test::assertTrue(http->del(url.c_str(), receive, 10000) == HTTP_OK);
Test::end();
url = secure_url + url_stream;
char bigbuf[8 * 1024];
HTTPText big(bigbuf);
Test::start("HTTPS big GET");
Test::assertTrue(http->get(url.c_str(), &big, 10000) == HTTP_OK);
Test::end();
url = secure_url + url_auth;
const char user[] = "user",pw[] = "passwd";
Test::start("HTTPS basic AUTH");
Test::assertTrue(http->basicAuth(user,pw) == HTTP_OK);
Test::assertTrue(http->get(url.c_str(), receive, 10000) == HTTP_OK);
Test::assertTrue(http->basicAuth("","") == HTTP_OK);
Test::end();
radio->disconnect();
}
#endif