Skip to content

Commit 5d68d48

Browse files
David MaloneyDavid Maloney
authored andcommitted
Land rapid7#4385, fixes bruteforce_speed validator
bruteforce_speed validator now accepts nil
2 parents fee49b0 + ac004d2 commit 5d68d48

File tree

2 files changed

+29
-2
lines changed
  • lib/metasploit/framework/login_scanner
  • spec/lib/metasploit/framework/login_scanner

2 files changed

+29
-2
lines changed

lib/metasploit/framework/login_scanner/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ module Base
5757
inclusion: { in: [true, false] }
5858

5959
validates :bruteforce_speed,
60-
presence: false,
6160
numericality: {
61+
allow_nil: true,
6262
only_integer: true,
6363
greater_than_or_equal_to: 0,
6464
less_than_or_equal_to: 5

spec/lib/metasploit/framework/login_scanner/base_spec.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,33 @@ def self.model_name
1212
end
1313
}
1414

15-
subject(:login_scanner) { base_class.new }
15+
let(:options) {
16+
17+
{
18+
connection_timeout: 1,
19+
cred_details: ["user", "pass"],
20+
host: '1.2.3.4',
21+
port: 4444,
22+
stop_on_success: true,
23+
bruteforce_speed: 5,
24+
25+
}
26+
}
27+
28+
subject(:login_scanner) {
29+
base_class.new(options)
30+
}
1631

1732
it { should respond_to :bruteforce_speed }
1833

1934
context 'validations' do
35+
36+
it 'is valid!' do
37+
expect(login_scanner).to be_valid
38+
end
39+
2040
context 'bruteforce_speed' do
41+
2142
it 'is not valid for a non-number' do
2243
login_scanner.bruteforce_speed = "a"
2344
expect(login_scanner).to_not be_valid
@@ -36,11 +57,17 @@ def self.model_name
3657
expect(login_scanner.errors[:bruteforce_speed]).to include "must be greater than or equal to 0"
3758
end
3859

60+
it 'is nil' do
61+
login_scanner.bruteforce_speed = nil
62+
expect(login_scanner).to be_valid
63+
end
64+
3965
it 'is not greater than five' do
4066
login_scanner.bruteforce_speed = "6"
4167
expect(login_scanner).to_not be_valid
4268
expect(login_scanner.errors[:bruteforce_speed]).to include "must be less than or equal to 5"
4369
end
70+
4471
end
4572

4673
it { should respond_to :sleep_time }

0 commit comments

Comments
 (0)