1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 | // Copyright (C) 2017-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <cc/data.h>
#include <dhcp/testutils/iface_mgr_test_config.h>
#include <dhcpsrv/cfg_shared_networks.h>
#include <dhcpsrv/shared_network.h>
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <gtest/gtest.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace isc;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
namespace {
// This is a basic test verifying that all shared networks are correctly
// parsed.
TEST(SharedNetworkListParserTest, parse) {
IfaceMgrTestConfig ifmgr(true);
// Basic configuration with array of shared networks.
std::string config = "["
" {"
" \"name\": \"bird\","
" \"interface\": \"eth0\""
" },"
" {"
" \"name\": \"monkey\","
" \"interface\": \"eth1\","
" \"user-context\": { \"comment\": \"example\" }"
" }"
"]";
ElementPtr config_element = Element::fromJSON(config);
SharedNetworks4ListParser parser;
CfgSharedNetworks4Ptr cfg(new CfgSharedNetworks4());
ASSERT_NO_THROW(parser.parse(cfg, config_element));
SharedNetwork4Ptr network1 = cfg->getByName("bird");
ASSERT_TRUE(network1);
EXPECT_EQ("bird", network1->getName());
EXPECT_EQ("eth0", network1->getIface().get());
EXPECT_FALSE(network1->getContext());
SharedNetwork4Ptr network2 = cfg->getByName("monkey");
ASSERT_TRUE(network2);
EXPECT_EQ("monkey", network2->getName());
EXPECT_EQ("eth1", network2->getIface().get());
ASSERT_TRUE(network2->getContext());
EXPECT_EQ(1, network2->getContext()->size());
EXPECT_TRUE(network2->getContext()->get("comment"));
}
// This test verifies that specifying two networks with the same name
// yields an error.
TEST(SharedNetworkListParserTest, duplicatedName) {<--- syntax error
IfaceMgrTestConfig ifmgr(true);
// Basic configuration with two networks having the same name.
std::string config = "["
" {"
" \"name\": \"bird\","
" \"interface\": \"eth0\""
" },"
" {"
" \"name\": \"bird\","
" \"interface\": \"eth1\""
" }"
"]";
ElementPtr config_element = Element::fromJSON(config);
SharedNetworks4ListParser parser;
CfgSharedNetworks4Ptr cfg(new CfgSharedNetworks4());
EXPECT_THROW(parser.parse(cfg, config_element), DhcpConfigError);
}
// This test verifies that the optional interface check works as expected.
TEST(SharedNetworkListParserTest, iface) {
// Basic configuration with a shared network.
std::string config = "["
" {"
" \"name\": \"bird\","
" \"interface\": \"eth1961\""
" }"
"]";
ElementPtr config_element = Element::fromJSON(config);
// The interface check can be disabled.
SharedNetworks6ListParser parser_no_check(false);
CfgSharedNetworks6Ptr cfg(new CfgSharedNetworks6());
EXPECT_NO_THROW(parser_no_check.parse(cfg, config_element));
cfg.reset(new CfgSharedNetworks6());
// Retry with the interface check enabled.
SharedNetworks6ListParser parser;
EXPECT_THROW(parser.parse(cfg, config_element), DhcpConfigError);
cfg.reset(new CfgSharedNetworks6());
// Configure default test interfaces.
IfaceMgrTestConfig ifmgr(true);
EXPECT_NO_THROW(parser_no_check.parse(cfg, config_element));
cfg.reset(new CfgSharedNetworks6());
EXPECT_NO_THROW(parser.parse(cfg, config_element));
}
} // end of anonymous namespace
|