|
| 1 | +// OpenVPN -- An application to securely tunnel IP networks |
| 2 | +// over a single port, with support for SSL/TLS-based |
| 3 | +// session authentication and key exchange, |
| 4 | +// packet encryption, packet authentication, and |
| 5 | +// packet compression. |
| 6 | +// |
| 7 | +// Copyright (C) 2024- OpenVPN Inc. |
| 8 | +// |
| 9 | +// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception |
| 10 | +// |
| 11 | + |
| 12 | +#include "test_common.hpp" |
| 13 | +#include "test_generators.hpp" |
| 14 | + |
| 15 | +#include <set> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +#include <openvpn/addr/addrlist.hpp> |
| 19 | + |
| 20 | +RC_GTEST_PROP(AddrList, AddMarksAddressAsExisting, ()) |
| 21 | +{ |
| 22 | + openvpn::IP::AddrList address_list; |
| 23 | + const auto address = *rc::genIPAddr(); |
| 24 | + address_list.add(address); |
| 25 | + RC_ASSERT(address_list.exists(address)); |
| 26 | +} |
| 27 | + |
| 28 | +RC_GTEST_PROP(AddrList, AddIsIdempotent, ()) |
| 29 | +{ |
| 30 | + openvpn::IP::AddrList list; |
| 31 | + const auto addr = *rc::genIPAddr(); |
| 32 | + list.add(addr); |
| 33 | + list.add(addr); |
| 34 | + RC_ASSERT(list.size() == 1U); |
| 35 | + RC_ASSERT(list[0] == addr); |
| 36 | +} |
| 37 | + |
| 38 | +RC_GTEST_PROP(AddrList, AddDistinctAddressesKeepsUniqueCount, ()) |
| 39 | +{ |
| 40 | + const auto addrs = *rc::gen::container<std::vector<openvpn::IP::Addr>>(rc::genIPAddr()); |
| 41 | + const std::set unique_addrs(addrs.begin(), addrs.end()); |
| 42 | + openvpn::IP::AddrList list; |
| 43 | + for (const auto &addr : addrs) |
| 44 | + { |
| 45 | + list.add(addr); |
| 46 | + } |
| 47 | + RC_ASSERT(list.size() == unique_addrs.size()); |
| 48 | +} |
| 49 | + |
| 50 | +RC_GTEST_PROP(AddrList, ExistsMatchesMembership, ()) |
| 51 | +{ |
| 52 | + const auto addrs = *rc::gen::container<std::vector<openvpn::IP::Addr>>(rc::genIPAddr()); |
| 53 | + const std::set unique_addrs(addrs.begin(), addrs.end()); |
| 54 | + openvpn::IP::AddrList list; |
| 55 | + for (const auto &addr : addrs) |
| 56 | + { |
| 57 | + list.add(addr); |
| 58 | + } |
| 59 | + const auto probe = *rc::gen::oneOf(rc::gen::elementOf(unique_addrs), rc::genIPAddr()); |
| 60 | + const bool expected = unique_addrs.contains(probe); |
| 61 | + RC_ASSERT(list.exists(probe) == expected); |
| 62 | +} |
0 commit comments