/
logger_spec.rb
61 lines (46 loc) · 1.68 KB
/
logger_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'spec_helper'
module Micetrap
describe Logger do
describe "#initialize" do
it 'initializes the filename' do
Time.stub_chain('now.strftime').and_return "2011-01-03__20-30"
logger = Logger.new :ftp
logger.filename.should == "micetrap_ftp_2011-01-03__20-30.log"
end
end
describe "instance methods" do
subject { Logger.new :ftp }
describe "#file" do
it 'returns the log file' do
file = double('file')
File.stub(:new).and_return file
subject.file.should be(file)
end
end
describe "#log_probe" do
it 'logs a scanned service along with the scanner info' do
file = double('file')
now = Time.now
Time.stub(:now).and_return now
File.stub(:new).and_return file
expected_string = "\n#{now} Recorded a probe coming from hackerz.com:5978 containing the following: ###EVILPROBE###"
File.should_receive(:open).and_yield file
file.should_receive(:write).with expected_string
subject.log_probe "###EVILPROBE###", "hackerz.com", 5978
end
end
describe "#log_message" do
it 'logs a misc messagescanned service along with the scanner info' do
file = double('file')
now = Time.now
Time.stub(:now).and_return now
File.stub(:new).and_return file
expected_string = "\n#{now} ::: Warning! :::"
File.should_receive(:open).and_yield file
file.should_receive(:write).with expected_string
subject.log_message "Warning!"
end
end
end
end
end