xref: /openbmc/bmcweb/test/http/parsing_test.cpp (revision 1fccd0d5)
1 #include "http/parsing.hpp"
2 
3 #include <gtest/gtest.h>
4 
5 namespace
6 {
7 
TEST(HttpParsing,isJsonContentType)8 TEST(HttpParsing, isJsonContentType)
9 {
10     EXPECT_TRUE(isJsonContentType("application/json"));
11 
12     // The Redfish specification DSP0266 shows no space between the ; and
13     // charset.
14     EXPECT_TRUE(isJsonContentType("application/json;charset=utf-8"));
15 
16     // Sites like mozilla show the space included [1]
17     //  https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
18     EXPECT_TRUE(isJsonContentType("application/json; charset=utf-8"));
19 
20     EXPECT_TRUE(isJsonContentType("APPLICATION/JSON"));
21     EXPECT_TRUE(isJsonContentType("APPLICATION/JSON; CHARSET=UTF-8"));
22     EXPECT_TRUE(isJsonContentType("APPLICATION/JSON;CHARSET=UTF-8"));
23 
24     EXPECT_FALSE(isJsonContentType("application/xml"));
25     EXPECT_FALSE(isJsonContentType(""));
26     EXPECT_FALSE(isJsonContentType(";"));
27     EXPECT_FALSE(isJsonContentType("application/json;"));
28     EXPECT_FALSE(isJsonContentType("application/json; "));
29     EXPECT_FALSE(isJsonContentType("application/json; charset=ascii"));
30     EXPECT_FALSE(isJsonContentType("json"));
31 }
32 } // namespace
33