Переглянути джерело

Unit test: 405 and 401 are both valid responses for rejected PUT requests

405 Method Not Allowed ... if there is no file system at the embedded server OR if no auth file
for put has been provided (PUT will never be possible)

401: send an authentication request if there is an auth file (PUT would be possible in principle)
bel2125 2 роки тому
батько
коміт
6e0770d012
1 змінених файлів з 12 додано та 1 видалено
  1. 12 1
      unittest/public_server.c

+ 12 - 1
unittest/public_server.c

@@ -1842,10 +1842,21 @@ START_TEST(test_request_handlers)
 	client_ri = mg_get_response_info(client_conn);
 
 	ck_assert(client_ri != NULL);
+	/* Result must be an error code*/
+	ck_assert_int_gt(client_ri->status_code, 400);
+	ck_assert_int_lt(client_ri->status_code, 500);
+
 #if defined(NO_FILES)
+	/* In case there is no filesystem, PUT is not a valid method */
 	ck_assert_int_eq(client_ri->status_code, 405); /* method not allowed */
 #else
-	ck_assert_int_eq(client_ri->status_code, 401); /* not authorized */
+	/* In case there is a filesystem but no auth file is provided,
+	 * PUT is not a valid method */
+	if (client_ri->status_code != 405) {
+		/* 401: It would be possible in principle, but there client needs
+		 * to send authentication data */
+		ck_assert_int_eq(client_ri->status_code, 401); /* not authorized */
+	}
 #endif
 	mg_close_connection(client_conn);