# -*- coding:binary -*- require 'rex/parser/nmap_xml' xml = '
' RSpec.describe Rex::Parser::NmapXMLStreamParser do parser = Rex::Parser::NmapXMLStreamParser.new total_hosts = 0 parser.on_found_host = Proc.new { |host| total_hosts += 1 it "should yield a host" do expect(host).not_to be_nil end it "should populate the host with proper keys" do expect(host).to have_key("status") expect(host).to have_key("ports") expect(host).to have_key("addrs") expect(host["ports"]).to be_a(Array) expect(host["addrs"]).to be_a(Hash) end it "should find the address" do expect(host["addrs"].keys.length).to eq 1 expect(host["addrs"]).to have_key("ipv4") expect(host["addrs"]["ipv4"]).to eq "192.168.0.1" end } REXML::Document.parse_stream(StringIO.new(xml), parser) it "should have found exactly one host" do expect(total_hosts).to eq 1 end end