blob: f4c9e708f2fa6445682fca1b3892995bf0dd7af9 [file] [log] [blame]
Nan Zhoudff2f9b2022-06-26 23:50:39 +00001#include "async_resp.hpp"
Ed Tanous88a03c52022-03-14 10:16:07 -07002#include "http_request.hpp"
3#include "routing.hpp"
Nan Zhoudff2f9b2022-06-26 23:50:39 +00004#include "utility.hpp"
Ed Tanous88a03c52022-03-14 10:16:07 -07005
Nan Zhoudff2f9b2022-06-26 23:50:39 +00006#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 Tanous88a03c52022-03-14 10:16:07 -070014
15TEST(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}