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

Commit a7eb3c9

Browse files
author
Andy Newton
committed
added mocks for ns lookup
1 parent 318b1f6 commit a7eb3c9

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

lib/nicinfo/domain.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def process json_data
112112
@entities = @common.process_entities @objectclass
113113
json_nses = NicInfo::get_nameservers json_data
114114
json_nses.each do |json_ns|
115-
ns = Ns.new( @config )
115+
ns = @config.factory.new_ns
116116
ns.process( json_ns )
117117
@nameservers << ns
118118
end if json_nses

lib/nicinfo/ns.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
module NicInfo
2323

2424
def NicInfo.display_ns json_data, config, data_node
25-
ns = Ns.new( config ).process( json_data )
25+
ns = config.factory.new_ns.process( json_data )
2626
NicInfo::display_object_with_entities( ns, config, data_node )
2727
end
2828

@@ -32,7 +32,7 @@ def NicInfo.display_nameservers json_data, config, data_node
3232
if ns_array.instance_of? Array
3333
display_array = Array.new
3434
ns_array.each do |ea|
35-
ns = Ns.new( config ).process( ea )
35+
ns = config.factory.new_ns.process( ea )
3636
display_array << ns
3737
end
3838
NicInfo::display_object_with_entities( display_array, config, data_node )
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Server: nginx
3+
Date: Wed, 20 Dec 2017 00:07:49 GMT
4+
Content-Type: application/rdap+json;charset=ISO-8859-1
5+
Content-Length: 806
6+
Connection: keep-alive
7+
Set-Cookie: JSESSIONID=5C34B7329ADDD6C0341A5B54675ED407; Path=/; Secure; HttpOnly
8+
X-Frame-Options: DENY
9+
Strict-Transport-Security: max-age=15768000
10+
11+
{"port43":"whois.verisign-grs.com","objectClassName":"nameserver","notices":[{"description":["Service subject to Terms of Use."],"links":[{"href":"http:\/\/rdap-pilot.verisignlabs.com\/terms_of_use","type":"text\/html"}],"title":"Terms of Use"}],"rdapConformance":["rdap_level_0"],"handle":"60625639~VRSN","ipAddresses":{"v6":["2001:500:13:0:0:0:0:108"],"v4":["199.212.0.108"]},"links":[{"rel":"self","href":"https:\/\/rdap-pilot.verisignlabs.com\/rdap\/v1\/nameserver\/NS1.ARIN.NET","type":"application\/rdap+json","value":"https:\/\/rdap-pilot.verisignlabs.com\/rdap\/v1\/nameserver\/NS1.ARIN.NET"}],"lang":"en-US","events":[{"eventAction":"registration","eventDate":"2007-10-09T12:45:17Z"},{"eventAction":"last changed","eventDate":"2014-06-13T18:33:47Z"}],"ldhName":"NS1.ARIN.NET","status":["active"]}

spec/webmock_spec.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
response = File.new( "spec/recorded_responses/ip_108_45_128_208.txt")
9191
stub_request(:get, "https://rdap.arin.net/registry/ip/108.45.128.208").to_return(response)
9292

93-
dir = File.join( @work_dir, "test_search_entity_200" )
93+
dir = File.join( @work_dir, "test_lookup_ip_108_45_128_208_200" )
9494
logger = NicInfo::Logger.new
9595
logger.data_out = StringIO.new
9696
logger.message_out = StringIO.new
@@ -117,7 +117,7 @@
117117
response = File.new( "spec/recorded_responses/autnum_703.txt")
118118
stub_request(:get, "https://rdap.arin.net/registry/autnum/703").to_return(response)
119119

120-
dir = File.join( @work_dir, "test_search_entity_200" )
120+
dir = File.join( @work_dir, "test_lookup_autnum_703_200" )
121121
logger = NicInfo::Logger.new
122122
logger.data_out = StringIO.new
123123
logger.message_out = StringIO.new
@@ -139,4 +139,31 @@
139139
expect( config.factory).to have_received(:new_autnum).once
140140
expect(a_request(:get, "https://rdap.arin.net/registry/autnum/703")).to have_been_made.once
141141
end
142+
143+
it 'should process an ns lookup' do
144+
response = File.new( "spec/recorded_responses/ns1_arin_net.txt")
145+
stub_request(:get, "https://rdap-pilot.verisignlabs.com/rdap/v1/nameserver/ns1.arin.net").to_return(response)
146+
147+
dir = File.join( @work_dir, "test_lookup_ns1_arin_net_200" )
148+
logger = NicInfo::Logger.new
149+
logger.data_out = StringIO.new
150+
logger.message_out = StringIO.new
151+
logger.message_level = NicInfo::MessageLevel::NO_MESSAGES
152+
config = NicInfo::Config.new( dir )
153+
config.logger=logger
154+
config.config[ NicInfo::BOOTSTRAP ][ NicInfo::UPDATE_BSFILES ]=false
155+
156+
args = [ "ns1.arin.net" ]
157+
158+
allow( config.factory ).to receive(:new_error_code).and_call_original
159+
allow( config.factory ).to receive(:new_notices).and_call_original
160+
allow( config.factory ).to receive(:new_entity).and_call_original
161+
allow( config.factory ).to receive(:new_ns).and_call_original
162+
expect{ NicInfo::Main.new( args, config ).run }.to_not output.to_stdout
163+
expect( config.factory).to_not have_received(:new_error_code)
164+
expect( config.factory).to have_received(:new_notices).once
165+
expect( config.factory).to_not have_received(:new_entity)
166+
expect( config.factory).to have_received(:new_ns).once
167+
expect(a_request(:get, "https://rdap-pilot.verisignlabs.com/rdap/v1/nameserver/ns1.arin.net")).to have_been_made.once
168+
end
142169
end

0 commit comments

Comments
 (0)