blob: da0f72c1495847706239d3ab59f9a6a31fc1ad78 [file] [log] [blame]
Ed Tanous88a03c52022-03-14 10:16:07 -07001#include "http_request.hpp"
2#include "routing.hpp"
3
4#include "gmock/gmock.h"
5#include "gtest/gtest.h"
6
7TEST(Router, AllowHeader)
8{
9 // Callback handler that does nothing
10 auto nullCallback = [](const crow::Request&,
11 const std::shared_ptr<bmcweb::AsyncResp>&) {};
12
13 crow::Router router;
14 std::error_code ec;
15
16 constexpr const std::string_view url = "/foo";
17
18 crow::Request req{{boost::beast::http::verb::get, url, 11}, ec};
19
20 // No route should return no methods.
21 router.validate();
22 EXPECT_EQ(router.buildAllowHeader(req), "");
23
24 router
25 .newRuleTagged<crow::black_magic::getParameterTag(url)>(
26 std::string(url))
27 .methods(boost::beast::http::verb::get)(nullCallback);
28 router.validate();
29 EXPECT_EQ(router.buildAllowHeader(req), "GET");
30
31 router
32 .newRuleTagged<crow::black_magic::getParameterTag(url)>(
33 std::string(url))
34 .methods(boost::beast::http::verb::patch)(nullCallback);
35 router.validate();
36 EXPECT_EQ(router.buildAllowHeader(req), "GET, PATCH");
37}