From ac004d2770856797aeea818f73e2d4018675a828 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 12 Dec 2014 13:57:37 -0600 Subject: [PATCH] Fix bruteforce validators to accept nil bruteforce_speed isn't always required, because the speed checker already handles nil (and presumes the user wants the fastest possible). See also MSP-11842 --- .../framework/login_scanner/base.rb | 2 +- .../framework/login_scanner/base_spec.rb | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/metasploit/framework/login_scanner/base.rb b/lib/metasploit/framework/login_scanner/base.rb index 511260ffea..16e7655a0b 100644 --- a/lib/metasploit/framework/login_scanner/base.rb +++ b/lib/metasploit/framework/login_scanner/base.rb @@ -57,8 +57,8 @@ module Metasploit inclusion: { in: [true, false] } validates :bruteforce_speed, - presence: false, numericality: { + allow_nil: true, only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 5 diff --git a/spec/lib/metasploit/framework/login_scanner/base_spec.rb b/spec/lib/metasploit/framework/login_scanner/base_spec.rb index 522024f9e1..b30725fe12 100644 --- a/spec/lib/metasploit/framework/login_scanner/base_spec.rb +++ b/spec/lib/metasploit/framework/login_scanner/base_spec.rb @@ -12,12 +12,33 @@ describe Metasploit::Framework::LoginScanner::Base do end } - subject(:login_scanner) { base_class.new } + let(:options) { + + { + connection_timeout: 1, + cred_details: ["user", "pass"], + host: '1.2.3.4', + port: 4444, + stop_on_success: true, + bruteforce_speed: 5, + + } + } + + subject(:login_scanner) { + base_class.new(options) + } it { should respond_to :bruteforce_speed } context 'validations' do + + it 'is valid!' do + expect(login_scanner).to be_valid + end + context 'bruteforce_speed' do + it 'is not valid for a non-number' do login_scanner.bruteforce_speed = "a" expect(login_scanner).to_not be_valid @@ -36,11 +57,17 @@ describe Metasploit::Framework::LoginScanner::Base do expect(login_scanner.errors[:bruteforce_speed]).to include "must be greater than or equal to 0" end + it 'is nil' do + login_scanner.bruteforce_speed = nil + expect(login_scanner).to be_valid + end + it 'is not greater than five' do login_scanner.bruteforce_speed = "6" expect(login_scanner).to_not be_valid expect(login_scanner.errors[:bruteforce_speed]).to include "must be less than or equal to 5" end + end it { should respond_to :sleep_time }