ruby-nmap 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ describe RunStat do
15
15
  subject { described_class.new(end_time,elapsed,summary,exit_status) }
16
16
 
17
17
  it "should convert the RunStat to a String" do
18
- subject.to_s.should == "#{end_time} #{elapsed} #{exit_status}"
18
+ expect(subject.to_s).to eq("#{end_time} #{elapsed} #{exit_status}")
19
19
  end
20
20
  end
21
21
  end
@@ -44,6 +44,7 @@
44
44
  <taskend task="NSE" time="1374390873"/>
45
45
  <host starttime="1374389727" endtime="1374390873"><status state="up" reason="reset"/>
46
46
  <address addr="74.207.244.221" addrtype="ipv4"/>
47
+ <address addr="08:00:27:7F:62:DC" addrtype="mac" vendor="Cadmus Computer Systems"/ >
47
48
  <hostnames>
48
49
  <hostname name="scanme.nmap.org" type="user"/>
49
50
  <hostname name="scanme.nmap.org" type="PTR"/>
@@ -9,12 +9,12 @@ describe Scan do
9
9
  subject { described_class.new(type,protocol) }
10
10
 
11
11
  it "should accept a type and protocol" do
12
- subject.type.should == type
13
- subject.protocol.should == protocol
12
+ expect(subject.type).to eq(type)
13
+ expect(subject.protocol).to eq(protocol)
14
14
  end
15
15
 
16
16
  it "should default services to []" do
17
- subject.services.should == []
17
+ expect(subject.services).to eq([])
18
18
  end
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ describe Scan do
22
22
  subject { described_class.new(type,protocol) }
23
23
 
24
24
  it "should include the type and protocol" do
25
- subject.to_s.should == "#{protocol} #{type}"
25
+ expect(subject.to_s).to eq("#{protocol} #{type}")
26
26
  end
27
27
  end
28
28
  end
@@ -19,17 +19,17 @@ describe ScanTask do
19
19
 
20
20
  describe "#duration" do
21
21
  it "should be > 0" do
22
- subject.duration.should > 0
22
+ expect(subject.duration).to be > 0
23
23
  end
24
24
 
25
25
  it "should be the time between the start_time and end_time" do
26
- (subject.start_time + subject.duration).should == subject.end_time
26
+ expect(subject.start_time + subject.duration).to eq(subject.end_time)
27
27
  end
28
28
  end
29
29
 
30
30
  describe "#to_s" do
31
31
  it "should include the start_time, name and extrainfo" do
32
- subject.to_s.should == "#{start_time}: #{name} (#{extrainfo})"
32
+ expect(subject.to_s).to eq("#{start_time}: #{name} (#{extrainfo})")
33
33
  end
34
34
  end
35
35
  end
@@ -18,7 +18,7 @@ describe Scanner do
18
18
  end
19
19
 
20
20
  it "should return the scanner command" do
21
- subject.to_s.should == "#{name} #{args}"
21
+ expect(subject.to_s).to eq("#{name} #{args}")
22
22
  end
23
23
  end
24
24
  end
@@ -4,7 +4,7 @@ shared_examples_for "#scripts" do
4
4
  describe "#scripts" do
5
5
  subject { super().scripts }
6
6
 
7
- it { should be_kind_of(Hash) }
8
- it { should_not be_empty }
7
+ it { is_expected.to be_kind_of(Hash) }
8
+ it { is_expected.not_to be_empty }
9
9
  end
10
10
  end
@@ -4,7 +4,9 @@ shared_examples_for "Sequence" do
4
4
  describe "#values" do
5
5
  subject { super().values }
6
6
 
7
- it { should have(6).items }
8
- it { should all_be_between(0,0xFFFFFFFF) }
7
+ it 'has 6 items' do
8
+ expect(subject.size).to eq(6)
9
+ end
10
+ it { is_expected.to all(be_between(0,0xFFFFFFFF)) }
9
11
  end
10
12
  end
@@ -9,67 +9,67 @@ describe Service do
9
9
 
10
10
  describe "#name" do
11
11
  it "should parse the name" do
12
- subject.name.should == 'ssh'
12
+ expect(subject.name).to eq('ssh')
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#ssl?" do
17
17
  it "should check the tunnel attribute" do
18
- pending "need a service that uses SSL"
18
+ skip "need a service that uses SSL"
19
19
  end
20
20
  end
21
21
 
22
22
  describe "#protocol" do
23
23
  it "should parse the proto attribute" do
24
- pending "need a service with the proto attribute"
24
+ skip "need a service with the proto attribute"
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#product" do
29
29
  it "should parse the product name attribute" do
30
- subject.product.should == 'OpenSSH'
30
+ expect(subject.product).to eq('OpenSSH')
31
31
  end
32
32
  end
33
33
 
34
34
  describe "#version" do
35
35
  it "should parse the version attribute" do
36
- subject.version.should == '5.3p1 Debian 3ubuntu7'
36
+ expect(subject.version).to eq('5.3p1 Debian 3ubuntu7')
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#extra_info" do
41
41
  it "should parse the extrainfo attribute" do
42
- subject.extra_info.should == 'protocol 2.0'
42
+ expect(subject.extra_info).to eq('protocol 2.0')
43
43
  end
44
44
  end
45
45
 
46
46
  describe "#hostname" do
47
47
  it "should parse the hostname attribute" do
48
- pending "need a service with the hostname attribute"
48
+ skip "need a service with the hostname attribute"
49
49
  end
50
50
  end
51
51
 
52
52
  describe "#os_type" do
53
53
  it "should parse the ostype attribute" do
54
- subject.os_type.should == 'Linux'
54
+ expect(subject.os_type).to eq('Linux')
55
55
  end
56
56
  end
57
57
 
58
58
  describe "#device_type" do
59
59
  it "should parse the devicetype attribute" do
60
- pending "need a service with the devicetype attribute"
60
+ skip "need a service with the devicetype attribute"
61
61
  end
62
62
  end
63
63
 
64
64
  describe "#fingerprint_method" do
65
65
  it "should parse the method attribute" do
66
- subject.fingerprint_method.should == :probed
66
+ expect(subject.fingerprint_method).to eq(:probed)
67
67
  end
68
68
  end
69
69
 
70
70
  describe "#confidence" do
71
71
  it "should parse the conf attribute" do
72
- subject.confidence.should be_between(0,10)
72
+ expect(subject.confidence).to be_between(0,10)
73
73
  end
74
74
  end
75
75
 
@@ -6,32 +6,6 @@ require 'nmap/version'
6
6
  require 'nmap/xml'
7
7
  include Nmap
8
8
 
9
- RSpec::Matchers.define :be_between do |min,max|
10
- match do |value|
11
- (value >= min) && (value <= max)
12
- end
13
- end
14
-
15
- RSpec::Matchers.define :all_be_between do |min,max|
16
- match do |values|
17
- values.all? { |value| (value >= min) && (value <= max) }
18
- end
19
- end
20
-
21
- RSpec::Matchers.define :be_one_of do |*values|
22
- match do |value|
23
- values.include?(value)
24
- end
25
-
26
- description { "be one of: #{expected.join(', ')}" }
27
- end
28
-
29
- RSpec::Matchers.define :all_be_kind_of do |base_class|
30
- match do |values|
31
- values.all? { |value| value.kind_of?(base_class) }
32
- end
33
- end
34
-
35
9
  RSpec.configure do |spec|
36
10
  spec.before(:all) do
37
11
  @xml = XML.new('spec/scan.xml')
@@ -9,7 +9,7 @@ describe Status do
9
9
  subject { described_class.new(state,reason) }
10
10
 
11
11
  it "should return the state" do
12
- subject.to_s.should == state.to_s
12
+ expect(subject.to_s).to eq(state.to_s)
13
13
  end
14
14
  end
15
15
  end
@@ -2,35 +2,35 @@ require 'spec_helper'
2
2
  require 'nmap/task'
3
3
 
4
4
  describe Task do
5
- describe "ports" do
5
+ describe "#ports=" do
6
6
  it "should ignore empty port Arrays" do
7
7
  subject.ports = []
8
8
 
9
- subject.arguments.should == []
9
+ expect(subject.arguments).to eq([])
10
10
  end
11
11
 
12
12
  it "should format a String of ports" do
13
13
  subject.ports = '80,21,25'
14
14
 
15
- subject.arguments.should == %w[-p 80,21,25]
15
+ expect(subject.arguments).to eq(%w[-p 80,21,25])
16
16
  end
17
17
 
18
18
  it "should format an Array of String ports" do
19
19
  subject.ports = %w[80 21 25]
20
20
 
21
- subject.arguments.should == %w[-p 80,21,25]
21
+ expect(subject.arguments).to eq(%w[-p 80,21,25])
22
22
  end
23
23
 
24
24
  it "should format an Array of Integer ports" do
25
25
  subject.ports = [80, 21, 25]
26
26
 
27
- subject.arguments.should == %w[-p 80,21,25]
27
+ expect(subject.arguments).to eq(%w[-p 80,21,25])
28
28
  end
29
29
 
30
30
  it "should format a Range of ports" do
31
31
  subject.ports = [80, 21..25]
32
32
 
33
- subject.arguments.should == %w[-p 80,21-25]
33
+ expect(subject.arguments).to eq(%w[-p 80,21-25])
34
34
  end
35
35
  end
36
36
  end
@@ -8,13 +8,13 @@ describe TcpSequence do
8
8
 
9
9
  describe "#index" do
10
10
  it "should parse the index" do
11
- subject.index.should be > 0
11
+ expect(subject.index).to be > 0
12
12
  end
13
13
  end
14
14
 
15
15
  describe "#description" do
16
16
  it "should parse the difficulty description" do
17
- subject.difficulty.should == "Good luck!"
17
+ expect(subject.difficulty).to eq("Good luck!")
18
18
  end
19
19
  end
20
20
 
@@ -36,7 +36,7 @@ describe TcpSequence do
36
36
  end
37
37
 
38
38
  it "should contain the description and values" do
39
- subject.to_s.should =~ regexp
39
+ expect(subject.to_s).to match(regexp)
40
40
  end
41
41
  end
42
42
 
@@ -8,7 +8,7 @@ describe TcpTsSequence do
8
8
 
9
9
  describe "#description" do
10
10
  it "should parse the description" do
11
- subject.description.should == "1000HZ"
11
+ expect(subject.description).to eq("1000HZ")
12
12
  end
13
13
  end
14
14
 
@@ -26,7 +26,7 @@ describe TcpTsSequence do
26
26
  end
27
27
 
28
28
  it "should contain the description and values" do
29
- subject.to_s.should =~ regexp
29
+ expect(subject.to_s).to match(regexp)
30
30
  end
31
31
  end
32
32
 
@@ -7,25 +7,36 @@ describe Traceroute do
7
7
  describe "#port" do
8
8
  subject { super().port }
9
9
 
10
- it { should be_kind_of(Integer) }
11
- it { should be > 0 }
12
- it { should be < 65535 }
10
+ it { is_expected.to be_kind_of(Integer) }
11
+ it { is_expected.to be > 0 }
12
+ it { is_expected.to be < 65535 }
13
13
  end
14
14
 
15
15
  describe "#protocol" do
16
16
  subject { super().protocol }
17
17
 
18
- it { should be_kind_of(Symbol) }
19
- it { should be_one_of(:tcp, :udp) }
18
+ it { is_expected.to be_kind_of(Symbol) }
19
+ it { is_expected.to eq(:tcp).or eq(:udp) }
20
20
  end
21
21
 
22
22
  describe "#each" do
23
23
  subject { super().each.first }
24
24
 
25
- it { should be_kind_of(Hop) }
25
+ it { is_expected.to be_kind_of(Hop) }
26
26
 
27
- its(:addr) { should be_kind_of(String) }
28
- its(:ttl) { should be_kind_of(String) }
29
- its(:rtt) { should be_kind_of(String) }
27
+ describe '#addr' do
28
+ subject { super().addr }
29
+ it { is_expected.to be_kind_of(String) }
30
+ end
31
+
32
+ describe '#ttl' do
33
+ subject { super().ttl }
34
+ it { is_expected.to be_kind_of(String) }
35
+ end
36
+
37
+ describe '#rtt' do
38
+ subject { super().rtt }
39
+ it { is_expected.to be_kind_of(String) }
40
+ end
30
41
  end
31
42
  end
@@ -9,7 +9,7 @@ describe Uptime do
9
9
  subject { described_class.new(seconds,last_boot) }
10
10
 
11
11
  it "should convert the uptipe to a String" do
12
- subject.to_s.should == "uptime: #{seconds} (#{last_boot})"
12
+ expect(subject.to_s).to eq("uptime: #{seconds} (#{last_boot})")
13
13
  end
14
14
  end
15
15
  end
@@ -11,7 +11,7 @@ describe XML do
11
11
  let(:document) { Nokogiri::XML(File.read(path)) }
12
12
 
13
13
  it "should use the document" do
14
- described_class.new(document).version.should == subject.version
14
+ expect(described_class.new(document).version).to eq(subject.version)
15
15
  end
16
16
  end
17
17
 
@@ -19,36 +19,46 @@ describe XML do
19
19
  let(:io) { File.new(path) }
20
20
 
21
21
  it "should parse the IO object" do
22
- described_class.new(io).version.should == subject.version
22
+ expect(described_class.new(io).version).to eq(subject.version)
23
23
  end
24
24
  end
25
25
 
26
26
  context "when given a String" do
27
27
  it "should parse the file at the path" do
28
- described_class.new(path).version.should == subject.version
28
+ expect(described_class.new(path).version).to eq(subject.version)
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
- describe "load" do
34
- it "should parse the given text" do
35
- subject.version.should == described_class.load(File.read(path)).version
33
+ describe "parse" do
34
+ let(:xml) { File.read(path) }
35
+
36
+ subject { described_class.parse(xml) }
37
+
38
+ it "should return an XML object" do
39
+ expect(subject).to be_kind_of(described_class)
40
+ end
41
+
42
+ it "should parse the XML" do
43
+ expect(subject.version).to_not be_nil
36
44
  end
37
45
  end
38
46
 
39
47
  describe "open" do
40
- it "should parse the given file" do
41
- subject.version.should == described_class.open(path).version
48
+ subject { described_class.open(path) }
49
+
50
+ it "should return an XML object" do
51
+ expect(subject).to be_kind_of(described_class)
42
52
  end
43
53
 
44
- it "should set the path" do
45
- subject.path.should == path
54
+ it "should parse the XML" do
55
+ expect(subject.version).to_not be_nil
46
56
  end
47
57
  end
48
58
 
49
59
  describe "#version" do
50
60
  it "should have a version" do
51
- subject.version.should == '1.04'
61
+ expect(subject.version).to eq('1.04')
52
62
  end
53
63
  end
54
64
 
@@ -58,15 +68,15 @@ describe XML do
58
68
  end
59
69
 
60
70
  it "should parse the scanner name" do
61
- subject.scanner.name.should == 'nmap'
71
+ expect(subject.scanner.name).to eq('nmap')
62
72
  end
63
73
 
64
74
  it "should parse the scanner arguments" do
65
- subject.scanner.arguments.should == 'nmap -v -sS -sU -A -O -oX spec/scan.xml scanme.nmap.org'
75
+ expect(subject.scanner.arguments).to eq('nmap -v -sS -sU -A -O -oX spec/scan.xml scanme.nmap.org')
66
76
  end
67
77
 
68
78
  it "should parse the scanner start time" do
69
- subject.scanner.start_time.should be_kind_of(Time)
79
+ expect(subject.scanner.start_time).to be_kind_of(Time)
70
80
  end
71
81
  end
72
82
 
@@ -74,138 +84,166 @@ describe XML do
74
84
  subject { super().scan_info.first }
75
85
 
76
86
  it "should parse the type" do
77
- subject.type.should == :syn
87
+ expect(subject.type).to eq(:syn)
78
88
  end
79
89
 
80
90
  it "should parse the protocol" do
81
- subject.protocol.should == :tcp
91
+ expect(subject.protocol).to eq(:tcp)
82
92
  end
83
93
 
84
94
  it "should parse the services" do
85
- subject.services.should_not be_empty
95
+ expect(subject.services).not_to be_empty
86
96
  end
87
97
  end
88
98
 
89
99
  it "should parse the verbose level" do
90
- subject.verbose.should == 1
100
+ expect(subject.verbose).to eq(1)
91
101
  end
92
102
 
93
103
  it "should parse the debugging level" do
94
- subject.debugging.should == 0
104
+ expect(subject.debugging).to eq(0)
95
105
  end
96
106
 
97
107
  describe "#each_run_stat" do
98
108
  subject { super().each_run_stat.first }
99
109
 
100
110
  it "should yield RunStat objects" do
101
- subject.should be_kind_of(RunStat)
111
+ expect(subject).to be_kind_of(RunStat)
102
112
  end
103
113
 
104
114
  it "should parse the end time" do
105
- subject.end_time.should be_kind_of(Time)
115
+ expect(subject.end_time).to be_kind_of(Time)
106
116
  end
107
117
 
108
118
  it "should parse the time elapsed" do
109
- subject.elapsed.should_not be_nil
119
+ expect(subject.elapsed).not_to be_nil
110
120
  end
111
121
 
112
122
  it "should parse the summary" do
113
- subject.summary.should_not be_empty
123
+ expect(subject.summary).not_to be_empty
114
124
  end
115
125
 
116
126
  it "should parse the exit status" do
117
- subject.exit_status.should be_one_of('success', 'failure')
127
+ expect(subject.exit_status).to eq('success').or eq('failure')
118
128
  end
119
129
  end
120
130
 
121
131
  describe "#run_stats" do
122
132
  subject { super().run_stats }
123
133
 
124
- it { should_not be_empty }
125
- it { should all_be_kind_of(RunStat) }
134
+ it { is_expected.not_to be_empty }
135
+ it { is_expected.to all(be_kind_of(RunStat)) }
126
136
  end
127
137
 
128
138
  describe "#each_task" do
129
139
  subject { super().each_task.first }
130
140
 
131
141
  it "should parse task name" do
132
- subject.name.should == 'Ping Scan'
142
+ expect(subject.name).to eq('Ping Scan')
133
143
  end
134
144
 
135
145
  it "should parse the start time" do
136
- subject.start_time.should be_kind_of(Time)
146
+ expect(subject.start_time).to be_kind_of(Time)
137
147
  end
138
148
 
139
149
  it "should parse the end time" do
140
- subject.end_time.should be_kind_of(Time)
141
- subject.end_time.should > subject.start_time
150
+ expect(subject.end_time).to be_kind_of(Time)
151
+ expect(subject.end_time).to be > subject.start_time
142
152
  end
143
153
 
144
154
  it "should parse the extrainfo" do
145
- subject.extrainfo.should_not be_empty
155
+ expect(subject.extrainfo).not_to be_empty
146
156
  end
147
157
  end
148
158
 
149
159
  describe "#tasks" do
150
160
  subject { super().tasks }
151
161
 
152
- it { should_not be_empty }
153
- it { should all_be_kind_of(ScanTask) }
162
+ it { is_expected.not_to be_empty }
163
+ it { is_expected.to all(be_kind_of(ScanTask)) }
154
164
  end
155
165
 
156
166
  describe "#each_host" do
157
167
  subject { super().each_host.first }
158
168
 
159
169
  it "should yield Host objects" do
160
- subject.should be_kind_of(Host)
170
+ expect(subject).to be_kind_of(Host)
161
171
  end
162
172
  end
163
173
 
164
174
  describe "#hosts" do
165
175
  subject { super().hosts }
166
176
 
167
- it { should_not be_empty }
168
- it { subject.should all_be_kind_of(Host) }
177
+ it { is_expected.not_to be_empty }
178
+ it { expect(subject).to all(be_kind_of(Host)) }
179
+ end
180
+
181
+ describe "#host" do
182
+ subject { super().host }
183
+
184
+ it { expect(subject).to be_kind_of(Host) }
185
+ end
186
+
187
+ describe "#down_host" do
188
+ pending "need down hosts in scan.xml" do
189
+ subject { super().down_host }
190
+
191
+ it { is_expected.to be_kind_of(Host) }
192
+
193
+ it "should contain only up hosts" do
194
+ expect(subject.status.state).to be(:down)
195
+ end
196
+ end
169
197
  end
170
198
 
171
199
  describe "#each_up_host" do
172
200
  subject { super().each_up_host.first }
173
201
 
174
202
  it "should yield Host objects" do
175
- subject.should be_kind_of(Host)
203
+ expect(subject).to be_kind_of(Host)
176
204
  end
177
205
 
178
206
  it "should be up" do
179
- subject.status.state.should be == :up
207
+ expect(subject.status.state).to eq(:up)
180
208
  end
181
209
  end
182
210
 
183
211
  describe "#up_hosts" do
184
212
  subject { super().up_hosts }
185
213
 
186
- it { should_not be_empty }
187
- it { should all_be_kind_of(Host) }
214
+ it { is_expected.not_to be_empty }
215
+ it { is_expected.to all(be_kind_of(Host)) }
216
+
217
+ it "should contain only up hosts" do
218
+ expect(subject.all? { |host| host.status.state == :up }).to be_truthy
219
+ end
220
+ end
221
+
222
+ describe "#up_host" do
223
+ subject { super().up_host }
224
+
225
+ it { is_expected.to be_kind_of(Host) }
188
226
 
189
227
  it "should contain only up hosts" do
190
- subject.all? { |host| host.status.state == :up }.should be_true
228
+ expect(subject.status.state).to be(:up)
191
229
  end
192
230
  end
193
231
 
194
232
  describe "#each" do
195
233
  it "should iterate over each up host" do
196
- subject.each.all? { |host| host.status.state == :up }.should == true
234
+ expect(subject.each.all? { |host| host.status.state == :up }).to eq(true)
197
235
  end
198
236
  end
199
237
 
200
238
  describe "#to_s" do
201
239
  it "should convert to a String" do
202
- subject.to_s.should == path
240
+ expect(subject.to_s).to eq(path)
203
241
  end
204
242
  end
205
243
 
206
244
  describe "#inspect" do
207
245
  it "should include the class and path" do
208
- subject.inspect.should == "#<#{described_class}: #{path}>"
246
+ expect(subject.inspect).to eq("#<#{described_class}: #{path}>")
209
247
  end
210
248
  end
211
249
  end