]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/test/http/rfc7230.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // Test that header file is self-contained.
9 #include <beast/http/rfc7230.hpp>
11 #include <beast/http/detail/rfc7230.hpp>
12 #include <beast/unit_test/suite.hpp>
16 #include <beast/core/detail/empty_base_optimization.hpp>
21 class rfc7230_test
: public beast::unit_test::suite
26 fmt(std::string
const& s
)
28 return '\'' + s
+ '\'';
33 str(boost::string_ref
const& s
)
35 return std::string(s
.data(), s
.size());
40 str(param_list
const& c
)
43 for(auto const& p
: c
)
46 s
.append(str(p
.first
));
47 if(! p
.second
.empty())
50 s
.append(str(p
.second
));
60 [&](std::string
const& s
)
62 auto const got
= str(param_list
{s
});
63 BEAST_EXPECTS(got
== s
, fmt(got
));
66 [&](std::string
const& s
, std::string
const& good
)
69 auto const got
= str(param_list
{s
});
71 BEAST_EXPECTS(got
== good
, fmt(got
));
74 [&](std::string
const& s
, std::string
const& good
)
76 auto const got
= str(param_list
{s
});
77 BEAST_EXPECTS(got
== good
, fmt(got
));
86 cs(" ;\t i =\t 1 \t", ";i=1");
87 cq("\t; \t xyz=1 ; ijk=\"q\\\"t\"", ";xyz=1;ijk=q\"t");
97 cq(";xy=\"\\\x01\"", "");
102 str(ext_list
const& ex
)
105 for(auto const& e
: ex
)
109 s
.append(str(e
.first
));
119 [&](std::string
const& s
)
121 auto const got
= str(ext_list
{s
});
122 BEAST_EXPECTS(got
== s
, fmt(got
));
125 [&](std::string
const& s
, std::string
const& good
)
128 auto const got
= str(ext_list
{s
});
130 BEAST_EXPECTS(got
== good
, fmt(got
));
133 [&](std::string
const& s
, std::string
const& good
)
135 auto const got
= str(ext_list
{s
});
136 BEAST_EXPECTS(got
== good
, fmt(got
));
139 ext-basic_parsed_list = *( "," OWS ) ext *( OWS "," [ OWS ext ] )
140 ext = token param-basic_parsed_list
141 param-basic_parsed_list = *( OWS ";" OWS param )
142 param = token OWS "=" OWS ( token / quoted-string )
153 cs(" , \t,, \t,", "");
154 cs( "permessage-deflate; client_no_context_takeover; client_max_window_bits",
155 "permessage-deflate;client_no_context_takeover;client_max_window_bits");
161 cs("\t a, b\t , c\t", "a,b,c");
165 cs("a; \t i\t=\t \t1\t ", "a;i=1");
167 ce("a;i=1;j=2;k=3,b;i=4;j=5;k=6");
169 cq("ab;x=\" \"", "ab;x= ");
170 cq("ab;x=\"\\\"\"", "ab;x=\"");
172 BEAST_EXPECT(ext_list
{"a,b;i=1,c;j=2;k=3"}.exists("A"));
173 BEAST_EXPECT(ext_list
{"a,b;i=1,c;j=2;k=3"}.exists("b"));
174 BEAST_EXPECT(! ext_list
{"a,b;i=1,c;j=2;k=3"}.exists("d"));
183 str(token_list
const& c
)
187 for(auto const& p
: c
)
201 [&](std::string
const& s
)
203 auto const got
= str(token_list
{s
});
204 BEAST_EXPECTS(got
== s
, fmt(got
));
207 [&](std::string
const& s
, std::string
const& good
)
210 auto const got
= str(token_list
{s
});
212 BEAST_EXPECTS(got
== good
, fmt(got
));
228 cs(" \t x \t ", "x");
230 cs("x ,\ty ", "x,y");
231 cs("x, y, z", "x,y,z");
233 BEAST_EXPECT(token_list
{"a,b,c"}.exists("A"));
234 BEAST_EXPECT(token_list
{"a,b,c"}.exists("b"));
235 BEAST_EXPECT(! token_list
{"a,b,c"}.exists("d"));
241 template<class Policy
>
243 std::vector
<std::string
>
244 to_vector(boost::string_ref
const& in
)
246 std::vector
<std::string
> v
;
247 detail::basic_parsed_list
<Policy
> list
{in
};
249 detail::basic_parsed_list
<Policy
>{in
})
250 v
.emplace_back(s
.data(), s
.size());
254 template<class Policy
>
256 validate(boost::string_ref
const& in
,
257 std::vector
<std::string
> const& v
)
259 BEAST_EXPECT(to_vector
<Policy
>(in
) == v
);
262 template<class Policy
>
264 good(boost::string_ref
const& in
)
266 BEAST_EXPECT(validate_list(
267 detail::basic_parsed_list
<Policy
>{in
}));
270 template<class Policy
>
272 good(boost::string_ref
const& in
,
273 std::vector
<std::string
> const& v
)
275 BEAST_EXPECT(validate_list(
276 detail::basic_parsed_list
<Policy
>{in
}));
277 validate
<Policy
>(in
, v
);
280 template<class Policy
>
282 bad(boost::string_ref
const& in
)
284 BEAST_EXPECT(! validate_list(
285 detail::basic_parsed_list
<Policy
>{in
}));
292 #token = [ ( "," / token ) *( OWS "," [ OWS token ] ) ]
294 using type
= detail::opt_token_list_policy
;
298 good
<type
>("\t", {});
299 good
<type
>(" \t", {});
301 good
<type
>(",,", {});
302 good
<type
>(", ,", {});
303 good
<type
>(",\t,", {});
304 good
<type
>(", \t,", {});
305 good
<type
>(", \t, ", {});
306 good
<type
>(", \t,\t", {});
307 good
<type
>(", \t, \t", {});
309 good
<type
>("x", {"x"});
310 good
<type
>(" x", {"x"});
311 good
<type
>("x,,", {"x"});
312 good
<type
>("x, ,", {"x"});
313 good
<type
>("x,, ", {"x"});
314 good
<type
>("x,,,", {"x"});
316 good
<type
>("x,y", {"x","y"});
317 good
<type
>("x ,y", {"x","y"});
318 good
<type
>("x\t,y", {"x","y"});
319 good
<type
>("x \t,y", {"x","y"});
320 good
<type
>(" x,y", {"x","y"});
321 good
<type
>(" x,y ", {"x","y"});
322 good
<type
>(",x,y", {"x","y"});
323 good
<type
>("x,y,", {"x","y"});
324 good
<type
>(",,x,y", {"x","y"});
325 good
<type
>(",x,,y", {"x","y"});
326 good
<type
>(",x,y,", {"x","y"});
327 good
<type
>("x ,, y", {"x","y"});
328 good
<type
>("x , ,y", {"x","y"});
330 good
<type
>("x,y,z", {"x","y","z"});
354 BEAST_DEFINE_TESTSUITE(rfc7230
,http
,beast
);