Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 9536796

Browse files
committed
Merge branch 'gh_issue_32' into 1.4
2 parents 50a367c + e5d294d commit 9536796

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

lib/nicinfo/nicinfo_main.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,10 @@ def do_rdap_query
654654

655655
def display_rdap_query json_data, show_help = true
656656
if @config.options.output_json
657-
@config.logger.raw( DataAmount::TERSE_DATA, json_data, false )
657+
@config.logger.raw( DataAmount::TERSE_DATA, JSON.generate( json_data ), false )
658658
elsif @config.options.json_values
659659
@config.options.json_values.each do |value|
660-
@config.logger.raw( DataAmount::TERSE_DATA, eval_json_value( value, json_data), false )
660+
@config.logger.raw( DataAmount::TERSE_DATA, JSON.generate( eval_json_value( value, json_data) ), false )
661661
end
662662
else
663663
@config.factory.new_notices.display_notices json_data, @config.options.query_type == QueryType::BY_SERVER_HELP

spec/webmock_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,51 @@
223223
expect(a_request(:get, "http://data.iana.org/rdap/ipv6.json" )).to have_been_made.once
224224
expect(a_request(:get, "http://data.iana.org/rdap/dns.json" )).to have_been_made.once
225225
end
226+
227+
it 'IP lookup should generate json' do
228+
response = File.new( "spec/recorded_responses/ip_108_45_128_208.txt")
229+
stub_request(:get, "https://rdap.arin.net/registry/ip/108.45.128.208").to_return(response)
230+
231+
dir = File.join( @work_dir, "test_lookup_ip_108_45_128_208_200_for_json" )
232+
logger = NicInfo::Logger.new
233+
logger.data_out = StringIO.new
234+
logger.message_out = StringIO.new
235+
logger.message_level = NicInfo::MessageLevel::NO_MESSAGES
236+
config = NicInfo::Config.new( dir )
237+
config.logger=logger
238+
config.config[ NicInfo::BOOTSTRAP ][ NicInfo::UPDATE_BSFILES ]=false
239+
240+
args = [ "--json", "108.45.128.208" ]
241+
242+
expect{ NicInfo::Main.new( args, config ).run }.to_not output.to_stdout
243+
expect(a_request(:get, "https://rdap.arin.net/registry/ip/108.45.128.208")).to have_been_made.once
244+
245+
json = JSON.load( logger.data_out.string )
246+
expect( json[ "objectClassName" ] ).to eq( "ip network" )
247+
end
248+
249+
it 'IP lookup should generate jv' do
250+
response = File.new( "spec/recorded_responses/ip_108_45_128_208.txt")
251+
stub_request(:get, "https://rdap.arin.net/registry/ip/108.45.128.208").to_return(response)
252+
253+
dir = File.join( @work_dir, "test_lookup_ip_108_45_128_208_200_for_jv" )
254+
logger = NicInfo::Logger.new
255+
logger.data_out = StringIO.new
256+
logger.message_out = StringIO.new
257+
logger.message_level = NicInfo::MessageLevel::NO_MESSAGES
258+
config = NicInfo::Config.new( dir )
259+
config.logger=logger
260+
config.config[ NicInfo::BOOTSTRAP ][ NicInfo::UPDATE_BSFILES ]=false
261+
262+
args = [ "--jv", "links", "108.45.128.208" ]
263+
264+
expect{ NicInfo::Main.new( args, config ).run }.to_not output.to_stdout
265+
expect(a_request(:get, "https://rdap.arin.net/registry/ip/108.45.128.208")).to have_been_made.once
266+
267+
json = JSON.load( logger.data_out.string )
268+
expect( json.length ).to eq( 2 )
269+
expect( json[0]["rel"] ).to eq( "self" )
270+
expect( json[1]["rel"] ).to eq( "alternate" )
271+
end
272+
226273
end

0 commit comments

Comments
 (0)