Parcourir la source

Add unit tests for SSL redirects

bel il y a 10 ans
Parent
commit
3b12b43da4
2 fichiers modifiés avec 47 ajouts et 3 suppressions
  1. 3 2
      .travis.yml
  2. 44 1
      test/public.c

+ 3 - 2
.travis.yml

@@ -32,6 +32,8 @@ addons:
   apt:
     packages:
       - cmake
+      - openssl
+      - libssl-dev
     sources:
       - kubuntu-backports
 
@@ -48,8 +50,7 @@ install:
 before_script:
   # Generate the build scripts with CMake
   - pwd
-  - ldd crypto
-  - ldd ssl
+  - ls -l
   - mkdir output
   - cd output
   - cmake --version

+ 44 - 1
test/public.c

@@ -535,6 +535,7 @@ START_TEST(test_request_handlers)
 	short ipv4r_port = 8194;
 	short ipv6_port = 8086;
 	short ipv6s_port = 8096;
+	short ipv6r_port = 8196;
 #elif !defined(USE_IPV6) && !defined(NO_SSL)
 	const char *HTTP_PORT = "8084,8194r,8094s";
 	short ipv4_port = 8084;
@@ -639,7 +640,7 @@ START_TEST(test_request_handlers)
 
 
 #if defined(USE_IPV6)
-	/* Get data from callback using [::1] */
+	/* Get data from callback using http://[::1] */
 	conn =
 	    mg_download("[::1]", ipv6_port, 0, ebuf, sizeof(ebuf), "%s", request);
 	ck_assert(conn != NULL);
@@ -654,6 +655,7 @@ START_TEST(test_request_handlers)
 	mg_close_connection(conn);
 #endif
 
+
 #if !defined(NO_SSL)
 	/* Get data from callback using https://127.0.0.1 */
 	conn = mg_download(
@@ -668,6 +670,47 @@ START_TEST(test_request_handlers)
 	buf[i] = 0;
 	ck_assert_str_eq(buf, expected);
 	mg_close_connection(conn);
+
+	/* Get redirect from callback using http://127.0.0.1 */
+	conn = mg_download(
+	    "127.0.0.1", ipv4r_port, 0, ebuf, sizeof(ebuf), "%s", request);
+	ck_assert(conn != NULL);
+	ri = mg_get_request_info(conn);
+
+	ck_assert(ri != NULL);
+	ck_assert_str_eq(ri->uri, "302");
+	i = mg_read(conn, buf, sizeof(buf));
+	ck_assert_int_eq(i, -1);
+	mg_close_connection(conn);
+#endif
+
+
+#if defined(USE_IPV6) && !defined(NO_SSL)
+	/* Get data from callback using https://[::1] */
+	conn =
+	    mg_download("[::1]", ipv6s_port, 1, ebuf, sizeof(ebuf), "%s", request);
+	ck_assert(conn != NULL);
+	ri = mg_get_request_info(conn);
+
+	ck_assert(ri != NULL);
+	ck_assert_str_eq(ri->uri, "200");
+	i = mg_read(conn, buf, sizeof(buf));
+	ck_assert_int_eq(i, strlen(expected));
+	buf[i] = 0;
+	ck_assert_str_eq(buf, expected);
+	mg_close_connection(conn);
+
+	/* Get redirect from callback using http://127.0.0.1 */
+	conn =
+	    mg_download("[::1]", ipv6r_port, 0, ebuf, sizeof(ebuf), "%s", request);
+	ck_assert(conn != NULL);
+	ri = mg_get_request_info(conn);
+
+	ck_assert(ri != NULL);
+	ck_assert_str_eq(ri->uri, "302");
+	i = mg_read(conn, buf, sizeof(buf));
+	ck_assert_int_eq(i, -1);
+	mg_close_connection(conn);
 #endif