From bc1be7f2133ef2c61f509120906d91d12afce708 Mon Sep 17 00:00:00 2001 From: wchen-r7 Date: Tue, 29 Sep 2015 17:20:30 -0500 Subject: [PATCH] some progress with rspec --- spec/tools/msu_finder_spec.rb | 214 +++++++++++++++++++++++++++++++++- tools/msu_finder.rb | 2 +- 2 files changed, 214 insertions(+), 2 deletions(-) diff --git a/spec/tools/msu_finder_spec.rb b/spec/tools/msu_finder_spec.rb index 1a4326633d..da93028ad3 100644 --- a/spec/tools/msu_finder_spec.rb +++ b/spec/tools/msu_finder_spec.rb @@ -1,7 +1,17 @@ load Metasploit::Framework.root.join('tools/msu_finder.rb').to_path +require 'nokogiri' + describe MicrosoftPatch do + before(:each) do + cli = Rex::Proto::Http::Client.new('127.0.0.1') + allow(cli).to receive(:connect) + allow(cli).to receive(:request_cgi) + allow(cli).to receive(:send_recv).and_return(Rex::Proto::Http::Response.new) + allow(Rex::Proto::Http::Client).to receive(:new).and_return(cli) + end + describe MicrosoftPatch::SiteInfo do context 'Constants' do context 'TECHNET' do @@ -49,18 +59,220 @@ describe MicrosoftPatch do end describe MicrosoftPatch::Base do + + def get_stdout(&block) + out = $stdout + $stdout = fake = StringIO.new + begin + yield + ensure + $stdout = out + end + fake.string + end + + def get_stderr(&block) + out = $stderr + $stderr = fake = StringIO.new + begin + yield + ensure + $stderr = out + end + fake.string + end + + subject do + MicrosoftPatch::Base.new + end + + describe '#print_debug' do + it 'prints a [DEBUG] message' do + output = get_stderr { subject.print_debug } + expect(output).to include('[DEBUG]') + end + end + + describe '#print_status' do + it 'prints a [*] message' do + output = get_stderr { subject.print_status } + expect(output).to include('[*]') + end + end + + describe '#print_error' do + it 'prints an [ERROR] message' do + output = get_stderr { subject.print_error } + expect(output).to include('[ERROR]') + end + end + + describe '#print_line' do + it 'prints a regular message' do + msg = 'TEST' + output = get_stdout { subject.print_line(msg) } + expect(output).to eq("#{msg}\n") + end + end + + describe '#send_http_request' do + it 'returns a Rex::Proto::Http::Response object' do + allow(subject).to receive(:print_debug) + res = subject.send_http_request(MicrosoftPatch::SiteInfo::TECHNET) + expect(res).to be_kind_of(Rex::Proto::Http::Response) + end + end + end describe MicrosoftPatch::PatchLinkCollector do + + subject do + MicrosoftPatch::PatchLinkCollector.new + end + + before(:each) do + allow(subject).to receive(:print_debug) + end + + describe '#download_advisory' do + it 'returns a Rex::Proto::Http::Response object' do + res = subject.download_advisory('ms15-100') + expect(res).to be_kind_of(Rex::Proto::Http::Response) + end + end + + describe '#get_appropriate_pattern' do + let(:ms15_100_html) do + %Q| + +
+
+

+
+ Affected Software +
+ + +
fake link
+
+
+

+
+
+ + | + end + + let(:ms07_029_html) do + %Q| + + + | + end + + let(:ms03_039_html) do + %Q| + + + | + end + + let(:ms07_030_html) do + %Q| + + + | + end + + it 'returns a pattern for ms15-100' do + expected_pattern = '//div[@id="mainBody"]//div//div[@class="sectionblock"]//table//a' + p = subject.get_appropriate_pattern(::Nokogiri::HTML(ms15_100_html)) + expect(p).to eq(expected_pattern) + end + + it 'returns a pattern for ms07-029' do + end + + it 'returns a pattern for ms03-039' do + end + + it 'returns a pattern for ms07-030' do + end + end + + describe '#get_details_aspx' do + end + + describe '#follow_redirect' do + end + + describe '#get_download_page' do + end + + describe '#get_download_links' do + end + + describe '#has_advisory?' do + end + + describe '#is_valid_msb?' do + end + end describe MicrosoftPatch::TechnetMsbSearch do + + describe '#find_msb_numbers' do + end + + describe '#search' do + end + + describe '#search_by_product_ids' do + end + + describe '#search_by_keyword' do + end + + describe '#get_product_dropdown_list' do + end + end describe MicrosoftPatch::GoogleMsbSearch do + + describe '#find_msb_numbers' do + end + + describe '#search' do + end + + describe '#parse_results' do + end + + describe '#get_total_results' do + end + + describe '#get_next_index' do + end + end describe MicrosoftPatch::Module do + + describe '#get_download_links' do + end + + describe '#google_search' do + end + + describe '#technet_search' do + end + + describe '#run' do + end + end -end \ No newline at end of file +end diff --git a/tools/msu_finder.rb b/tools/msu_finder.rb index 2ef0699829..da2738e894 100644 --- a/tools/msu_finder.rb +++ b/tools/msu_finder.rb @@ -64,7 +64,7 @@ module MicrosoftPatch # @param msg [String] The message to print. # @return [void] def print_error(msg='') - $stderr.puts "[Error] #{msg}" + $stderr.puts "[ERROR] #{msg}" end # Prints a regular message.