1 /*
2 * Copyright (C) 2006-2021 Registro.br. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * 1. Redistribution of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY REGISTRO.BR ``AS IS AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIE OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 * EVENT SHALL REGISTRO.BR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
19 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
21 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
22 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23 * DAMAGE.
24 */
25 /* $Id$ */
26 #if USE_BR_ORG
27 #include <memory>
28 #include <string>
29
30 #include "libepp_nicbr.H"
31
32 #include "BrOrgUpdateTest.H"
33 #include "BrOrgUpdate.H"
34 #include "FileUtil.H"
35 #include "IoException.H"
36 #include "XmlException.H"
37
38 LIBEPP_NICBR_NS_USE
39
40 CPPUNIT_TEST_SUITE_REGISTRATION(BrOrgUpdateTest);
41
BrOrgUpdateTest()42 BrOrgUpdateTest::BrOrgUpdateTest() {}
43
~BrOrgUpdateTest()44 BrOrgUpdateTest::~BrOrgUpdateTest() {}
45
setUp()46 void BrOrgUpdateTest::setUp() {}
47
tearDown()48 void BrOrgUpdateTest::tearDown() {}
49
set_xml_template_test()50 void BrOrgUpdateTest::set_xml_template_test()
51 {
52 string to_be_parsed =
53 "<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
54 "<epp xmlns='urn:ietf:params:xml:ns:epp-1.0' "
55 "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
56 "xsi:schemaLocation='urn:ietf:params:xml:ns:epp-1.0 "
57 "epp-1.0.xsd'>"
58 "<command>"
59 "<update>"
60 "<contact:update "
61 "xmlns:contact='urn:ietf:params:xml:ns:contact-1.0' "
62 "xsi:schemaLocation='urn:ietf:params:xml:ns:contact-1.0 "
63 "contact-1.0.xsd'>"
64 "<contact:id>$(id)$</contact:id>"
65 "$(add)$"
66 "$(rem)$"
67 "$(chg)$"
68 "</contact:update>"
69 "</update>"
70 "<extension>"
71 "<brorg:update "
72 "xmlns:brorg='urn:ietf:params:xml:ns:brorg-1.0' "
73 "xsi:schemaLocation='urn:ietf:params:xml:ns:brorg-1.0 "
74 "brorg-1.0.xsd'>"
75 "<brorg:organization>$(organization)$</brorg:organization>"
76 "$(brorg_add)$"
77 "$(brorg_rem)$"
78 "$(brorg_chg)$"
79 "</brorg:update>"
80 "$(lacnicorg_ext)$"
81 "</extension>"
82 "$(clTRID)$"
83 "</command>"
84 "</epp>";
85
86 string expected =
87 "<?xml version='1.0' encoding='UTF-8' standalone='no'?>"
88 "<epp xmlns='urn:ietf:params:xml:ns:epp-1.0' "
89 "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
90 "xsi:schemaLocation='urn:ietf:params:xml:ns:epp-1.0 "
91 "epp-1.0.xsd'>"
92 "<command>"
93 "<update>"
94 "<contact:update "
95 "xmlns:contact='urn:ietf:params:xml:ns:contact-1.0' "
96 "xsi:schemaLocation='urn:ietf:params:xml:ns:contact-1.0 "
97 "contact-1.0.xsd'>"
98 "<contact:id>e654321</contact:id>"
99 "</contact:update>"
100 "</update>"
101 "<extension>"
102 "<brorg:update "
103 "xmlns:brorg='urn:ietf:params:xml:ns:brorg-1.0' "
104 "xsi:schemaLocation='urn:ietf:params:xml:ns:brorg-1.0 "
105 "brorg-1.0.xsd'>"
106 "<brorg:organization>"
107 "005.506.560/0001-36"
108 "</brorg:organization>"
109 "<brorg:add>"
110 "<brorg:contact type='admin'>hkk</brorg:contact>"
111 "</brorg:add>"
112 "<brorg:rem>"
113 "<brorg:contact type='admin'>fan</brorg:contact>"
114 "</brorg:rem>"
115 "<brorg:chg>"
116 "<brorg:responsible>Responsible Name</brorg:responsible>"
117 "<brorg:exDate>2009-02-01T12:00:00.0Z</brorg:exDate>"
118 "<brorg:suspended>true</brorg:suspended>"
119 "</brorg:chg>"
120 "</brorg:update>"
121 "<lacnicorg:update "
122 "xmlns:lacnicorg='urn:ietf:params:xml:ns:lacnicorg-1.0' "
123 "xsi:schemaLocation='urn:ietf:params:xml:ns:lacnicorg-1.0 "
124 "lacnicorg-1.0.xsd'>"
125 "<lacnicorg:add>"
126 "<lacnicorg:eppIP>192.168.0.1</lacnicorg:eppIP>"
127 "<lacnicorg:eppIP>192.0.2.0/24</lacnicorg:eppIP>"
128 "<lacnicorg:renewalType>large</lacnicorg:renewalType>"
129 "</lacnicorg:add>"
130 "<lacnicorg:rem>"
131 "<lacnicorg:eppIP>203.0.113.0/24</lacnicorg:eppIP>"
132 "<lacnicorg:renewalType>small</lacnicorg:renewalType>"
133 "</lacnicorg:rem>"
134 "<lacnicorg:chg>"
135 "<lacnicorg:type>normal</lacnicorg:type>"
136 "<lacnicorg:eppStatus>active</lacnicorg:eppStatus>"
137 "<lacnicorg:eppPassword>abc123</lacnicorg:eppPassword>"
138 "<lacnicorg:resourcesClass>non-legacy-only</lacnicorg:resourcesClass>"
139 "</lacnicorg:chg>"
140 "<lacnicorg:password>abc123</lacnicorg:password>"
141 "</lacnicorg:update>"
142 "</extension>"
143 "<clTRID>ABC-12345</clTRID>"
144 "</command>"
145 "</epp>";
146
147 BrOrgUpdate brorg_update;
148 BrOrgUpdateCmd *cmd = brorg_update.get_command();
149
150 CommonData common;
151 common.set_id("e654321");
152 cmd->set_organization("005.506.560/0001-36");
153 cmd->set_responsible("Responsible Name");
154 cmd->set_exDate("2009-02-01T12:00:00.0Z");
155 cmd->insert_contact_add("admin", "hkk");
156 cmd->insert_contact_rem("admin", "fan");
157 cmd->set_suspended(true);
158 cmd->set_type("normal");
159
160 // LacnicOrg specific
161 cmd->set_epp_status("active");
162 cmd->set_epp_password("abc123");
163 cmd->insert_epp_ip_add("192.168.0.1");
164 cmd->insert_epp_ip_add("192.0.2.0/24");
165 cmd->insert_epp_ip_rem("203.0.113.0/24");
166 cmd->insert_renewal_type_add("large");
167 cmd->insert_renewal_type_rem("small");
168 cmd->set_resources_class("non-legacy-only");
169 cmd->set_password("abc123");
170
171 brorg_update.get_command()->set_clTRID("ABC-12345");
172 cmd->set_common_data(common);
173 brorg_update.set_xml_template(to_be_parsed);
174
175 CPPUNIT_ASSERT_EQUAL(expected, brorg_update.get_xml());
176
177 //tests reset method
178 cmd->reset();
179
180 //parent information
181 CPPUNIT_ASSERT(cmd->get_status_list_add().empty());
182 CPPUNIT_ASSERT(cmd->get_status_list_rem().empty());
183 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_common_data().get_id());
184 CPPUNIT_ASSERT(cmd->get_common_data().get_postal_info().empty());
185 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_common_data().get_voice().ext);
186 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_common_data().get_voice().number);
187 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_common_data().get_fax().ext);
188 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_common_data().get_fax().number);
189 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_common_data().get_email());
190 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_authInfo().get_pw());
191 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().flag == -1);
192 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().name_int == false);
193 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().name_loc == false);
194 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().org_int == false);
195 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().org_loc == false);
196 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().addr_int == false);
197 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().addr_loc == false);
198 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().email == false);
199 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().voice == false);
200 CPPUNIT_ASSERT(cmd->get_common_data().get_disclose().fax == false);
201
202 //BrOrgUpdate specific
203 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_organization());
204 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_responsible());
205 CPPUNIT_ASSERT_EQUAL((string) "", cmd->get_exDate());
206 CPPUNIT_ASSERT(cmd->get_contact_list_add().empty());
207 CPPUNIT_ASSERT(cmd->get_contact_list_rem().empty());
208 CPPUNIT_ASSERT(cmd->get_suspended() == SuspendedStatus::UNDEFINED);
209
210 //LacnicOrg specific
211 CPPUNIT_ASSERT(cmd->get_type().empty());
212 CPPUNIT_ASSERT(cmd->get_epp_status().empty());
213 CPPUNIT_ASSERT(cmd->get_epp_password().empty());
214 CPPUNIT_ASSERT(cmd->get_epp_ips_add().empty());
215 CPPUNIT_ASSERT(cmd->get_epp_ips_rem().empty());
216 CPPUNIT_ASSERT(cmd->get_renewal_types_add().empty());
217 CPPUNIT_ASSERT(cmd->get_renewal_types_rem().empty());
218 CPPUNIT_ASSERT(cmd->get_resources_class().empty());
219 CPPUNIT_ASSERT(cmd->get_password().empty());
220 }
221
command_test()222 void BrOrgUpdateTest::command_test()
223 {
224 BrOrgUpdate br_org_update;
225 BrOrgUpdateCmd *cmd = br_org_update.get_command();
226
227 CommonData common;
228 //parent information
229 cmd->insert_status_list_add("clientDeleteProhibited");
230 cmd->insert_status_list_add("linked");
231 cmd->insert_status_list_rem("clientTransferProhibited");
232 cmd->insert_status_list_rem("clientUpdateProhibited");
233 common.set_id("cme254");
234 PostalInfo postal_info;
235 postal_info.set_type("int");
236 postal_info.set_name("John Doe");
237 postal_info.set_org("Example Inc.");
238 postal_info.set_str1("123 Example Dr.");
239 postal_info.set_str2("Suite 100");
240 postal_info.set_city( "Dulles");
241 postal_info.set_sp("VA");
242 postal_info.set_pc("20166-6503");
243 postal_info.set_cc("US");
244 common.insert_postal_info(postal_info);
245 postal_info.reset();
246 postal_info.set_type("loc");
247 postal_info.set_name("John Doe");
248 postal_info.set_org("Other Inc.");
249 postal_info.set_str1("123 Street");
250 postal_info.set_str2("7th floor");
251 postal_info.set_str3("Suite 123");
252 postal_info.set_city( "Miami");
253 postal_info.set_cc("US");
254 common.insert_postal_info(postal_info);
255
256 CommonData::Phone voice;
257 voice.ext = "1234";
258 voice.number = "+1.7035555555";
259 common.set_voice(voice);
260
261 CommonData::Phone fax;
262 fax.ext = "3456";
263 fax.number = "+1.7035555556";
264 common.set_fax(fax);
265
266 common.set_email("jdoe@example.com");
267
268 AuthInfo authInfo;
269 authInfo.set_roid("");
270 authInfo.set_pw("2fooBAR");
271 cmd->set_authInfo(authInfo);
272
273 CommonData::Disclose disclose;
274 disclose.flag = 1;
275 disclose.voice = true;
276 disclose.email = true;
277 common.set_disclose(disclose);
278
279 //BrOrgUpdate specific information
280 cmd->set_organization("005.506.560/0001-36");
281 cmd->set_exDate("2009-02-01T12:00:00.0Z");
282 cmd->insert_contact_add("admin", "hkk");
283 cmd->insert_contact_rem("admin", "fan");
284 cmd->set_common_data(common);
285 cmd->set_suspended(true);
286
287 // LacnicOrg specific
288 cmd->set_type("normal");
289 cmd->set_epp_status("active");
290 cmd->set_epp_password("abc123");
291 cmd->insert_epp_ip_add("192.168.0.1");
292 cmd->insert_epp_ip_add("192.0.2.0/24");
293 cmd->insert_epp_ip_rem("203.0.113.0/24");
294 cmd->insert_renewal_type_add("large");
295 cmd->insert_renewal_type_rem("small");
296 cmd->set_resources_class("non-legacy-only");
297 cmd->set_password("abc123");
298
299 bool exception_caught = false;
300 try {
301 string xml_template =
302 FileUtil::read_file("../docs/templates/br_org_update.xml");
303
304 br_org_update.get_command()->set_clTRID("ABC-12345");
305 br_org_update.set_xml_template(xml_template);
306
307 DomParser parser;
308 parser.enable_validation("../docs/schemas");
309 parser.parse_command(br_org_update.get_xml());
310 } catch (const IoException &e) {
311 exception_caught = true;
312 printf("\nIO Exception: code [%d] message [%s]",
313 e.get_code(), e.get_msg().c_str());
314 } catch (const XmlException &e) {
315 exception_caught = true;
316 printf("\nXml Exception: code [%d] message [%s] low level message [%s]\n",
317 e.get_code(), e.get_msg().c_str(), e.get_low_level_msg().c_str());
318 }
319
320 CPPUNIT_ASSERT(!exception_caught);
321 }
322 #endif //USE_BR_ORG
323