static const char *basic_auth_path = "/basic_auth";
static const char *digest_auth_path = "/digest_auth";
-static int run_server (guint * http_port, guint * https_port);
+static gboolean run_server (guint * http_port, guint * https_port);
static void stop_server (void);
static void
tc_internet = tcase_create ("internet");
suite_add_tcase (s, tc_chain);
- run_server (&http_port, &https_port);
- atexit (stop_server);
- tcase_add_test (tc_chain, test_first_buffer_has_offset);
- tcase_add_test (tc_chain, test_redirect_yes);
- tcase_add_test (tc_chain, test_redirect_no);
- tcase_add_test (tc_chain, test_not_found);
- tcase_add_test (tc_chain, test_forbidden);
- tcase_add_test (tc_chain, test_cookies);
- tcase_add_test (tc_chain, test_good_user_basic_auth);
- tcase_add_test (tc_chain, test_bad_user_basic_auth);
- tcase_add_test (tc_chain, test_bad_password_basic_auth);
- tcase_add_test (tc_chain, test_good_user_digest_auth);
- tcase_add_test (tc_chain, test_bad_user_digest_auth);
- tcase_add_test (tc_chain, test_bad_password_digest_auth);
- if (soup_ssl_supported)
- tcase_add_test (tc_chain, test_https);
+ if (run_server (&http_port, &https_port)) {
+ atexit (stop_server);
+ tcase_add_test (tc_chain, test_first_buffer_has_offset);
+ tcase_add_test (tc_chain, test_redirect_yes);
+ tcase_add_test (tc_chain, test_redirect_no);
+ tcase_add_test (tc_chain, test_not_found);
+ tcase_add_test (tc_chain, test_forbidden);
+ tcase_add_test (tc_chain, test_cookies);
+ tcase_add_test (tc_chain, test_good_user_basic_auth);
+ tcase_add_test (tc_chain, test_bad_user_basic_auth);
+ tcase_add_test (tc_chain, test_bad_password_basic_auth);
+ tcase_add_test (tc_chain, test_good_user_digest_auth);
+ tcase_add_test (tc_chain, test_bad_user_digest_auth);
+ tcase_add_test (tc_chain, test_bad_password_digest_auth);
+
+ if (soup_ssl_supported)
+ tcase_add_test (tc_chain, test_https);
+ } else {
+ g_print ("Skipping 12 souphttpsrc tests, couldn't start or connect to "
+ "local http server\n");
+ }
suite_add_tcase (s, tc_internet);
tcase_set_timeout (tc_internet, 250);
static SoupServer *server; /* NULL */
static SoupServer *ssl_server; /* NULL */
-int
+static gboolean
run_server (guint * http_port, guint * https_port)
{
guint port = SOUP_ADDRESS_ANY_PORT;
SoupAuthDomain *domain = NULL;
if (server_running)
- return 0;
+ return TRUE;
+
server_running = 1;
*http_port = *https_port = 0;
server = soup_server_new (SOUP_SERVER_PORT, port, NULL);
if (!server) {
GST_DEBUG ("Unable to bind to server port %u", port);
- return 1;
+ return FALSE;
}
*http_port = soup_server_get_port (server);
GST_INFO ("HTTP server listening on port %u", *http_port);
if (!ssl_server) {
GST_DEBUG ("Unable to bind to SSL server port %u", ssl_port);
- return 1;
+ stop_server ();
+ return FALSE;
}
*https_port = soup_server_get_port (ssl_server);
GST_INFO ("HTTPS server listening on port %u", *https_port);
soup_server_run_async (ssl_server);
}
- return 0;
+ /* check if we can connect to our local http server */
+ {
+ GSocketConnection *conn;
+ GSocketClient *client;
+
+ client = g_socket_client_new ();
+ g_socket_client_set_timeout (client, 2);
+ conn = g_socket_client_connect_to_host (client, "127.0.0.1", *http_port,
+ NULL, NULL);
+ if (conn == NULL) {
+ GST_INFO ("Couldn't connect to http server 127.0.0.1:%u", *http_port);
+ g_object_unref (client);
+ stop_server ();
+ return FALSE;
+ }
+ g_object_unref (conn);
+ conn = g_socket_client_connect_to_host (client, "127.0.0.1", *http_port,
+ NULL, NULL);
+ if (conn == NULL) {
+ GST_INFO ("Couldn't connect to https server 127.0.0.1:%u", *https_port);
+ g_object_unref (client);
+ stop_server ();
+ return FALSE;
+ }
+ g_object_unref (conn);
+ g_object_unref (client);
+ }
+
+ return TRUE;
}
static void