ncr_unittests.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <dhcp_ddns/ncr_msg.h>
  15. #include <dhcp/duid.h>
  16. #include <util/time_utilities.h>
  17. #include <gtest/gtest.h>
  18. #include <algorithm>
  19. using namespace std;
  20. using namespace isc;
  21. using namespace isc::dhcp_ddns;
  22. using namespace isc::dhcp;
  23. namespace {
  24. /// @brief Defines a list of valid JSON NameChangeRequest renditions.
  25. /// They are used as input to test conversion from JSON.
  26. const char *valid_msgs[] =
  27. {
  28. // Valid Add.
  29. "{"
  30. " \"change_type\" : 0 , "
  31. " \"forward_change\" : true , "
  32. " \"reverse_change\" : false , "
  33. " \"fqdn\" : \"walah.walah.com\" , "
  34. " \"ip_address\" : \"192.168.2.1\" , "
  35. " \"dhcid\" : \"010203040A7F8E3D\" , "
  36. " \"lease_expires_on\" : \"20130121132405\" , "
  37. " \"lease_length\" : 1300 "
  38. "}",
  39. // Valid Remove.
  40. "{"
  41. " \"change_type\" : 1 , "
  42. " \"forward_change\" : true , "
  43. " \"reverse_change\" : false , "
  44. " \"fqdn\" : \"walah.walah.com\" , "
  45. " \"ip_address\" : \"192.168.2.1\" , "
  46. " \"dhcid\" : \"010203040A7F8E3D\" , "
  47. " \"lease_expires_on\" : \"20130121132405\" , "
  48. " \"lease_length\" : 1300 "
  49. "}",
  50. // Valid Add with IPv6 address
  51. "{"
  52. " \"change_type\" : 0 , "
  53. " \"forward_change\" : true , "
  54. " \"reverse_change\" : false , "
  55. " \"fqdn\" : \"walah.walah.com\" , "
  56. " \"ip_address\" : \"fe80::2acf:e9ff:fe12:e56f\" , "
  57. " \"dhcid\" : \"010203040A7F8E3D\" , "
  58. " \"lease_expires_on\" : \"20130121132405\" , "
  59. " \"lease_length\" : 1300 "
  60. "}"
  61. };
  62. /// @brief Defines a list of invalid JSON NameChangeRequest renditions.
  63. /// They are used as input to test conversion from JSON.
  64. const char *invalid_msgs[] =
  65. {
  66. // Invalid change type.
  67. "{"
  68. " \"change_type\" : 7 , "
  69. " \"forward_change\" : true , "
  70. " \"reverse_change\" : false , "
  71. " \"fqdn\" : \"walah.walah.com\" , "
  72. " \"ip_address\" : \"192.168.2.1\" , "
  73. " \"dhcid\" : \"010203040A7F8E3D\" , "
  74. " \"lease_expires_on\" : \"20130121132405\" , "
  75. " \"lease_length\" : 1300 "
  76. "}",
  77. // Invalid forward change.
  78. "{"
  79. " \"change_type\" : 0 , "
  80. " \"forward_change\" : \"bogus\" , "
  81. " \"reverse_change\" : false , "
  82. " \"fqdn\" : \"walah.walah.com\" , "
  83. " \"ip_address\" : \"192.168.2.1\" , "
  84. " \"dhcid\" : \"010203040A7F8E3D\" , "
  85. " \"lease_expires_on\" : \"20130121132405\" , "
  86. " \"lease_length\" : 1300 "
  87. "}",
  88. // Invalid reverse change.
  89. "{"
  90. " \"change_type\" : 0 , "
  91. " \"forward_change\" : true , "
  92. " \"reverse_change\" : 500 , "
  93. " \"fqdn\" : \"walah.walah.com\" , "
  94. " \"ip_address\" : \"192.168.2.1\" , "
  95. " \"dhcid\" : \"010203040A7F8E3D\" , "
  96. " \"lease_expires_on\" : \"20130121132405\" , "
  97. " \"lease_length\" : 1300 "
  98. "}",
  99. // Forward and reverse change both false.
  100. "{"
  101. " \"change_type\" : 0 , "
  102. " \"forward_change\" : false , "
  103. " \"reverse_change\" : false , "
  104. " \"fqdn\" : \"walah.walah.com\" , "
  105. " \"ip_address\" : \"192.168.2.1\" , "
  106. " \"dhcid\" : \"010203040A7F8E3D\" , "
  107. " \"lease_expires_on\" : \"20130121132405\" , "
  108. " \"lease_length\" : 1300 "
  109. "}",
  110. // Blank FQDN
  111. "{"
  112. " \"change_type\" : 0 , "
  113. " \"forward_change\" : true , "
  114. " \"reverse_change\" : false , "
  115. " \"fqdn\" : \"\" , "
  116. " \"ip_address\" : \"192.168.2.1\" , "
  117. " \"dhcid\" : \"010203040A7F8E3D\" , "
  118. " \"lease_expires_on\" : \"20130121132405\" , "
  119. " \"lease_length\" : 1300 "
  120. "}",
  121. // Bad IP address
  122. "{"
  123. " \"change_type\" : 0 , "
  124. " \"forward_change\" : true , "
  125. " \"reverse_change\" : false , "
  126. " \"fqdn\" : \"walah.walah.com\" , "
  127. " \"ip_address\" : \"xxxxxx\" , "
  128. " \"dhcid\" : \"010203040A7F8E3D\" , "
  129. " \"lease_expires_on\" : \"20130121132405\" , "
  130. " \"lease_length\" : 1300 "
  131. "}",
  132. // Blank DHCID
  133. "{"
  134. " \"change_type\" : 0 , "
  135. " \"forward_change\" : true , "
  136. " \"reverse_change\" : false , "
  137. " \"fqdn\" : \"walah.walah.com\" , "
  138. " \"ip_address\" : \"192.168.2.1\" , "
  139. " \"dhcid\" : \"\" , "
  140. " \"lease_expires_on\" : \"20130121132405\" , "
  141. " \"lease_length\" : 1300 "
  142. "}",
  143. // Odd number of digits in DHCID
  144. "{"
  145. " \"change_type\" : 0 , "
  146. " \"forward_change\" : true , "
  147. " \"reverse_change\" : false , "
  148. " \"fqdn\" : \"walah.walah.com\" , "
  149. " \"ip_address\" : \"192.168.2.1\" , "
  150. " \"dhcid\" : \"010203040A7F8E3\" , "
  151. " \"lease_expires_on\" : \"20130121132405\" , "
  152. " \"lease_length\" : 1300 "
  153. "}",
  154. // Text in DHCID
  155. "{"
  156. " \"change_type\" : 0 , "
  157. " \"forward_change\" : true , "
  158. " \"reverse_change\" : false , "
  159. " \"fqdn\" : \"walah.walah.com\" , "
  160. " \"ip_address\" : \"192.168.2.1\" , "
  161. " \"dhcid\" : \"THIS IS BOGUS!!!\" , "
  162. " \"lease_expires_on\" : \"20130121132405\" , "
  163. " \"lease_length\" : 1300 "
  164. "}",
  165. // Invalid lease expiration string
  166. "{"
  167. " \"change_type\" : 0 , "
  168. " \"forward_change\" : true , "
  169. " \"reverse_change\" : false , "
  170. " \"fqdn\" : \"walah.walah.com\" , "
  171. " \"ip_address\" : \"192.168.2.1\" , "
  172. " \"dhcid\" : \"010203040A7F8E3D\" , "
  173. " \"lease_expires_on\" : \"Wed Jun 26 13:46:46 EDT 2013\" , "
  174. " \"lease_length\" : 1300 "
  175. "}",
  176. // Non-integer for lease length.
  177. "{"
  178. " \"change_type\" : 0 , "
  179. " \"forward_change\" : true , "
  180. " \"reverse_change\" : false , "
  181. " \"fqdn\" : \"walah.walah.com\" , "
  182. " \"ip_address\" : \"192.168.2.1\" , "
  183. " \"dhcid\" : \"010203040A7F8E3D\" , "
  184. " \"lease_expires_on\" : \"20130121132405\" , "
  185. " \"lease_length\" : \"BOGUS\" "
  186. "}"
  187. };
  188. /// @brief Tests the NameChangeRequest constructors.
  189. /// This test verifies that:
  190. /// 1. Default constructor works.
  191. /// 2. "Full" constructor, when given valid parameter values, works.
  192. /// 3. "Full" constructor, given a blank FQDN fails
  193. /// 4. "Full" constructor, given an invalid IP Address FQDN fails
  194. /// 5. "Full" constructor, given a blank DHCID fails
  195. /// 6. "Full" constructor, given false for both forward and reverse fails
  196. TEST(NameChangeRequestTest, constructionTests) {
  197. // Verify the default constructor works.
  198. NameChangeRequestPtr ncr;
  199. EXPECT_NO_THROW(ncr.reset(new NameChangeRequest()));
  200. EXPECT_TRUE(ncr);
  201. // Verify that full constructor works.
  202. uint64_t expiry = isc::util::detail::gettimeWrapper();
  203. D2Dhcid dhcid("010203040A7F8E3D");
  204. EXPECT_NO_THROW(ncr.reset(new NameChangeRequest(
  205. CHG_ADD, true, true, "walah.walah.com",
  206. "192.168.1.101", dhcid, expiry, 1300)));
  207. EXPECT_TRUE(ncr);
  208. ncr.reset();
  209. // Verify blank FQDN is detected.
  210. EXPECT_THROW(NameChangeRequest(CHG_ADD, true, true, "",
  211. "192.168.1.101", dhcid, expiry, 1300), NcrMessageError);
  212. // Verify that an invalid IP address is detected.
  213. EXPECT_THROW(NameChangeRequest(CHG_ADD, true, true, "valid.fqdn",
  214. "xxx.168.1.101", dhcid, expiry, 1300), NcrMessageError);
  215. // Verify that a blank DHCID is detected.
  216. D2Dhcid blank_dhcid;
  217. EXPECT_THROW(NameChangeRequest(CHG_ADD, true, true, "walah.walah.com",
  218. "192.168.1.101", blank_dhcid, expiry, 1300), NcrMessageError);
  219. // Verify that one or both of direction flags must be true.
  220. EXPECT_THROW(NameChangeRequest(CHG_ADD, false, false, "valid.fqdn",
  221. "192.168.1.101", dhcid, expiry, 1300), NcrMessageError);
  222. }
  223. /// @brief Tests the basic workings of D2Dhcid to and from string conversions.
  224. /// It verifies that:
  225. /// 1. DHCID input strings must contain an even number of characters
  226. /// 2. DHCID input strings must contain only hexadecimal character digits
  227. /// 3. A valid DHCID string converts correctly.
  228. /// 4. Converting a D2Dhcid to a string works correctly.
  229. /// 5. Equality, inequality, and less-than-equal operators work.
  230. TEST(NameChangeRequestTest, dhcidTest) {
  231. D2Dhcid dhcid;
  232. // Odd number of digits should be rejected.
  233. std::string test_str = "010203040A7F8E3";
  234. EXPECT_THROW(dhcid.fromStr(test_str), NcrMessageError);
  235. // Non digit content should be rejected.
  236. test_str = "0102BOGUSA7F8E3D";
  237. EXPECT_THROW(dhcid.fromStr(test_str), NcrMessageError);
  238. // Verify that valid input converts into a proper byte array.
  239. test_str = "010203040A7F8E3D";
  240. ASSERT_NO_THROW(dhcid.fromStr(test_str));
  241. // Create a test vector of expected byte contents.
  242. const uint8_t bytes[] = { 0x1, 0x2, 0x3, 0x4, 0xA, 0x7F, 0x8E, 0x3D };
  243. std::vector<uint8_t> expected_bytes(bytes, bytes + sizeof(bytes));
  244. // Fetch the byte vector from the dhcid and verify if equals the expected
  245. // content.
  246. const std::vector<uint8_t>& converted_bytes = dhcid.getBytes();
  247. EXPECT_EQ(expected_bytes.size(), converted_bytes.size());
  248. EXPECT_TRUE (std::equal(expected_bytes.begin(),
  249. expected_bytes.begin()+expected_bytes.size(),
  250. converted_bytes.begin()));
  251. // Convert the new dhcid back to string and verify it matches the original
  252. // DHCID input string.
  253. std::string next_str = dhcid.toStr();
  254. EXPECT_EQ(test_str, next_str);
  255. // Test equality, inequality, and less-than-equal operators
  256. test_str="AABBCCDD";
  257. EXPECT_NO_THROW(dhcid.fromStr(test_str));
  258. D2Dhcid other_dhcid;
  259. EXPECT_NO_THROW(other_dhcid.fromStr(test_str));
  260. EXPECT_TRUE(dhcid == other_dhcid);
  261. EXPECT_FALSE(dhcid != other_dhcid);
  262. EXPECT_NO_THROW(other_dhcid.fromStr("BBCCDDEE"));
  263. EXPECT_TRUE(dhcid < other_dhcid);
  264. }
  265. /// Tests that DHCID is correctly created from a DUID and FQDN. The final format
  266. /// of the DHCID is as follows:
  267. /// <identifier-type> <digest-type-code> <digest>
  268. /// where:
  269. /// - identifier-type (2 octets) is 0x0002.
  270. /// - digest-type-code (1 octet) indicates SHA-256 hashing and is equal 0x1.
  271. /// - digest = SHA-256(<DUID> <FQDN>)
  272. /// Note: FQDN is given in the on-wire canonical format.
  273. TEST(NameChangeRequestTest, dhcidFromDUID) {
  274. D2Dhcid dhcid;
  275. // Create DUID.
  276. uint8_t duid_data[] = { 0, 1, 2, 3, 4, 5, 6 };
  277. DUID duid(duid_data, sizeof(duid_data));
  278. // Create FQDN in on-wire format: myhost.example.com. It is encoded
  279. // as a set of labels, each preceded by its length. The whole FQDN
  280. // is zero-terminated.
  281. const uint8_t fqdn_data[] = {
  282. 6, 109, 121, 104, 111, 115, 116, // myhost.
  283. 7, 101, 120, 97, 109, 112, 108, 101, // example.
  284. 3, 99, 111, 109, 0 // com.
  285. };
  286. std::vector<uint8_t> wire_fqdn(fqdn_data, fqdn_data + sizeof(fqdn_data));
  287. // Create DHCID.
  288. ASSERT_NO_THROW(dhcid.fromDUID(duid, wire_fqdn));
  289. // The reference DHCID (represented as string of hexadecimal digits)
  290. // has been calculated using one of the online calculators.
  291. std::string dhcid_ref = "0002012191B7B21AF97E0E656DF887C5E2D"
  292. "EF30E7758A207EDF4CCB2DE8CA37066021C";
  293. // Make sure that the DHCID is valid.
  294. EXPECT_EQ(dhcid_ref, dhcid.toStr());
  295. }
  296. // Test that DHCID is correctly created when the DUID has minimal length (1).
  297. TEST(NameChangeRequestTest, dhcidFromMinDUID) {
  298. D2Dhcid dhcid;
  299. // Create DUID.
  300. uint8_t duid_data[] = { 1 };
  301. DUID duid(duid_data, sizeof(duid_data));
  302. // Create FQDN in on-wire format: myhost.example.com. It is encoded
  303. // as a set of labels, each preceded by its length. The whole FQDN
  304. // is zero-terminated.
  305. const uint8_t fqdn_data[] = {
  306. 6, 109, 121, 104, 111, 115, 116, // myhost.
  307. 7, 101, 120, 97, 109, 112, 108, 101, // example.
  308. 3, 99, 111, 109, 0 // com.
  309. };
  310. std::vector<uint8_t> wire_fqdn(fqdn_data, fqdn_data + sizeof(fqdn_data));
  311. // Create DHCID.
  312. ASSERT_NO_THROW(dhcid.fromDUID(duid, wire_fqdn));
  313. // The reference DHCID (represented as string of hexadecimal digits)
  314. // has been calculated using one of the online calculators.
  315. std::string dhcid_ref = "000201F89004F73E60CAEDFF514E11CB91D"
  316. "1F45C8F0A55D4BC4C688484A819F8EA4074";
  317. // Make sure that the DHCID is valid.
  318. EXPECT_EQ(dhcid_ref, dhcid.toStr());
  319. }
  320. // Test that DHCID is correctly created when the DUID has maximal length (128).
  321. TEST(NameChangeRequestTest, dhcidFromMaxDUID) {
  322. D2Dhcid dhcid;
  323. // Create DUID.
  324. std::vector<uint8_t> duid_data(128, 1);
  325. DUID duid(&duid_data[0], duid_data.size());
  326. // Create FQDN in on-wire format: myhost.example.com. It is encoded
  327. // as a set of labels, each preceded by its length. The whole FQDN
  328. // is zero-terminated.
  329. const uint8_t fqdn_data[] = {
  330. 6, 109, 121, 104, 111, 115, 116, // myhost.
  331. 7, 101, 120, 97, 109, 112, 108, 101, // example.
  332. 3, 99, 111, 109, 0 // com.
  333. };
  334. std::vector<uint8_t> wire_fqdn(fqdn_data, fqdn_data + sizeof(fqdn_data));
  335. // Create DHCID.
  336. ASSERT_NO_THROW(dhcid.fromDUID(duid, wire_fqdn));
  337. // The reference DHCID (represented as string of hexadecimal digits)
  338. // has been calculated using one of the online calculators.
  339. std::string dhcid_ref = "00020137D8FBDC0585B44DFA03FAD2E36C6"
  340. "159737D545A12EFB40B0D88D110A5748234";
  341. // Make sure that the DHCID is valid.
  342. EXPECT_EQ(dhcid_ref, dhcid.toStr());
  343. }
  344. /// @brief Verifies the fundamentals of converting from and to JSON.
  345. /// It verifies that:
  346. /// 1. A NameChangeRequest can be created from a valid JSON string.
  347. /// 2. A valid JSON string can be created from a NameChangeRequest
  348. TEST(NameChangeRequestTest, basicJsonTest) {
  349. // Define valid JSON rendition of a request.
  350. std::string msg_str = "{"
  351. "\"change_type\":1,"
  352. "\"forward_change\":true,"
  353. "\"reverse_change\":false,"
  354. "\"fqdn\":\"walah.walah.com\","
  355. "\"ip_address\":\"192.168.2.1\","
  356. "\"dhcid\":\"010203040A7F8E3D\","
  357. "\"lease_expires_on\":\"20130121132405\","
  358. "\"lease_length\":1300"
  359. "}";
  360. // Verify that a NameChangeRequests can be instantiated from the
  361. // a valid JSON rendition.
  362. NameChangeRequestPtr ncr;
  363. ASSERT_NO_THROW(ncr = NameChangeRequest::fromJSON(msg_str));
  364. ASSERT_TRUE(ncr);
  365. // Verify that the JSON string created by the new request equals the
  366. // original input string.
  367. std::string json_str = ncr->toJSON();
  368. EXPECT_EQ(msg_str, json_str);
  369. }
  370. /// @brief Tests a variety of invalid JSON message strings.
  371. /// This test iterates over a list of JSON messages, each containing a single
  372. /// content error. The list of messages is defined by the global array,
  373. /// invalid_messages. Currently that list contains the following invalid
  374. /// conditions:
  375. /// 1. Invalid change type
  376. /// 2. Invalid forward change
  377. /// 3. Invalid reverse change
  378. /// 4. Forward and reverse change both false
  379. /// 5. Invalid forward change
  380. /// 6. Blank FQDN
  381. /// 7. Bad IP address
  382. /// 8. Blank DHCID
  383. /// 9. Odd number of digits in DHCID
  384. /// 10. Text in DHCID
  385. /// 11. Invalid lease expiration string
  386. /// 12. Non-integer for lease length.
  387. /// If more permutations arise they can easily be added to the list.
  388. TEST(NameChangeRequestTest, invalidMsgChecks) {
  389. // Iterate over the list of JSON strings, attempting to create a
  390. // NameChangeRequest. The attempt should throw a NcrMessageError.
  391. int num_msgs = sizeof(invalid_msgs)/sizeof(char*);
  392. for (int i = 0; i < num_msgs; i++) {
  393. EXPECT_THROW(NameChangeRequest::fromJSON(invalid_msgs[i]),
  394. NcrMessageError) << "Invalid message not caught idx: "
  395. << i << std::endl << " text:[" << invalid_msgs[i] << "]"
  396. << std::endl;
  397. }
  398. }
  399. /// @brief Tests a variety of valid JSON message strings.
  400. /// This test iterates over a list of JSON messages, each containing a single
  401. /// valid request rendition. The list of messages is defined by the global
  402. /// array, valid_messages. Currently that list contains the following valid
  403. /// messages:
  404. /// 1. Valid, IPv4 Add
  405. /// 2. Valid, IPv4 Remove
  406. /// 3. Valid, IPv6 Add
  407. /// If more permutations arise they can easily be added to the list.
  408. TEST(NameChangeRequestTest, validMsgChecks) {
  409. // Iterate over the list of JSON strings, attempting to create a
  410. // NameChangeRequest. The attempt should succeed.
  411. int num_msgs = sizeof(valid_msgs)/sizeof(char*);
  412. for (int i = 0; i < num_msgs; i++) {
  413. EXPECT_NO_THROW(NameChangeRequest::fromJSON(valid_msgs[i]))
  414. << "Valid message failed, message idx: " << i
  415. << std::endl << " text:[" << valid_msgs[i] << "]"
  416. << std::endl;
  417. }
  418. }
  419. /// @brief Tests converting to and from JSON via isc::util buffer classes.
  420. /// This test verifies that:
  421. /// 1. A NameChangeRequest can be rendered in JSON written to an OutputBuffer
  422. /// 2. A InputBuffer containing a valid JSON request rendition can be used
  423. /// to create a NameChangeRequest.
  424. TEST(NameChangeRequestTest, toFromBufferTest) {
  425. // Define a string containing a valid JSON NameChangeRequest rendition.
  426. std::string msg_str = "{"
  427. "\"change_type\":1,"
  428. "\"forward_change\":true,"
  429. "\"reverse_change\":false,"
  430. "\"fqdn\":\"walah.walah.com\","
  431. "\"ip_address\":\"192.168.2.1\","
  432. "\"dhcid\":\"010203040A7F8E3D\","
  433. "\"lease_expires_on\":\"20130121132405\","
  434. "\"lease_length\":1300"
  435. "}";
  436. // Create a request from JSON directly.
  437. NameChangeRequestPtr ncr;
  438. ASSERT_NO_THROW(ncr = NameChangeRequest::fromJSON(msg_str));
  439. // Verify that we output the request as JSON text to a buffer
  440. // without error.
  441. isc::util::OutputBuffer output_buffer(1024);
  442. ASSERT_NO_THROW(ncr->toFormat(FMT_JSON, output_buffer));
  443. // Make an InputBuffer from the OutputBuffer.
  444. isc::util::InputBuffer input_buffer(output_buffer.getData(),
  445. output_buffer.getLength());
  446. // Verify that we can create a new request from the InputBuffer.
  447. NameChangeRequestPtr ncr2;
  448. ASSERT_NO_THROW(ncr2 =
  449. NameChangeRequest::fromFormat(FMT_JSON, input_buffer));
  450. // Convert the new request to JSON directly.
  451. std::string final_str = ncr2->toJSON();
  452. // Verify that the final string matches the original.
  453. ASSERT_EQ(final_str, msg_str);
  454. }
  455. } // end of anonymous namespace