Nan Zhou | dff2f9b | 2022-06-26 23:50:39 +0000 | [diff] [blame^] | 1 | #include "async_resp.hpp" |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 2 | #include "http_request.hpp" |
| 3 | #include "routing.hpp" |
Nan Zhou | dff2f9b | 2022-06-26 23:50:39 +0000 | [diff] [blame^] | 4 | #include "utility.hpp" |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 5 | |
Nan Zhou | dff2f9b | 2022-06-26 23:50:39 +0000 | [diff] [blame^] | 6 | #include <boost/beast/http/verb.hpp> |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <string_view> |
| 11 | #include <system_error> |
| 12 | |
| 13 | #include <gtest/gtest.h> |
Ed Tanous | 88a03c5 | 2022-03-14 10:16:07 -0700 | [diff] [blame] | 14 | |
| 15 | TEST(Router, AllowHeader) |
| 16 | { |
| 17 | // Callback handler that does nothing |
| 18 | auto nullCallback = [](const crow::Request&, |
| 19 | const std::shared_ptr<bmcweb::AsyncResp>&) {}; |
| 20 | |
| 21 | crow::Router router; |
| 22 | std::error_code ec; |
| 23 | |
| 24 | constexpr const std::string_view url = "/foo"; |
| 25 | |
| 26 | crow::Request req{{boost::beast::http::verb::get, url, 11}, ec}; |
| 27 | |
| 28 | // No route should return no methods. |
| 29 | router.validate(); |
| 30 | EXPECT_EQ(router.buildAllowHeader(req), ""); |
| 31 | |
| 32 | router |
| 33 | .newRuleTagged<crow::black_magic::getParameterTag(url)>( |
| 34 | std::string(url)) |
| 35 | .methods(boost::beast::http::verb::get)(nullCallback); |
| 36 | router.validate(); |
| 37 | EXPECT_EQ(router.buildAllowHeader(req), "GET"); |
| 38 | |
| 39 | router |
| 40 | .newRuleTagged<crow::black_magic::getParameterTag(url)>( |
| 41 | std::string(url)) |
| 42 | .methods(boost::beast::http::verb::patch)(nullCallback); |
| 43 | router.validate(); |
| 44 | EXPECT_EQ(router.buildAllowHeader(req), "GET, PATCH"); |
| 45 | } |