void TLSSOCKET_CONNECT_INVALID() { TLSSocket sock; TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance())); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert(tls_global::cert)); TEST_ASSERT(sock.connect(NULL, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS) < 0); TEST_ASSERT(sock.connect("", MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS) < 0); TEST_ASSERT(sock.connect("", 0) < 0); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT_TLS)); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); }
nsapi_error_t tlssocket_connect_to_srv(TLSSocket &sock, uint16_t port) { SocketAddress tls_addr; NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tls_addr); tls_addr.set_port(port); printf("MBED: Server '%s', port %d\n", tls_addr.get_ip_address(), tls_addr.get_port()); nsapi_error_t err = sock.set_root_ca_cert(tls_global::cert); if (err != NSAPI_ERROR_OK) { printf("Error from sock.set_root_ca_cert: %d\n", err); return err; } err = sock.open(NetworkInterface::get_default_instance()); if (err != NSAPI_ERROR_OK) { printf("Error from sock.open: %d\n", err); return err; } err = sock.connect(tls_addr); if (err != NSAPI_ERROR_OK) { printf("Error from sock.connect: %d\n", err); return err; } return NSAPI_ERROR_OK; }