PageRenderTime 25ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/puphpet/puppet/modules/firewall/spec/unit/puppet/util/ipcidr_spec.rb

https://bitbucket.org/joshcrawmer4/php-contact-form
Ruby | 96 lines | 67 code | 27 blank | 2 comment | 3 complexity | ca149e92bb80ed7b45ac7db1d5326a78 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, MIT, GPL-2.0
  1. require 'spec_helper'
  2. require 'puppet/util/ipcidr'
  3. describe 'Puppet::Util::IPCidr' do
  4. describe 'ipv4 address' do
  5. subject { ipaddr }
  6. let(:ipaddr) { Puppet::Util::IPCidr.new('96.126.112.51') }
  7. it { expect(subject.cidr).to eql '96.126.112.51/32' }
  8. it { expect(subject.prefixlen).to be 32 }
  9. it { expect(subject.netmask).to eql '255.255.255.255' }
  10. end
  11. describe 'single ipv4 address with cidr' do
  12. subject { ipcidr }
  13. let(:ipcidr) { Puppet::Util::IPCidr.new('96.126.112.51/32') }
  14. it { expect(subject.cidr).to eql '96.126.112.51/32' }
  15. it { expect(subject.prefixlen).to be 32 }
  16. it { expect(subject.netmask).to eql '255.255.255.255' }
  17. end
  18. describe 'ipv4 address range with cidr' do
  19. subject { ipcidr }
  20. let(:ipcidr) { Puppet::Util::IPCidr.new('96.126.112.0/24') }
  21. it { expect(subject.cidr).to eql '96.126.112.0/24' }
  22. it { expect(subject.prefixlen).to be 24 }
  23. it { expect(subject.netmask).to eql '255.255.255.0' }
  24. end
  25. # https://tickets.puppetlabs.com/browse/MODULES-3215
  26. describe 'ipv4 address range with invalid cidr' do
  27. subject { ipcidr }
  28. let(:ipcidr) { Puppet::Util::IPCidr.new('96.126.112.20/24') }
  29. specify { subject.cidr.should == '96.126.112.0/24' } # .20 is expected to
  30. # be silently dropped.
  31. specify { subject.prefixlen.should == 24 }
  32. specify { subject.netmask.should == '255.255.255.0' }
  33. end
  34. describe 'ipv4 open range with cidr' do
  35. subject { ipcidr }
  36. let(:ipcidr) { Puppet::Util::IPCidr.new('0.0.0.0/0') }
  37. it { expect(subject.cidr).to eql '0.0.0.0/0' }
  38. it { expect(subject.prefixlen).to be 0 }
  39. it { expect(subject.netmask).to eql '0.0.0.0' }
  40. end
  41. describe 'ipv6 address' do
  42. subject { ipaddr }
  43. let(:ipaddr) { Puppet::Util::IPCidr.new('2001:db8:85a3:0:0:8a2e:370:7334') }
  44. it { expect(subject.cidr).to eql '2001:db8:85a3::8a2e:370:7334/128' }
  45. it { expect(subject.prefixlen).to be 128 }
  46. it { expect(subject.netmask).to eql 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' }
  47. end
  48. describe 'single ipv6 addr with cidr' do
  49. subject { ipaddr }
  50. let(:ipaddr) { Puppet::Util::IPCidr.new('2001:db8:85a3:0:0:8a2e:370:7334/128') }
  51. it { expect(subject.cidr).to eql '2001:db8:85a3::8a2e:370:7334/128' }
  52. it { expect(subject.prefixlen).to be 128 }
  53. it { expect(subject.netmask).to eql 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' }
  54. end
  55. describe 'ipv6 addr range with cidr' do
  56. subject { ipaddr }
  57. let(:ipaddr) { Puppet::Util::IPCidr.new('2001:db8:1234::/48') }
  58. it { expect(subject.cidr).to eql '2001:db8:1234::/48' }
  59. it { expect(subject.prefixlen).to be 48 }
  60. it { expect(subject.netmask).to eql 'ffff:ffff:ffff:0000:0000:0000:0000:0000' }
  61. end
  62. describe 'ipv6 open range with cidr' do
  63. subject { ipaddr }
  64. let(:ipaddr) { Puppet::Util::IPCidr.new('::/0') }
  65. it { expect(subject.cidr).to eql '::/0' }
  66. it { expect(subject.prefixlen).to be 0 }
  67. it { expect(subject.netmask).to eql '0000:0000:0000:0000:0000:0000:0000:0000' }
  68. end
  69. end