From d80ce16748d7efd1d20b2f9a6fc24d0a6554ced3 Mon Sep 17 00:00:00 2001 From: Brian Cunnie Date: Fri, 9 Sep 2016 06:27:41 -0700 Subject: [PATCH] Test core fucntion of sslip.io - w-x-y-z.sslip.io resolves to w.x.y.z --- spec/check-dns_spec.rb | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/spec/check-dns_spec.rb b/spec/check-dns_spec.rb index 1bf5e21..f4c1341 100644 --- a/spec/check-dns_spec.rb +++ b/spec/check-dns_spec.rb @@ -4,17 +4,19 @@ # practice using rspec. def get_whois_nameservers(domain) whois_output = `whois #{domain}` + soa = nil whois_lines = whois_output.split(/\n+/) nameserver_lines = whois_lines.select { |line| line =~ /^NS/ } nameservers = nameserver_lines.map { |line| line.split.last } + # whois records don't have trail '.'; NS records do; add trailing '.' + nameservers.map { |ns| ns << '.' } nameservers end -describe 'xip.io-style domain' do - domain = ENV['DOMAIN'] || 'example.com' - whois_nameservers = get_whois_nameservers(domain) - +domain = ENV['DOMAIN'] || 'example.com' +whois_nameservers = get_whois_nameservers(domain) +describe domain do context "when evaluating $DOMAIN (\"#{domain}\") environment variable" do let (:domain) { ENV['DOMAIN'] } it 'is set' do @@ -25,8 +27,30 @@ describe 'xip.io-style domain' do end end + it "should have at least 2 nameservers" do + expect(whois_nameservers.size).to be > 1 + end + whois_nameservers.each do |whois_nameserver| - context "Nameserver #{whois_nameserver}" do + it "nameserver #{whois_nameserver}'s NS records match whois's #{whois_nameservers}" do + dig_nameservers = `dig +short ns sslip.io @#{whois_nameserver}`.split(/\n+/) + expect(dig_nameservers.sort).to eq(whois_nameservers.sort) + end + + it "nameserver #{whois_nameserver}'s SOA record match" do + dig_soa = `dig +short soa sslip.io @#{whois_nameserver}` + soa = soa || dig_soa + expect(dig_soa).to eq(soa) + end + + a = [ rand(256), rand(256), rand(256), rand(256) ] + it "resolves #{a.join(".")}.sslip.io to #{a.join(".")}" do + expect(`dig +short #{a.join(".") + "." + domain} @#{whois_nameserver}`.chomp).to eq(a.join(".")) + end + + a = [ rand(256), rand(256), rand(256), rand(256) ] + it "resolves #{a.join("-")}.sslip.io to #{a.join(".")}" do + expect(`dig +short #{a.join("-") + "." + domain} @#{whois_nameserver}`.chomp).to eq(a.join(".")) end end end