Closed peterjmcg closed 3 years ago
RuntimeError: Unable to parse asset: 'test-asset.example.com'. invalid address: test
I have made a PR that fixes this, but the build is failing (more dependencies and ruby update issues). The following monkey patch can be used to get this working.
# Monkey Patch the nexpose-client gem for https://github.com/rapid7/nexpose-client/issues/325
module Nexpose
module HostOrIP
module_function
# Convert a host or IP address to the corresponding HostName or IPRange
# class.
#
# If the String cannot be converted, it will raise an error.
#
# @param [String] asset String representation of an IP or host name.
# @return [IPRange|HostName] Valid class, if it can be converted.
#
def convert(asset)
ips = asset.split('-').map(&:strip)
IPAddr.new(ips[0])
IPAddr.new(ips[1]) if ips[1]
IPRange.new(ips[0], ips[1])
rescue ArgumentError => e
if e.message =~ /invalid address/
HostName.new(asset)
else
raise "Unable to parse asset: '#{asset}'. #{e.message}"
end
end
end
end
I just released version 7.3.0 to catch up all the changes since 7.2.1. I think this issue should be fixed with that since it been sitting on the master branch for a while.
Hostname not recognized by util.rb/convert when using Ruby 2.6.3
Expected Behavior
Load site data with Nexpose::Site.load with site assets including hostnames. No errors expected.
Current Behavior
When loading the site data using Nexpose::Site.load error message is output when hostname is found in asset list.
Possible Solution
In util.rb / convert replace
if e.message == 'invalid address'
with
if e.message.include? "invalid address"
It seems error message now includes the asset address in addition to the string 'invalid address'
Steps to Reproduce (for bugs)
Load site data with Nexpose::Site.load with site assets including hostnames using Ruby 2.6.3. Works ok with Ruby 2.3.3. Not sure which Ruby version introduced the problem.
Ruby code that reproduces the issue: See above
Context
Script fails.
Your Environment