# encoding: UTF-8 shared_examples 'WpTarget::Malwares' do let(:fixtures_dir) { SPEC_FIXTURES_WPSCAN_WP_TARGET_DIR + '/malwares' } let(:malwares_file) { fixtures_dir + '/malwares.txt' } describe '#malwares_file' do it 'returns the correct file path' do expect(WpTarget::Malwares.malwares_file(malwares_file)).to be === malwares_file end end describe '#malwares & #has_malwares' do after :each do if @fixture stub_request_to_fixture( url: wp_target.url, fixture: File.new(File.join(fixtures_dir, @fixture)) ) end malwares = wp_target.malwares(malwares_file) expect(malwares.sort).to be === @expected.sort expect(wp_target.has_malwares?).to be === (@expected.empty? ? false : true) end it 'returns an empty array on a 404' do stub_request(:get, wp_target.url).to_return(status: 404) @expected = [] end it 'returns an array empty array if no infection found' do @fixture = '/clean.html' @expected = [] end it 'returns an array with 1 malware url (.rr.nu check)' do @fixture = '/single-infection.html' @expected = ['http://irstde24clined.rr.nu/mm.php?d=1'] end it 'returns an array with 1 malware url (iframe check)' do @fixture = '/single-iframe-infection.html' @expected = ['http://www.thesea.org/media.php'] end it 'returns an array with 3 malwares url' do @fixture = '/multiple-infections.html' @expected = ['http://irstde24clined.rr.nu/mm.php?d=1', 'http://atio79srem.rr.nu/pmg.php?dr=1', 'http://www.thesea.org/media.php'] end end end