PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/unit/type/host_spec.rb

https://github.com/david-caro/puppet
Ruby | 665 lines | 557 code | 72 blank | 36 comment | 17 complexity | ff36209c5398499d5dcc1fbd427a59ef MD5 | raw file
Possible License(s): Apache-2.0, CC-BY-3.0
  1. #! /usr/bin/env ruby
  2. require 'spec_helper'
  3. host = Puppet::Type.type(:host)
  4. describe host do
  5. FakeHostProvider = Struct.new(:ip, :host_aliases, :comment)
  6. before do
  7. @class = host
  8. @catalog = Puppet::Resource::Catalog.new
  9. @provider = FakeHostProvider.new
  10. @resource = stub 'resource', :resource => nil, :provider => @provider
  11. end
  12. it "should have :name be its namevar" do
  13. @class.key_attributes.should == [:name]
  14. end
  15. describe "when validating attributes" do
  16. [:name, :provider ].each do |param|
  17. it "should have a #{param} parameter" do
  18. @class.attrtype(param).should == :param
  19. end
  20. end
  21. [:ip, :target, :host_aliases, :comment, :ensure].each do |property|
  22. it "should have a #{property} property" do
  23. @class.attrtype(property).should == :property
  24. end
  25. end
  26. it "should have a list host_aliases" do
  27. @class.attrclass(:host_aliases).ancestors.should be_include(Puppet::Property::OrderedList)
  28. end
  29. end
  30. describe "when validating values" do
  31. it "should support present as a value for ensure" do
  32. proc { @class.new(:name => "foo", :ensure => :present) }.should_not raise_error
  33. end
  34. it "should support absent as a value for ensure" do
  35. proc { @class.new(:name => "foo", :ensure => :absent) }.should_not raise_error
  36. end
  37. it "should accept IPv4 addresses" do
  38. proc { @class.new(:name => "foo", :ip => '10.96.0.1') }.should_not raise_error
  39. end
  40. it "should accept long IPv6 addresses" do
  41. # Taken from wikipedia article about ipv6
  42. proc { @class.new(:name => "foo", :ip => '2001:0db8:85a3:08d3:1319:8a2e:0370:7344') }.should_not raise_error
  43. end
  44. it "should accept one host_alias" do
  45. proc { @class.new(:name => "foo", :host_aliases => 'alias1') }.should_not raise_error
  46. end
  47. it "should accept multiple host_aliases" do
  48. proc { @class.new(:name => "foo", :host_aliases => [ 'alias1', 'alias2' ]) }.should_not raise_error
  49. end
  50. it "should accept shortened IPv6 addresses" do
  51. proc { @class.new(:name => "foo", :ip => '2001:db8:0:8d3:0:8a2e:70:7344') }.should_not raise_error
  52. proc { @class.new(:name => "foo", :ip => '::ffff:192.0.2.128') }.should_not raise_error
  53. proc { @class.new(:name => "foo", :ip => '::1') }.should_not raise_error
  54. end
  55. it "should not accept malformed IPv4 addresses like 192.168.0.300" do
  56. proc { @class.new(:name => "foo", :ip => '192.168.0.300') }.should raise_error
  57. end
  58. it "should reject over-long IPv4 addresses" do
  59. expect { @class.new(:name => "foo", :ip => '10.10.10.10.10') }.to raise_error
  60. end
  61. it "should not accept malformed IP addresses like 2001:0dg8:85a3:08d3:1319:8a2e:0370:7344" do
  62. proc { @class.new(:name => "foo", :ip => '2001:0dg8:85a3:08d3:1319:8a2e:0370:7344') }.should raise_error
  63. end
  64. # Assorted, annotated IPv6 passes.
  65. ["::1", # loopback, compressed, non-routable
  66. "::", # unspecified, compressed, non-routable
  67. "0:0:0:0:0:0:0:1", # loopback, full
  68. "0:0:0:0:0:0:0:0", # unspecified, full
  69. "2001:DB8:0:0:8:800:200C:417A", # unicast, full
  70. "FF01:0:0:0:0:0:0:101", # multicast, full
  71. "2001:DB8::8:800:200C:417A", # unicast, compressed
  72. "FF01::101", # multicast, compressed
  73. # Some more test cases that should pass.
  74. "2001:0000:1234:0000:0000:C1C0:ABCD:0876",
  75. "3ffe:0b00:0000:0000:0001:0000:0000:000a",
  76. "FF02:0000:0000:0000:0000:0000:0000:0001",
  77. "0000:0000:0000:0000:0000:0000:0000:0001",
  78. "0000:0000:0000:0000:0000:0000:0000:0000",
  79. # Assorted valid, compressed IPv6 addresses.
  80. "2::10",
  81. "ff02::1",
  82. "fe80::",
  83. "2002::",
  84. "2001:db8::",
  85. "2001:0db8:1234::",
  86. "::ffff:0:0",
  87. "::1",
  88. "1:2:3:4:5:6:7:8",
  89. "1:2:3:4:5:6::8",
  90. "1:2:3:4:5::8",
  91. "1:2:3:4::8",
  92. "1:2:3::8",
  93. "1:2::8",
  94. "1::8",
  95. "1::2:3:4:5:6:7",
  96. "1::2:3:4:5:6",
  97. "1::2:3:4:5",
  98. "1::2:3:4",
  99. "1::2:3",
  100. "1::8",
  101. "::2:3:4:5:6:7:8",
  102. "::2:3:4:5:6:7",
  103. "::2:3:4:5:6",
  104. "::2:3:4:5",
  105. "::2:3:4",
  106. "::2:3",
  107. "::8",
  108. "1:2:3:4:5:6::",
  109. "1:2:3:4:5::",
  110. "1:2:3:4::",
  111. "1:2:3::",
  112. "1:2::",
  113. "1::",
  114. "1:2:3:4:5::7:8",
  115. "1:2:3:4::7:8",
  116. "1:2:3::7:8",
  117. "1:2::7:8",
  118. "1::7:8",
  119. # IPv4 addresses as dotted-quads
  120. "1:2:3:4:5:6:1.2.3.4",
  121. "1:2:3:4:5::1.2.3.4",
  122. "1:2:3:4::1.2.3.4",
  123. "1:2:3::1.2.3.4",
  124. "1:2::1.2.3.4",
  125. "1::1.2.3.4",
  126. "1:2:3:4::5:1.2.3.4",
  127. "1:2:3::5:1.2.3.4",
  128. "1:2::5:1.2.3.4",
  129. "1::5:1.2.3.4",
  130. "1::5:11.22.33.44",
  131. "fe80::217:f2ff:254.7.237.98",
  132. "::ffff:192.168.1.26",
  133. "::ffff:192.168.1.1",
  134. "0:0:0:0:0:0:13.1.68.3", # IPv4-compatible IPv6 address, full, deprecated
  135. "0:0:0:0:0:FFFF:129.144.52.38", # IPv4-mapped IPv6 address, full
  136. "::13.1.68.3", # IPv4-compatible IPv6 address, compressed, deprecated
  137. "::FFFF:129.144.52.38", # IPv4-mapped IPv6 address, compressed
  138. "fe80:0:0:0:204:61ff:254.157.241.86",
  139. "fe80::204:61ff:254.157.241.86",
  140. "::ffff:12.34.56.78",
  141. "::ffff:192.0.2.128", # this is OK, since there's a single zero digit in IPv4
  142. "fe80:0000:0000:0000:0204:61ff:fe9d:f156",
  143. "fe80:0:0:0:204:61ff:fe9d:f156",
  144. "fe80::204:61ff:fe9d:f156",
  145. "::1",
  146. "fe80::",
  147. "fe80::1",
  148. "::ffff:c000:280",
  149. # Additional test cases from http://rt.cpan.org/Public/Bug/Display.html?id=50693
  150. "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
  151. "2001:db8:85a3:0:0:8a2e:370:7334",
  152. "2001:db8:85a3::8a2e:370:7334",
  153. "2001:0db8:0000:0000:0000:0000:1428:57ab",
  154. "2001:0db8:0000:0000:0000::1428:57ab",
  155. "2001:0db8:0:0:0:0:1428:57ab",
  156. "2001:0db8:0:0::1428:57ab",
  157. "2001:0db8::1428:57ab",
  158. "2001:db8::1428:57ab",
  159. "0000:0000:0000:0000:0000:0000:0000:0001",
  160. "::1",
  161. "::ffff:0c22:384e",
  162. "2001:0db8:1234:0000:0000:0000:0000:0000",
  163. "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff",
  164. "2001:db8:a::123",
  165. "fe80::",
  166. "1111:2222:3333:4444:5555:6666:7777:8888",
  167. "1111:2222:3333:4444:5555:6666:7777::",
  168. "1111:2222:3333:4444:5555:6666::",
  169. "1111:2222:3333:4444:5555::",
  170. "1111:2222:3333:4444::",
  171. "1111:2222:3333::",
  172. "1111:2222::",
  173. "1111::",
  174. "1111:2222:3333:4444:5555:6666::8888",
  175. "1111:2222:3333:4444:5555::8888",
  176. "1111:2222:3333:4444::8888",
  177. "1111:2222:3333::8888",
  178. "1111:2222::8888",
  179. "1111::8888",
  180. "::8888",
  181. "1111:2222:3333:4444:5555::7777:8888",
  182. "1111:2222:3333:4444::7777:8888",
  183. "1111:2222:3333::7777:8888",
  184. "1111:2222::7777:8888",
  185. "1111::7777:8888",
  186. "::7777:8888",
  187. "1111:2222:3333:4444::6666:7777:8888",
  188. "1111:2222:3333::6666:7777:8888",
  189. "1111:2222::6666:7777:8888",
  190. "1111::6666:7777:8888",
  191. "::6666:7777:8888",
  192. "1111:2222:3333::5555:6666:7777:8888",
  193. "1111:2222::5555:6666:7777:8888",
  194. "1111::5555:6666:7777:8888",
  195. "::5555:6666:7777:8888",
  196. "1111:2222::4444:5555:6666:7777:8888",
  197. "1111::4444:5555:6666:7777:8888",
  198. "::4444:5555:6666:7777:8888",
  199. "1111::3333:4444:5555:6666:7777:8888",
  200. "::3333:4444:5555:6666:7777:8888",
  201. "::2222:3333:4444:5555:6666:7777:8888",
  202. "1111:2222:3333:4444:5555:6666:123.123.123.123",
  203. "1111:2222:3333:4444:5555::123.123.123.123",
  204. "1111:2222:3333:4444::123.123.123.123",
  205. "1111:2222:3333::123.123.123.123",
  206. "1111:2222::123.123.123.123",
  207. "1111::123.123.123.123",
  208. "::123.123.123.123",
  209. "1111:2222:3333:4444::6666:123.123.123.123",
  210. "1111:2222:3333::6666:123.123.123.123",
  211. "1111:2222::6666:123.123.123.123",
  212. "1111::6666:123.123.123.123",
  213. "::6666:123.123.123.123",
  214. "1111:2222:3333::5555:6666:123.123.123.123",
  215. "1111:2222::5555:6666:123.123.123.123",
  216. "1111::5555:6666:123.123.123.123",
  217. "::5555:6666:123.123.123.123",
  218. "1111:2222::4444:5555:6666:123.123.123.123",
  219. "1111::4444:5555:6666:123.123.123.123",
  220. "::4444:5555:6666:123.123.123.123",
  221. "1111::3333:4444:5555:6666:123.123.123.123",
  222. "::2222:3333:4444:5555:6666:123.123.123.123",
  223. # Playing with combinations of "0" and "::"; these are all sytactically
  224. # correct, but are bad form because "0" adjacent to "::" should be
  225. # combined into "::"
  226. "::0:0:0:0:0:0:0",
  227. "::0:0:0:0:0:0",
  228. "::0:0:0:0:0",
  229. "::0:0:0:0",
  230. "::0:0:0",
  231. "::0:0",
  232. "::0",
  233. "0:0:0:0:0:0:0::",
  234. "0:0:0:0:0:0::",
  235. "0:0:0:0:0::",
  236. "0:0:0:0::",
  237. "0:0:0::",
  238. "0:0::",
  239. "0::",
  240. # Additional cases: http://crisp.tweakblogs.net/blog/2031/ipv6-validation-%28and-caveats%29.html
  241. "0:a:b:c:d:e:f::",
  242. "::0:a:b:c:d:e:f", # syntactically correct, but bad form (::0:... could be combined)
  243. "a:b:c:d:e:f:0::",
  244. ].each do |ip|
  245. it "should accept #{ip.inspect} as an IPv6 address" do
  246. expect { @class.new(:name => "foo", :ip => ip) }.not_to raise_error
  247. end
  248. end
  249. # ...aaaand, some failure cases.
  250. [":",
  251. "02001:0000:1234:0000:0000:C1C0:ABCD:0876", # extra 0 not allowed!
  252. "2001:0000:1234:0000:00001:C1C0:ABCD:0876", # extra 0 not allowed!
  253. "2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", # junk after valid address
  254. "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", # internal space
  255. "3ffe:0b00:0000:0001:0000:0000:000a", # seven segments
  256. "FF02:0000:0000:0000:0000:0000:0000:0000:0001", # nine segments
  257. "3ffe:b00::1::a", # double "::"
  258. "::1111:2222:3333:4444:5555:6666::", # double "::"
  259. "1:2:3::4:5::7:8", # Double "::"
  260. "12345::6:7:8",
  261. # IPv4 embedded, but bad...
  262. "1::5:400.2.3.4", "1::5:260.2.3.4", "1::5:256.2.3.4", "1::5:1.256.3.4",
  263. "1::5:1.2.256.4", "1::5:1.2.3.256", "1::5:300.2.3.4", "1::5:1.300.3.4",
  264. "1::5:1.2.300.4", "1::5:1.2.3.300", "1::5:900.2.3.4", "1::5:1.900.3.4",
  265. "1::5:1.2.900.4", "1::5:1.2.3.900", "1::5:300.300.300.300", "1::5:3000.30.30.30",
  266. "1::400.2.3.4", "1::260.2.3.4", "1::256.2.3.4", "1::1.256.3.4",
  267. "1::1.2.256.4", "1::1.2.3.256", "1::300.2.3.4", "1::1.300.3.4",
  268. "1::1.2.300.4", "1::1.2.3.300", "1::900.2.3.4", "1::1.900.3.4",
  269. "1::1.2.900.4", "1::1.2.3.900", "1::300.300.300.300", "1::3000.30.30.30",
  270. "::400.2.3.4", "::260.2.3.4", "::256.2.3.4", "::1.256.3.4",
  271. "::1.2.256.4", "::1.2.3.256", "::300.2.3.4", "::1.300.3.4",
  272. "::1.2.300.4", "::1.2.3.300", "::900.2.3.4", "::1.900.3.4",
  273. "::1.2.900.4", "::1.2.3.900", "::300.300.300.300", "::3000.30.30.30",
  274. "2001:1:1:1:1:1:255Z255X255Y255", # garbage instead of "." in IPv4
  275. "::ffff:192x168.1.26", # ditto
  276. "::ffff:2.3.4",
  277. "::ffff:257.1.2.3",
  278. "1.2.3.4:1111:2222:3333:4444::5555",
  279. "1.2.3.4:1111:2222:3333::5555",
  280. "1.2.3.4:1111:2222::5555",
  281. "1.2.3.4:1111::5555",
  282. "1.2.3.4::5555",
  283. "1.2.3.4::",
  284. # Testing IPv4 addresses represented as dotted-quads Leading zero's in
  285. # IPv4 addresses not allowed: some systems treat the leading "0" in
  286. # ".086" as the start of an octal number Update: The BNF in RFC-3986
  287. # explicitly defines the dec-octet (for IPv4 addresses) not to have a
  288. # leading zero
  289. "fe80:0000:0000:0000:0204:61ff:254.157.241.086",
  290. "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4",
  291. "1111:2222:3333:4444:5555:6666:00.00.00.00",
  292. "1111:2222:3333:4444:5555:6666:000.000.000.000",
  293. "1111:2222:3333:4444:5555:6666:256.256.256.256",
  294. "1111:2222:3333:4444::5555:",
  295. "1111:2222:3333::5555:",
  296. "1111:2222::5555:",
  297. "1111::5555:",
  298. "::5555:",
  299. ":::",
  300. "1111:",
  301. ":",
  302. ":1111:2222:3333:4444::5555",
  303. ":1111:2222:3333::5555",
  304. ":1111:2222::5555",
  305. ":1111::5555",
  306. ":::5555",
  307. ":::",
  308. # Additional test cases from http://rt.cpan.org/Public/Bug/Display.html?id=50693
  309. "123",
  310. "ldkfj",
  311. "2001::FFD3::57ab",
  312. "2001:db8:85a3::8a2e:37023:7334",
  313. "2001:db8:85a3::8a2e:370k:7334",
  314. "1:2:3:4:5:6:7:8:9",
  315. "1::2::3",
  316. "1:::3:4:5",
  317. "1:2:3::4:5:6:7:8:9",
  318. # Invalid data
  319. "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX",
  320. # Too many components
  321. "1111:2222:3333:4444:5555:6666:7777:8888:9999",
  322. "1111:2222:3333:4444:5555:6666:7777:8888::",
  323. "::2222:3333:4444:5555:6666:7777:8888:9999",
  324. # Too few components
  325. "1111:2222:3333:4444:5555:6666:7777",
  326. "1111:2222:3333:4444:5555:6666",
  327. "1111:2222:3333:4444:5555",
  328. "1111:2222:3333:4444",
  329. "1111:2222:3333",
  330. "1111:2222",
  331. "1111",
  332. # Missing :
  333. "11112222:3333:4444:5555:6666:7777:8888",
  334. "1111:22223333:4444:5555:6666:7777:8888",
  335. "1111:2222:33334444:5555:6666:7777:8888",
  336. "1111:2222:3333:44445555:6666:7777:8888",
  337. "1111:2222:3333:4444:55556666:7777:8888",
  338. "1111:2222:3333:4444:5555:66667777:8888",
  339. "1111:2222:3333:4444:5555:6666:77778888",
  340. # Missing : intended for ::
  341. "1111:2222:3333:4444:5555:6666:7777:8888:",
  342. "1111:2222:3333:4444:5555:6666:7777:",
  343. "1111:2222:3333:4444:5555:6666:",
  344. "1111:2222:3333:4444:5555:",
  345. "1111:2222:3333:4444:",
  346. "1111:2222:3333:",
  347. "1111:2222:",
  348. "1111:",
  349. ":",
  350. ":8888",
  351. ":7777:8888",
  352. ":6666:7777:8888",
  353. ":5555:6666:7777:8888",
  354. ":4444:5555:6666:7777:8888",
  355. ":3333:4444:5555:6666:7777:8888",
  356. ":2222:3333:4444:5555:6666:7777:8888",
  357. ":1111:2222:3333:4444:5555:6666:7777:8888",
  358. # :::
  359. ":::2222:3333:4444:5555:6666:7777:8888",
  360. "1111:::3333:4444:5555:6666:7777:8888",
  361. "1111:2222:::4444:5555:6666:7777:8888",
  362. "1111:2222:3333:::5555:6666:7777:8888",
  363. "1111:2222:3333:4444:::6666:7777:8888",
  364. "1111:2222:3333:4444:5555:::7777:8888",
  365. "1111:2222:3333:4444:5555:6666:::8888",
  366. "1111:2222:3333:4444:5555:6666:7777:::",
  367. # Double ::",
  368. "::2222::4444:5555:6666:7777:8888",
  369. "::2222:3333::5555:6666:7777:8888",
  370. "::2222:3333:4444::6666:7777:8888",
  371. "::2222:3333:4444:5555::7777:8888",
  372. "::2222:3333:4444:5555:7777::8888",
  373. "::2222:3333:4444:5555:7777:8888::",
  374. "1111::3333::5555:6666:7777:8888",
  375. "1111::3333:4444::6666:7777:8888",
  376. "1111::3333:4444:5555::7777:8888",
  377. "1111::3333:4444:5555:6666::8888",
  378. "1111::3333:4444:5555:6666:7777::",
  379. "1111:2222::4444::6666:7777:8888",
  380. "1111:2222::4444:5555::7777:8888",
  381. "1111:2222::4444:5555:6666::8888",
  382. "1111:2222::4444:5555:6666:7777::",
  383. "1111:2222:3333::5555::7777:8888",
  384. "1111:2222:3333::5555:6666::8888",
  385. "1111:2222:3333::5555:6666:7777::",
  386. "1111:2222:3333:4444::6666::8888",
  387. "1111:2222:3333:4444::6666:7777::",
  388. "1111:2222:3333:4444:5555::7777::",
  389. # Too many components"
  390. "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",
  391. "1111:2222:3333:4444:5555:6666:7777:1.2.3.4",
  392. "1111:2222:3333:4444:5555:6666::1.2.3.4",
  393. "::2222:3333:4444:5555:6666:7777:1.2.3.4",
  394. "1111:2222:3333:4444:5555:6666:1.2.3.4.5",
  395. # Too few components
  396. "1111:2222:3333:4444:5555:1.2.3.4",
  397. "1111:2222:3333:4444:1.2.3.4",
  398. "1111:2222:3333:1.2.3.4",
  399. "1111:2222:1.2.3.4",
  400. "1111:1.2.3.4",
  401. # Missing :
  402. "11112222:3333:4444:5555:6666:1.2.3.4",
  403. "1111:22223333:4444:5555:6666:1.2.3.4",
  404. "1111:2222:33334444:5555:6666:1.2.3.4",
  405. "1111:2222:3333:44445555:6666:1.2.3.4",
  406. "1111:2222:3333:4444:55556666:1.2.3.4",
  407. "1111:2222:3333:4444:5555:66661.2.3.4",
  408. # Missing .
  409. "1111:2222:3333:4444:5555:6666:255255.255.255",
  410. "1111:2222:3333:4444:5555:6666:255.255255.255",
  411. "1111:2222:3333:4444:5555:6666:255.255.255255",
  412. # Missing : intended for ::
  413. ":1.2.3.4",
  414. ":6666:1.2.3.4",
  415. ":5555:6666:1.2.3.4",
  416. ":4444:5555:6666:1.2.3.4",
  417. ":3333:4444:5555:6666:1.2.3.4",
  418. ":2222:3333:4444:5555:6666:1.2.3.4",
  419. ":1111:2222:3333:4444:5555:6666:1.2.3.4",
  420. # :::
  421. ":::2222:3333:4444:5555:6666:1.2.3.4",
  422. "1111:::3333:4444:5555:6666:1.2.3.4",
  423. "1111:2222:::4444:5555:6666:1.2.3.4",
  424. "1111:2222:3333:::5555:6666:1.2.3.4",
  425. "1111:2222:3333:4444:::6666:1.2.3.4",
  426. "1111:2222:3333:4444:5555:::1.2.3.4",
  427. # Double ::
  428. "::2222::4444:5555:6666:1.2.3.4",
  429. "::2222:3333::5555:6666:1.2.3.4",
  430. "::2222:3333:4444::6666:1.2.3.4",
  431. "::2222:3333:4444:5555::1.2.3.4",
  432. "1111::3333::5555:6666:1.2.3.4",
  433. "1111::3333:4444::6666:1.2.3.4",
  434. "1111::3333:4444:5555::1.2.3.4",
  435. "1111:2222::4444::6666:1.2.3.4",
  436. "1111:2222::4444:5555::1.2.3.4",
  437. "1111:2222:3333::5555::1.2.3.4",
  438. # Missing parts
  439. "::.",
  440. "::..",
  441. "::...",
  442. "::1...",
  443. "::1.2..",
  444. "::1.2.3.",
  445. "::.2..",
  446. "::.2.3.",
  447. "::.2.3.4",
  448. "::..3.",
  449. "::..3.4",
  450. "::...4",
  451. # Extra : in front
  452. ":1111:2222:3333:4444:5555:6666:7777::",
  453. ":1111:2222:3333:4444:5555:6666::",
  454. ":1111:2222:3333:4444:5555::",
  455. ":1111:2222:3333:4444::",
  456. ":1111:2222:3333::",
  457. ":1111:2222::",
  458. ":1111::",
  459. ":::",
  460. ":1111:2222:3333:4444:5555:6666::8888",
  461. ":1111:2222:3333:4444:5555::8888",
  462. ":1111:2222:3333:4444::8888",
  463. ":1111:2222:3333::8888",
  464. ":1111:2222::8888",
  465. ":1111::8888",
  466. ":::8888",
  467. ":1111:2222:3333:4444:5555::7777:8888",
  468. ":1111:2222:3333:4444::7777:8888",
  469. ":1111:2222:3333::7777:8888",
  470. ":1111:2222::7777:8888",
  471. ":1111::7777:8888",
  472. ":::7777:8888",
  473. ":1111:2222:3333:4444::6666:7777:8888",
  474. ":1111:2222:3333::6666:7777:8888",
  475. ":1111:2222::6666:7777:8888",
  476. ":1111::6666:7777:8888",
  477. ":::6666:7777:8888",
  478. ":1111:2222:3333::5555:6666:7777:8888",
  479. ":1111:2222::5555:6666:7777:8888",
  480. ":1111::5555:6666:7777:8888",
  481. ":::5555:6666:7777:8888",
  482. ":1111:2222::4444:5555:6666:7777:8888",
  483. ":1111::4444:5555:6666:7777:8888",
  484. ":::4444:5555:6666:7777:8888",
  485. ":1111::3333:4444:5555:6666:7777:8888",
  486. ":::3333:4444:5555:6666:7777:8888",
  487. ":::2222:3333:4444:5555:6666:7777:8888",
  488. ":1111:2222:3333:4444:5555:6666:1.2.3.4",
  489. ":1111:2222:3333:4444:5555::1.2.3.4",
  490. ":1111:2222:3333:4444::1.2.3.4",
  491. ":1111:2222:3333::1.2.3.4",
  492. ":1111:2222::1.2.3.4",
  493. ":1111::1.2.3.4",
  494. ":::1.2.3.4",
  495. ":1111:2222:3333:4444::6666:1.2.3.4",
  496. ":1111:2222:3333::6666:1.2.3.4",
  497. ":1111:2222::6666:1.2.3.4",
  498. ":1111::6666:1.2.3.4",
  499. ":::6666:1.2.3.4",
  500. ":1111:2222:3333::5555:6666:1.2.3.4",
  501. ":1111:2222::5555:6666:1.2.3.4",
  502. ":1111::5555:6666:1.2.3.4",
  503. ":::5555:6666:1.2.3.4",
  504. ":1111:2222::4444:5555:6666:1.2.3.4",
  505. ":1111::4444:5555:6666:1.2.3.4",
  506. ":::4444:5555:6666:1.2.3.4",
  507. ":1111::3333:4444:5555:6666:1.2.3.4",
  508. ":::2222:3333:4444:5555:6666:1.2.3.4",
  509. # Extra : at end
  510. "1111:2222:3333:4444:5555:6666:7777:::",
  511. "1111:2222:3333:4444:5555:6666:::",
  512. "1111:2222:3333:4444:5555:::",
  513. "1111:2222:3333:4444:::",
  514. "1111:2222:3333:::",
  515. "1111:2222:::",
  516. "1111:::",
  517. ":::",
  518. "1111:2222:3333:4444:5555:6666::8888:",
  519. "1111:2222:3333:4444:5555::8888:",
  520. "1111:2222:3333:4444::8888:",
  521. "1111:2222:3333::8888:",
  522. "1111:2222::8888:",
  523. "1111::8888:",
  524. "::8888:",
  525. "1111:2222:3333:4444:5555::7777:8888:",
  526. "1111:2222:3333:4444::7777:8888:",
  527. "1111:2222:3333::7777:8888:",
  528. "1111:2222::7777:8888:",
  529. "1111::7777:8888:",
  530. "::7777:8888:",
  531. "1111:2222:3333:4444::6666:7777:8888:",
  532. "1111:2222:3333::6666:7777:8888:",
  533. "1111:2222::6666:7777:8888:",
  534. "1111::6666:7777:8888:",
  535. "::6666:7777:8888:",
  536. "1111:2222:3333::5555:6666:7777:8888:",
  537. "1111:2222::5555:6666:7777:8888:",
  538. "1111::5555:6666:7777:8888:",
  539. "::5555:6666:7777:8888:",
  540. "1111:2222::4444:5555:6666:7777:8888:",
  541. "1111::4444:5555:6666:7777:8888:",
  542. "::4444:5555:6666:7777:8888:",
  543. "1111::3333:4444:5555:6666:7777:8888:",
  544. "::3333:4444:5555:6666:7777:8888:",
  545. "::2222:3333:4444:5555:6666:7777:8888:",
  546. ].each do |ip|
  547. it "should reject #{ip.inspect} as an IPv6 address" do
  548. expect { @class.new(:name => "foo", :ip => ip) }.to raise_error
  549. end
  550. end
  551. it "should not accept spaces in resourcename" do
  552. proc { @class.new(:name => "foo bar") }.should raise_error
  553. end
  554. it "should not accept host_aliases with spaces" do
  555. proc { @class.new(:name => "foo", :host_aliases => [ 'well_formed', 'not wellformed' ]) }.should raise_error
  556. end
  557. it "should not accept empty host_aliases" do
  558. proc { @class.new(:name => "foo", :host_aliases => ['alias1','']) }.should raise_error
  559. end
  560. end
  561. describe "when syncing" do
  562. it "should send the first value to the provider for ip property" do
  563. @ip = @class.attrclass(:ip).new(:resource => @resource, :should => %w{192.168.0.1 192.168.0.2})
  564. @ip.sync
  565. @provider.ip.should == '192.168.0.1'
  566. end
  567. it "should send the first value to the provider for comment property" do
  568. @comment = @class.attrclass(:comment).new(:resource => @resource, :should => %w{Bazinga Notme})
  569. @comment.sync
  570. @provider.comment.should == 'Bazinga'
  571. end
  572. it "should send the joined array to the provider for host_alias" do
  573. @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
  574. @host_aliases.sync
  575. @provider.host_aliases.should == 'foo bar'
  576. end
  577. it "should also use the specified delimiter for joining" do
  578. @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
  579. @host_aliases.stubs(:delimiter).returns "\t"
  580. @host_aliases.sync
  581. @provider.host_aliases.should == "foo\tbar"
  582. end
  583. it "should care about the order of host_aliases" do
  584. @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
  585. @host_aliases.insync?(%w{foo bar}).should == true
  586. @host_aliases.insync?(%w{bar foo}).should == false
  587. end
  588. it "should not consider aliases to be in sync if should is a subset of current" do
  589. @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
  590. @host_aliases.insync?(%w{foo bar anotherone}).should == false
  591. end
  592. end
  593. end