Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Ed Tanous | 1fccd0d | 2024-03-19 09:16:16 -0700 | [diff] [blame] | 3 | #include "http/parsing.hpp" |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace |
| 8 | { |
| 9 | |
| 10 | TEST(HttpParsing, isJsonContentType) |
| 11 | { |
| 12 | EXPECT_TRUE(isJsonContentType("application/json")); |
| 13 | |
| 14 | // The Redfish specification DSP0266 shows no space between the ; and |
| 15 | // charset. |
| 16 | EXPECT_TRUE(isJsonContentType("application/json;charset=utf-8")); |
Ed Tanous | e4628c8 | 2024-12-16 10:57:04 -0800 | [diff] [blame] | 17 | EXPECT_TRUE(isJsonContentType("application/json;charset=ascii")); |
Ed Tanous | 1fccd0d | 2024-03-19 09:16:16 -0700 | [diff] [blame] | 18 | |
| 19 | // Sites like mozilla show the space included [1] |
| 20 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type |
| 21 | EXPECT_TRUE(isJsonContentType("application/json; charset=utf-8")); |
| 22 | |
| 23 | EXPECT_TRUE(isJsonContentType("APPLICATION/JSON")); |
| 24 | EXPECT_TRUE(isJsonContentType("APPLICATION/JSON; CHARSET=UTF-8")); |
| 25 | EXPECT_TRUE(isJsonContentType("APPLICATION/JSON;CHARSET=UTF-8")); |
| 26 | |
| 27 | EXPECT_FALSE(isJsonContentType("application/xml")); |
| 28 | EXPECT_FALSE(isJsonContentType("")); |
| 29 | EXPECT_FALSE(isJsonContentType(";")); |
| 30 | EXPECT_FALSE(isJsonContentType("application/json;")); |
| 31 | EXPECT_FALSE(isJsonContentType("application/json; ")); |
Ed Tanous | 1fccd0d | 2024-03-19 09:16:16 -0700 | [diff] [blame] | 32 | EXPECT_FALSE(isJsonContentType("json")); |
| 33 | } |
| 34 | } // namespace |