57 throw Exception(
"expected that buffer would begin with " + prefix);
58 buf.
advance(prefix.length() + 1);
64 throw Exception(
"expected that buffer would end with push-continuation 1");
67 else if (pc_mode ==
PC_2)
70 throw Exception(
"expected that buffer would end with push-continuation 2");
81 if (index == size - 1)
88 static const std::string rchrs =
"012abcABC,\"\\";
93 for (
int i = 0; i < len; ++i)
94 ret += rchrs[prng.
randrange32(
static_cast<uint32_t
>(rchrs.size()))];
103 for (
int i = 0; i < len; ++i)
110 static const int sizes[3] = {10, 100, 1000};
115 for (
int i = 0; i < len; ++i)
136 for (
size_t i = 0; i < frag.size(); ++i)
142 for (
size_t i = 0; i < frag.size(); ++i)
145 cc.
add(cli_opt,
nullptr);
147 ASSERT_EQ(cc.
complete(), i == frag.size() - 1);
151 std::erase_if(cc, [](
const Option &o)
152 {
return !o.
empty() && o.
ref(0) ==
"push-continuation"; });
165 buf_append_string(buf, prefix +
",route-gateway 10.213.0.1,ifconfig 10.213.0.48 255.255.0.0,ifconfig-ipv6 fdab::48/64 fdab::1,client-ip 192.168.4.1,ping 1,ping-restart 8,reneg-sec 60,cipher AES-128-GCM,compress stub-v2,peer-id 4,topology subnet,explicit-exit-notify");
169 for (
int i = 0; i < 1000; ++i)
187 ASSERT_EQ(frag.size(), 15);
195 for (
const auto &e : opt)
210 for (
int i = 0; i < n; ++i)
217TEST(Continuation, TestRandomPushReply)
222TEST(Continuation, TestRandomPushUpdate)
227TEST(Continuation, TestFragmentPushReply)
232TEST(Continuation, TestFragmentPushUpdate)
237TEST(Continuation, PushUpdateAdd)
242 cc.
add(orig_opts,
nullptr);
248 cc.
add(update,
nullptr,
true);
251 ASSERT_EQ(cc.size(), 5);
254TEST(Continuation, PushUpdateAddUnsupported)
259 cc.
add(orig_opts,
nullptr);
265 JY_EXPECT_THROW(cc.
add(update,
nullptr,
true), OptionListContinuation::push_update_unsupported_option,
"my_unsupported_option");
269 cc.
add(update,
nullptr,
true);
272 ASSERT_EQ(cc.size(), 5);
275TEST(Continuation, PushUpdateRemove)
280 JY_EXPECT_THROW(cc.
add(update,
nullptr,
true), OptionListContinuation::push_update_unsupported_option,
"my_unsupported_option");
285 cc.
add(update,
nullptr,
true);
290TEST(Continuation, PushUpdateAddMultiple)
296 cc.
add(orig_opts,
nullptr);
303 cc.
add(update,
nullptr,
true);
307 cc.
add(update,
nullptr,
true);
311 ASSERT_TRUE(cc.
exists(
"f"));
312 ASSERT_FALSE(cc.
exists(
"dns"));
313 ASSERT_FALSE(cc.
exists(
"ifconfig"));
314 ASSERT_TRUE(cc.
exists(
"bla"));
317 ASSERT_EQ(idx->size(), 4);
319 ASSERT_EQ(cc.size(), 10);
size_t size() const
Returns the size of the buffer in T objects.
void advance(const size_t delta)
Advances the buffer by the specified delta.
void set_size(const size_t size)
After an external method, operating on the array as a mutable unsigned char buffer,...
void reset_completion()
Resets completion flag. Intended to use by PUSH_UPDATE.
void finalize(const PushOptionsMerger::Ptr merger)
void add(const OptionList &other, OptionList::FilterBase *filt, bool push_update=false)
const IndexList * get_index_ptr(const std::string &name) const
static OptionList parse_from_csv_static(const std::string &str, Limits *lim)
void parse_from_csv(const std::string &str, Limits *lim)
static OptionList parse_from_csv_static_nomap(const std::string &str, Limits *lim)
std::string render_csv() const
std::string render(const unsigned int flags) const
bool exists(const std::string &name) const
const std::string & ref(const size_t i) const
static BufferPtr defragment(const std::vector< BufferPtr > &bv, const std::string &prefix)
static constexpr size_t FRAGMENT_SIZE
Abstract base class for random number generators.
std::uint32_t randrange32(const std::uint32_t end)
Return a uniformly distributed random number in the range [0, end)
#define OPENVPN_LOG(args)
constexpr BufferFlags GROW(1U<< 2)
if enabled, buffer will grow (otherwise buffer_full exception will be thrown)
void buf_append_string(Buffer &buf, const std::string &str)
std::string buf_to_string(const Buffer &buf)
static void test_roundtrip(const OptionList &opt_orig, const std::string &prefix)
static std::string get_csv_from_frag(Buffer buf, const size_t index, const size_t size, const std::string &prefix)
static std::string get_csv(Buffer buf, const PCMode pc_mode, const std::string &prefix)
static Option random_opt(RandomAPI &prng)
static void test_prefix_fragment(const std::string &prefix)
TEST(Continuation, TestRandomPushReply)
static void require_equal(const OptionList &opt1, const OptionList &opt2, const std::string &title)
static OptionList random_optionlist(RandomAPI &prng)
static std::string random_term(RandomAPI &prng)
static void test_prefix_random(const std::string &prefix)