ronin 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +32 -0
  4. data/.gitignore +7 -7
  5. data/.ruby-version +1 -0
  6. data/COPYING.txt +3 -3
  7. data/ChangeLog.md +25 -11
  8. data/Gemfile +21 -20
  9. data/README.md +102 -81
  10. data/Rakefile +4 -5
  11. data/bin/ronin +7 -12
  12. data/bin/ronin-campaigns +7 -12
  13. data/bin/ronin-console +7 -12
  14. data/bin/ronin-creds +7 -12
  15. data/bin/ronin-database +7 -12
  16. data/bin/ronin-emails +7 -12
  17. data/bin/ronin-exec +7 -12
  18. data/bin/ronin-fuzzer +7 -12
  19. data/bin/ronin-help +7 -12
  20. data/bin/ronin-hosts +7 -12
  21. data/bin/ronin-install +7 -12
  22. data/bin/ronin-ips +7 -12
  23. data/bin/ronin-net-proxy +7 -12
  24. data/bin/ronin-repos +7 -12
  25. data/bin/ronin-uninstall +7 -12
  26. data/bin/ronin-update +7 -12
  27. data/bin/ronin-urls +7 -12
  28. data/bin/ronin-wordlist +7 -12
  29. data/gemspec.yml +8 -8
  30. data/lib/bond/completions/ronin.rb +23 -23
  31. data/lib/ronin.rb +3 -3
  32. data/lib/ronin/address.rb +6 -7
  33. data/lib/ronin/arch.rb +3 -3
  34. data/lib/ronin/author.rb +5 -7
  35. data/lib/ronin/auto_load.rb +5 -5
  36. data/lib/ronin/bootstrap.rb +3 -3
  37. data/lib/ronin/campaign.rb +3 -3
  38. data/lib/ronin/config.rb +5 -7
  39. data/lib/ronin/credential.rb +3 -3
  40. data/lib/ronin/database.rb +3 -3
  41. data/lib/ronin/database/database.rb +8 -12
  42. data/lib/ronin/database/exceptions.rb +3 -3
  43. data/lib/ronin/database/exceptions/invalid_config.rb +3 -3
  44. data/lib/ronin/database/exceptions/unknown_repository.rb +3 -3
  45. data/lib/ronin/database/migrations.rb +3 -3
  46. data/lib/ronin/database/migrations/1.0.0.rb +3 -3
  47. data/lib/ronin/database/migrations/1.1.0.rb +3 -3
  48. data/lib/ronin/database/migrations/exceptions.rb +3 -3
  49. data/lib/ronin/database/migrations/exceptions/duplicate_migration.rb +3 -3
  50. data/lib/ronin/database/migrations/exceptions/unknown_migration.rb +3 -3
  51. data/lib/ronin/database/migrations/graph.rb +3 -3
  52. data/lib/ronin/database/migrations/migration.rb +3 -3
  53. data/lib/ronin/database/migrations/migrations.rb +3 -3
  54. data/lib/ronin/email_address.rb +5 -7
  55. data/lib/ronin/environment.rb +3 -3
  56. data/lib/ronin/exceptions.rb +3 -3
  57. data/lib/ronin/exceptions/duplicate_repository.rb +3 -3
  58. data/lib/ronin/exceptions/repository_not_found.rb +3 -3
  59. data/lib/ronin/host_name.rb +3 -3
  60. data/lib/ronin/host_name_ip_address.rb +3 -3
  61. data/lib/ronin/installation.rb +5 -7
  62. data/lib/ronin/ip_address.rb +6 -8
  63. data/lib/ronin/ip_address_mac_address.rb +3 -3
  64. data/lib/ronin/license.rb +6 -6
  65. data/lib/ronin/mac_address.rb +3 -3
  66. data/lib/ronin/model.rb +3 -3
  67. data/lib/ronin/model/has_authors.rb +3 -3
  68. data/lib/ronin/model/has_description.rb +3 -3
  69. data/lib/ronin/model/has_license.rb +3 -3
  70. data/lib/ronin/model/has_name.rb +3 -3
  71. data/lib/ronin/model/has_title.rb +3 -3
  72. data/lib/ronin/model/has_unique_name.rb +5 -7
  73. data/lib/ronin/model/has_version.rb +3 -3
  74. data/lib/ronin/model/importable.rb +3 -3
  75. data/lib/ronin/model/model.rb +7 -8
  76. data/lib/ronin/model/types.rb +3 -3
  77. data/lib/ronin/model/types/description.rb +9 -12
  78. data/lib/ronin/open_port.rb +5 -7
  79. data/lib/ronin/organization.rb +3 -3
  80. data/lib/ronin/os.rb +5 -7
  81. data/lib/ronin/os_guess.rb +3 -3
  82. data/lib/ronin/password.rb +3 -3
  83. data/lib/ronin/port.rb +3 -3
  84. data/lib/ronin/repositories.rb +3 -3
  85. data/lib/ronin/repository.rb +3 -3
  86. data/lib/ronin/ronin.rb +3 -3
  87. data/lib/ronin/script.rb +3 -3
  88. data/lib/ronin/script/buildable.rb +3 -3
  89. data/lib/ronin/script/deployable.rb +3 -3
  90. data/lib/ronin/script/exceptions.rb +3 -3
  91. data/lib/ronin/script/exceptions/build_failed.rb +3 -3
  92. data/lib/ronin/script/exceptions/deploy_failed.rb +3 -3
  93. data/lib/ronin/script/exceptions/exception.rb +3 -3
  94. data/lib/ronin/script/exceptions/not_built.rb +3 -3
  95. data/lib/ronin/script/exceptions/test_failed.rb +3 -3
  96. data/lib/ronin/script/path.rb +3 -3
  97. data/lib/ronin/script/script.rb +3 -3
  98. data/lib/ronin/script/testable.rb +3 -3
  99. data/lib/ronin/service.rb +3 -3
  100. data/lib/ronin/service_credential.rb +3 -3
  101. data/lib/ronin/software.rb +3 -3
  102. data/lib/ronin/spec/database.rb +27 -21
  103. data/lib/ronin/target.rb +3 -3
  104. data/lib/ronin/tcp_port.rb +3 -3
  105. data/lib/ronin/udp_port.rb +3 -3
  106. data/lib/ronin/ui.rb +3 -3
  107. data/lib/ronin/ui/cli.rb +3 -3
  108. data/lib/ronin/ui/cli/class_command.rb +14 -7
  109. data/lib/ronin/ui/cli/cli.rb +5 -5
  110. data/lib/ronin/ui/cli/command.rb +5 -7
  111. data/lib/ronin/ui/cli/commands.rb +3 -3
  112. data/lib/ronin/ui/cli/commands/campaigns.rb +5 -7
  113. data/lib/ronin/ui/cli/commands/console.rb +3 -3
  114. data/lib/ronin/ui/cli/commands/creds.rb +3 -3
  115. data/lib/ronin/ui/cli/commands/database.rb +3 -3
  116. data/lib/ronin/ui/cli/commands/emails.rb +3 -3
  117. data/lib/ronin/ui/cli/commands/exec.rb +3 -3
  118. data/lib/ronin/ui/cli/commands/fuzzer.rb +16 -16
  119. data/lib/ronin/ui/cli/commands/help.rb +3 -3
  120. data/lib/ronin/ui/cli/commands/hosts.rb +5 -7
  121. data/lib/ronin/ui/cli/commands/install.rb +7 -11
  122. data/lib/ronin/ui/cli/commands/ips.rb +5 -7
  123. data/lib/ronin/ui/cli/commands/net/proxy.rb +19 -12
  124. data/lib/ronin/ui/cli/commands/repos.rb +3 -3
  125. data/lib/ronin/ui/cli/commands/uninstall.rb +3 -3
  126. data/lib/ronin/ui/cli/commands/update.rb +3 -3
  127. data/lib/ronin/ui/cli/commands/urls.rb +3 -3
  128. data/lib/ronin/ui/cli/commands/wordlist.rb +3 -3
  129. data/lib/ronin/ui/cli/exceptions.rb +3 -3
  130. data/lib/ronin/ui/cli/exceptions/unknown_command.rb +3 -3
  131. data/lib/ronin/ui/cli/model_command.rb +6 -9
  132. data/lib/ronin/ui/cli/printing.rb +3 -3
  133. data/lib/ronin/ui/cli/resources_command.rb +7 -11
  134. data/lib/ronin/ui/cli/script_command.rb +5 -10
  135. data/lib/ronin/ui/console.rb +3 -3
  136. data/lib/ronin/ui/console/commands.rb +3 -3
  137. data/lib/ronin/ui/console/console.rb +3 -3
  138. data/lib/ronin/ui/console/context.rb +3 -3
  139. data/lib/ronin/ui/console/shell.rb +3 -3
  140. data/lib/ronin/url.rb +5 -7
  141. data/lib/ronin/url_query_param.rb +3 -3
  142. data/lib/ronin/url_query_param_name.rb +6 -6
  143. data/lib/ronin/url_scheme.rb +4 -4
  144. data/lib/ronin/user_name.rb +3 -3
  145. data/lib/ronin/vendor.rb +3 -3
  146. data/lib/ronin/version.rb +5 -5
  147. data/lib/ronin/web_credential.rb +5 -7
  148. data/man/ronin-campaigns.1.md +20 -20
  149. data/man/ronin-console.1.md +17 -17
  150. data/man/ronin-creds.1.md +16 -16
  151. data/man/ronin-database.1.md +23 -23
  152. data/man/ronin-emails.1.md +18 -18
  153. data/man/ronin-exec.1.md +11 -11
  154. data/man/ronin-fuzzer.1.md +23 -23
  155. data/man/ronin-help.1.md +5 -5
  156. data/man/ronin-hosts.1.md +20 -20
  157. data/man/ronin-install.1.md +18 -18
  158. data/man/ronin-ips.1.md +21 -21
  159. data/man/ronin-net-proxy.1.md +24 -24
  160. data/man/ronin-repos.1.md +18 -18
  161. data/man/ronin-uninstall.1.md +14 -14
  162. data/man/ronin-update.1.md +14 -14
  163. data/man/ronin-urls.1.md +22 -22
  164. data/man/ronin-wordlist.1.md +14 -13
  165. data/man/ronin.1.md +1 -1
  166. data/spec/arch_spec.rb +59 -46
  167. data/spec/author_spec.rb +14 -14
  168. data/spec/campaign_spec.rb +8 -0
  169. data/spec/credential_spec.rb +11 -8
  170. data/spec/database_spec.rb +6 -6
  171. data/spec/email_address_spec.rb +23 -20
  172. data/spec/host_name_spec.rb +24 -22
  173. data/spec/installation_spec.rb +6 -6
  174. data/spec/ip_address_spec.rb +31 -26
  175. data/spec/license_spec.rb +15 -9
  176. data/spec/mac_address_spec.rb +17 -8
  177. data/spec/model/has_authors_spec.rb +56 -37
  178. data/spec/model/has_description_spec.rb +36 -23
  179. data/spec/model/has_license_spec.rb +38 -28
  180. data/spec/model/has_name_spec.rb +36 -19
  181. data/spec/model/has_title_spec.rb +27 -14
  182. data/spec/model/has_version_spec.rb +64 -35
  183. data/spec/model/model_spec.rb +57 -33
  184. data/spec/model/models/{basic_model.rb → base_model.rb} +1 -1
  185. data/spec/model/models/{custom_model.rb → inherited_model.rb} +2 -3
  186. data/spec/os_spec.rb +24 -20
  187. data/spec/password_spec.rb +17 -9
  188. data/spec/port_spec.rb +30 -22
  189. data/spec/repository_spec.rb +59 -60
  190. data/spec/ronin_spec.rb +4 -4
  191. data/spec/script/buildable_spec.rb +8 -8
  192. data/spec/script/deployable_spec.rb +7 -7
  193. data/spec/script/path_spec.rb +42 -40
  194. data/spec/script/script_spec.rb +23 -23
  195. data/spec/script/testable_spec.rb +20 -20
  196. data/spec/service_spec.rb +14 -8
  197. data/spec/software_spec.rb +30 -17
  198. data/spec/spec_helper.rb +4 -4
  199. data/spec/ui/cli/classes/test_command.rb +2 -4
  200. data/spec/ui/cli/cli_spec.rb +5 -5
  201. data/spec/ui/cli/command_spec.rb +34 -30
  202. data/spec/url_query_param_spec.rb +23 -14
  203. data/spec/url_scheme_spec.rb +12 -9
  204. data/spec/url_spec.rb +64 -61
  205. data/spec/vendor_spec.rb +15 -8
  206. metadata +122 -150
  207. data/.gemtest +0 -0
@@ -1,5 +1,13 @@
1
1
  require 'spec_helper'
2
+
2
3
  require 'ronin/campaign'
3
4
 
4
5
  describe Campaign do
6
+ describe "targets?" do
7
+ pending "needs specs"
8
+ end
9
+
10
+ describe "#target!" do
11
+ pending "needs specs"
12
+ end
5
13
  end
@@ -1,26 +1,29 @@
1
1
  require 'spec_helper'
2
+
2
3
  require 'ronin/credential'
3
4
 
4
5
  describe Credential do
5
- let(:name) { 'alice' }
6
- let(:secret) { 'secret' }
6
+ let(:name) { 'alice' }
7
+ let(:password) { 'secret' }
7
8
 
8
9
  subject do
9
- Credential.new(
10
+ described_class.new(
10
11
  :user_name => {:name => name},
11
- :password => {:clear_text => secret}
12
+ :password => {:clear_text => password}
12
13
  )
13
14
  end
14
15
 
15
16
  it "should provide the user-name" do
16
- subject.user.should == name
17
+ expect(subject.user).to eq(name)
17
18
  end
18
19
 
19
20
  it "should provide the clear-text password" do
20
- subject.clear_text.should == secret
21
+ expect(subject.clear_text).to eq(password)
21
22
  end
22
23
 
23
- it "should be convertable to a String" do
24
- subject.to_s.should == "#{name}:#{secret}"
24
+ describe "#to_s" do
25
+ it "should include the user name and password" do
26
+ expect(subject.to_s).to eq("#{name}:#{password}")
27
+ end
25
28
  end
26
29
  end
@@ -4,25 +4,25 @@ require 'ronin/database'
4
4
  describe Database do
5
5
  describe "repositories" do
6
6
  it "should not be empty" do
7
- subject.repositories.should_not be_empty
7
+ expect(subject.repositories).not_to be_empty
8
8
  end
9
9
 
10
10
  it "should have a ':default' repository" do
11
- subject.repositories[:default].should_not be_nil
11
+ expect(subject.repositories[:default]).not_to be_nil
12
12
  end
13
13
  end
14
14
 
15
15
  it "shold determine if a repository is defined" do
16
- subject.repository?(:default).should == true
16
+ expect(subject.repository?(:default)).to be(true)
17
17
  end
18
18
 
19
19
  it "should determine when a repository is setup" do
20
- subject.setup?(:default).should == true
20
+ expect(subject.setup?(:default)).to be(true)
21
21
  end
22
22
 
23
23
  it "should not allow switching to unknown repositories" do
24
- lambda {
24
+ expect {
25
25
  subject.repository(:foo) { }
26
- }.should raise_error(Database::UnknownRepository)
26
+ }.to raise_error(Database::UnknownRepository)
27
27
  end
28
28
  end
@@ -1,13 +1,14 @@
1
1
  require 'spec_helper'
2
+
2
3
  require 'ronin/email_address'
3
4
 
4
5
  describe EmailAddress do
5
- let(:user) { 'joe' }
6
- let(:host) { 'example.com' }
6
+ let(:user) { 'joe' }
7
+ let(:host) { 'example.com' }
7
8
  let(:email) { "#{user}@#{host}" }
8
9
 
9
10
  subject {
10
- EmailAddress.new(
11
+ described_class.new(
11
12
  :user_name => {:name => user},
12
13
  :host_name => {:address => host}
13
14
  )
@@ -18,10 +19,10 @@ describe EmailAddress do
18
19
 
19
20
  let(:email1) { subject.parse('foo@bar.com') }
20
21
  let(:email2) { subject.parse('foo!bar@baz.com') }
21
- let(:text) { "To: #{email1}, #{email2}." }
22
+ let(:text) { "To: #{email1}, #{email2}." }
22
23
 
23
24
  it "should extract multiple email addresses from text" do
24
- subject.extract(text).should == [email1, email2]
25
+ expect(subject.extract(text)).to eq([email1, email2])
25
26
  end
26
27
 
27
28
  it "should yield the extracted email addresses if a block is given" do
@@ -29,23 +30,23 @@ describe EmailAddress do
29
30
 
30
31
  subject.extract(text) { |email| emails << email }
31
32
 
32
- emails.should == [email1, email2]
33
+ expect(emails).to eq([email1, email2])
33
34
  end
34
35
  end
35
36
 
36
37
  describe "parse" do
37
38
  it "should parse email addresses" do
38
- email_address = EmailAddress.parse(email)
39
+ email_address = described_class.parse(email)
39
40
 
40
- email_address.user_name.name.should == user
41
- email_address.host_name.address.should == host
41
+ expect(email_address.user_name.name).to eq(user)
42
+ expect(email_address.host_name.address).to eq(host)
42
43
  end
43
44
 
44
45
  it "should strip whitespace from emails" do
45
- email_address = EmailAddress.parse(" #{email} ")
46
+ email_address = described_class.parse(" #{email} ")
46
47
 
47
- email_address.user_name.name.should == user
48
- email_address.host_name.address.should == host
48
+ expect(email_address.user_name.name).to eq(user)
49
+ expect(email_address.host_name.address).to eq(host)
49
50
  end
50
51
  end
51
52
 
@@ -53,28 +54,30 @@ describe EmailAddress do
53
54
  it "should accept Strings" do
54
55
  email_address = described_class.from(email)
55
56
 
56
- email_address.user_name.name.should == user
57
- email_address.host_name.address.should == host
57
+ expect(email_address.user_name.name).to eq(user)
58
+ expect(email_address.host_name.address).to eq(host)
58
59
  end
59
60
 
60
61
  it "should accept URI::MailTo objects" do
61
62
  uri = URI("mailto:#{email}")
62
63
  email_address = described_class.from(uri)
63
64
 
64
- email_address.user_name.name.should == user
65
- email_address.host_name.address.should == host
65
+ expect(email_address.user_name.name).to eq(user)
66
+ expect(email_address.host_name.address).to eq(host)
66
67
  end
67
68
  end
68
69
 
69
70
  it "should provide the user-name" do
70
- subject.user.should == user
71
+ expect(subject.user).to eq(user)
71
72
  end
72
73
 
73
74
  it "should provide the host-name" do
74
- subject.host.should == host
75
+ expect(subject.host).to eq(host)
75
76
  end
76
77
 
77
- it "should convert to a String" do
78
- subject.to_s.should == email
78
+ describe "#to_s" do
79
+ it "should include the email address" do
80
+ expect(subject.to_s).to eq(email)
81
+ end
79
82
  end
80
83
  end
@@ -1,20 +1,23 @@
1
1
  require 'spec_helper'
2
+
2
3
  require 'ronin/host_name'
3
4
 
4
5
  describe HostName do
5
6
  let(:domain) { 'localhost' }
6
- let(:ip) { '127.0.0.1' }
7
+ let(:ip) { '127.0.0.1' }
7
8
 
8
- subject { HostName.new(:address => domain) }
9
+ subject { described_class.new(:address => domain) }
9
10
 
10
- it "should require an address" do
11
- host_name = HostName.new
11
+ describe "validations" do
12
+ it "should require an address" do
13
+ host_name = described_class.new
12
14
 
13
- host_name.should_not be_valid
15
+ expect(host_name).not_to be_valid
16
+ end
14
17
  end
15
18
 
16
19
  it "should alias #name to #address" do
17
- subject.name.should == subject.address
20
+ expect(subject.name).to eq(subject.address)
18
21
  end
19
22
 
20
23
  describe "extract" do
@@ -25,7 +28,7 @@ describe HostName do
25
28
  let(:text) { "Hosts: #{host1}, #{host2}." }
26
29
 
27
30
  it "should extract multiple host-names from text" do
28
- subject.extract(text).should == [host1, host2]
31
+ expect(subject.extract(text)).to eq([host1, host2])
29
32
  end
30
33
 
31
34
  it "should yield the extracted host-names if a block is given" do
@@ -33,58 +36,57 @@ describe HostName do
33
36
 
34
37
  subject.extract(text) { |host| hosts << host }
35
38
 
36
- hosts.should == [host1, host2]
39
+ expect(hosts).to eq([host1, host2])
37
40
  end
38
41
  end
39
42
 
40
43
  describe "lookup" do
41
- subject { HostName }
42
-
43
- let(:bad_ip) { '0.0.0.0' }
44
+ subject { described_class }
44
45
 
45
46
  it "should look up the host names for an IP Address" do
46
47
  host_names = subject.lookup(ip).map { |name| name.address }
47
48
 
48
- host_names.should include(domain)
49
+ expect(host_names).to include(domain)
49
50
  end
50
51
 
51
52
  it "should associate the host names with the original IP address" do
52
53
  host_names = subject.lookup(ip)
53
54
 
54
55
  host_names.each do |host|
55
- host.ip_addresses[0].address.should == ip
56
+ expect(host.ip_addresses[0].address).to eq(ip)
56
57
  end
57
58
  end
58
59
 
60
+ let(:bad_ip) { '0.0.0.0' }
61
+
59
62
  it "should return an empty Array for unknown host names" do
60
63
  host_names = subject.lookup(bad_ip)
61
64
 
62
- host_names.should be_empty
65
+ expect(host_names).to be_empty
63
66
  end
64
67
  end
65
68
 
66
69
  describe "#lookup!" do
67
- let(:bad_domain) { '.bad.domain.com.' }
68
-
69
70
  it "should look up the IP Addresses for the host name" do
70
71
  ips = subject.lookup!
71
72
 
72
- ips.should_not be_empty
73
- ips[0].address.should == ip
73
+ expect(ips.any? { |ip_address| ip_address.address == ip }).to be(true)
74
74
  end
75
75
 
76
76
  it "should associate the IP addresses with the original host name" do
77
77
  ips = subject.lookup!
78
78
 
79
- ips.each do |ip|
80
- ip.host_names[0].address.should == domain
79
+ ips.each do |ip_address|
80
+ expect(ip_address.host_names[0].address).to eq(domain)
81
81
  end
82
82
  end
83
83
 
84
+ let(:bad_domain) { 'foo' }
85
+
84
86
  it "should return an empty Array for unknown host names" do
85
- ips = HostName.new(:address => bad_domain).lookup!
87
+ ips = described_class.new(:address => bad_domain).lookup!
86
88
 
87
- ips.should be_empty
89
+ expect(ips).to be_empty
88
90
  end
89
91
  end
90
92
  end
@@ -3,11 +3,11 @@ require 'ronin/installation'
3
3
 
4
4
  describe Installation do
5
5
  it "should load the gemspec for the 'ronin' library" do
6
- subject.gems['ronin'].should_not be_nil
6
+ expect(subject.gems['ronin']).not_to be_nil
7
7
  end
8
8
 
9
9
  it "should provide the names of the installed Ronin libraries" do
10
- subject.libraries.should include('ronin')
10
+ expect(subject.libraries).to include('ronin')
11
11
  end
12
12
 
13
13
  let(:directory) { 'lib/ronin/ui/cli/commands/' }
@@ -17,11 +17,11 @@ describe Installation do
17
17
 
18
18
  describe "each_file" do
19
19
  it "should enumerate over the files which match a glob pattern" do
20
- subject.each_file(pattern).to_a.should =~ paths
20
+ expect(subject.each_file(pattern).to_a).to match_array(paths)
21
21
  end
22
22
 
23
23
  it "should return an Enumerator when no block is given" do
24
- subject.each_file(pattern).should respond_to(:each)
24
+ expect(subject.each_file(pattern)).to respond_to(:each)
25
25
  end
26
26
  end
27
27
 
@@ -30,11 +30,11 @@ describe Installation do
30
30
  let(:expected) { files }
31
31
 
32
32
  it "should enumerate over the files which match a glob pattern" do
33
- subject.each_file_in(directory,ext).to_a.should =~ expected
33
+ expect(subject.each_file_in(directory,ext).to_a).to match_array(expected)
34
34
  end
35
35
 
36
36
  it "should return an Enumerator when no block is given" do
37
- subject.each_file_in(directory,ext).should respond_to(:each)
37
+ expect(subject.each_file_in(directory,ext)).to respond_to(:each)
38
38
  end
39
39
  end
40
40
  end
@@ -1,27 +1,28 @@
1
1
  require 'spec_helper'
2
+
2
3
  require 'ronin/ip_address'
3
4
 
4
5
  describe IPAddress do
5
6
  let(:example_domain) { 'localhost' }
6
7
  let(:example_ip) { '127.0.0.1' }
7
8
 
8
- subject { IPAddress.new(:address => example_ip) }
9
+ subject { described_class.new(:address => example_ip) }
9
10
 
10
11
  it "should require an address" do
11
- ip_address = IPAddress.new
12
+ ip_address = described_class.new
12
13
 
13
- ip_address.should_not be_valid
14
+ expect(ip_address).not_to be_valid
14
15
  end
15
16
 
16
17
  describe "extract" do
17
- subject { IPAddress }
18
+ subject { described_class }
18
19
 
19
20
  let(:ip1) { subject.parse('127.0.0.1') }
20
21
  let(:ip2) { subject.parse('10.1.1.1') }
21
22
  let(:text) { "Hosts: #{ip1}, #{ip2}" }
22
23
 
23
24
  it "should extract multiple IP Addresses from text" do
24
- subject.extract(text).should == [ip1, ip2]
25
+ expect(subject.extract(text)).to eq([ip1, ip2])
25
26
  end
26
27
 
27
28
  it "should yield the extracted IPs if a block is given" do
@@ -29,44 +30,42 @@ describe IPAddress do
29
30
 
30
31
  subject.extract(text) { |ip| ip_addresses << ip }
31
32
 
32
- ip_addresses.should == [ip1, ip2]
33
+ expect(ip_addresses).to eq([ip1, ip2])
33
34
  end
34
35
  end
35
36
 
36
37
  describe "lookup" do
37
- subject { IPAddress }
38
-
39
- let(:bad_domain) { '.bad.domain.com.' }
38
+ subject { described_class }
40
39
 
41
40
  it "should lookup host-names to IP Addresses" do
42
41
  ip_addresses = subject.lookup(example_domain)
43
42
  addresses = ip_addresses.map { |ip| ip.address }
44
43
 
45
- addresses.should include(example_ip)
44
+ expect(addresses).to include(example_ip)
46
45
  end
47
46
 
48
47
  it "should associate the IP addresses with the original host name" do
49
48
  ip_addresses = subject.lookup(example_domain)
50
49
  host_names = ip_addresses.map { |ip| ip.host_names[0].address }
51
50
 
52
- host_names.should include(example_domain)
51
+ expect(host_names).to include(example_domain)
53
52
  end
54
53
 
54
+ let(:bad_domain) { 'foo' }
55
+
55
56
  it "should return an empty Array for unknown domain names" do
56
57
  ip_addresses = subject.lookup(bad_domain)
57
58
 
58
- ip_addresses.should be_empty
59
+ expect(ip_addresses).to be_empty
59
60
  end
60
61
  end
61
62
 
62
63
  describe "#lookup!" do
63
- let(:bad_ip) { '0.0.0.0' }
64
-
65
64
  it "should reverse lookup the host-name for an IP Address" do
66
65
  host_names = subject.lookup!
67
66
  addresses = host_names.map { |host_name| host_name.address }
68
67
 
69
- addresses.should include(example_domain)
68
+ expect(addresses).to include(example_domain)
70
69
  end
71
70
 
72
71
  it "should associate the host names with the original IP address" do
@@ -75,30 +74,36 @@ describe IPAddress do
75
74
  host_name.ip_addresses[0].address
76
75
  end
77
76
 
78
- ip_addresses.should include(subject)
77
+ expect(ip_addresses).to include(subject)
79
78
  end
80
79
 
80
+ let(:bad_ip) { '0.0.0.0' }
81
+
81
82
  it "should return an empty Array for unknown domain names" do
82
- ip_address = IPAddress.new(:address => bad_ip)
83
+ ip_address = described_class.new(:address => bad_ip)
83
84
  host_names = ip_address.lookup!
84
85
 
85
- host_names.should be_empty
86
+ expect(host_names).to be_empty
86
87
  end
87
88
  end
88
89
 
89
90
  describe "#version" do
90
- let(:ipv4) { IPAddress.new(:address => '127.0.0.1') }
91
- let(:ipv6) { IPAddress.new(:address => '::1') }
92
-
93
91
  it "should only accept 4 or 6" do
94
- ip_address = IPAddress.new(:address => '1.1.1.1', :version => 7)
92
+ ip_address = described_class.new(:address => '1.1.1.1', :version => 7)
93
+
94
+ expect(ip_address).not_to be_valid
95
+ end
96
+
97
+ context "with IPv4 address" do
98
+ subject { described_class.new(:address => '127.0.0.1') }
95
99
 
96
- ip_address.should_not be_valid
100
+ it { expect(subject.version).to be == 4 }
97
101
  end
98
102
 
99
- it "should default to the version of the address" do
100
- ipv4.version.should == 4
101
- ipv6.version.should == 6
103
+ context "with IPv6 address" do
104
+ subject { described_class.new(:address => '::1') }
105
+
106
+ it { expect(subject.version).to be == 6 }
102
107
  end
103
108
  end
104
109
  end