Added test to check set_file_content(), SEGFAULT with SSL enabled

This commit is contained in:
Paul Harris 2024-09-09 12:08:58 +08:00
parent f35aff84c2
commit 48dbd7bda6

View File

@ -2300,6 +2300,14 @@ protected:
[&](const Request & /*req*/, Response &res) {
res.set_content("Hello World!", "text/plain");
})
.Get("/file_content_dir_no_slash",
[&](const Request & /*req*/, Response &res) {
res.set_file_content("./www/dir");
})
.Get("/file_content_dir_with_slash/",
[&](const Request & /*req*/, Response &res) {
res.set_file_content("./www/dir/");
})
.Get("/file_content",
[&](const Request & /*req*/, Response &res) {
res.set_file_content("./www/dir/test.html");
@ -2916,7 +2924,7 @@ TEST_F(ServerTest, GetMethod200) {
EXPECT_EQ("Hello World!", res->body);
}
TEST_F(ServerTest, GetFileContent) {
TEST_F(ServerTest, GetFileContent_File) {
auto res = cli_.Get("/file_content");
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
@ -2925,6 +2933,24 @@ TEST_F(ServerTest, GetFileContent) {
EXPECT_EQ("test.html", res->body);
}
TEST_F(ServerTest, GetFileContent_DirNoSlash) {
auto res = cli_.Get("/file_content_dir_no_slash");
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ("text/html", res->get_header_value("Content-Type"));
EXPECT_EQ(9, std::stoi(res->get_header_value("Content-Length")));
EXPECT_EQ("index.html", res->body);
}
TEST_F(ServerTest, GetFileContent_DirWithSlash) {
auto res = cli_.Get("/file_content_dir_with_slash/");
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ("text/html", res->get_header_value("Content-Type"));
EXPECT_EQ(9, std::stoi(res->get_header_value("Content-Length")));
EXPECT_EQ("index.html", res->body);
}
TEST_F(ServerTest, GetFileContentWithContentType) {
auto res = cli_.Get("/file_content_with_content_type");
ASSERT_TRUE(res);