mirror of
https://github.com/cunnie/sslip.io.git
synced 2025-10-05 23:56:50 +08:00
Test core fucntion of sslip.io
- w-x-y-z.sslip.io resolves to w.x.y.z
This commit is contained in:
@@ -4,17 +4,19 @@
|
|||||||
# practice using rspec.
|
# practice using rspec.
|
||||||
def get_whois_nameservers(domain)
|
def get_whois_nameservers(domain)
|
||||||
whois_output = `whois #{domain}`
|
whois_output = `whois #{domain}`
|
||||||
|
soa = nil
|
||||||
whois_lines = whois_output.split(/\n+/)
|
whois_lines = whois_output.split(/\n+/)
|
||||||
nameserver_lines = whois_lines.select { |line| line =~ /^NS/ }
|
nameserver_lines = whois_lines.select { |line| line =~ /^NS/ }
|
||||||
nameservers = nameserver_lines.map { |line| line.split.last }
|
nameservers = nameserver_lines.map { |line| line.split.last }
|
||||||
|
# whois records don't have trail '.'; NS records do; add trailing '.'
|
||||||
|
nameservers.map { |ns| ns << '.' }
|
||||||
nameservers
|
nameservers
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'xip.io-style domain' do
|
domain = ENV['DOMAIN'] || 'example.com'
|
||||||
domain = ENV['DOMAIN'] || 'example.com'
|
whois_nameservers = get_whois_nameservers(domain)
|
||||||
whois_nameservers = get_whois_nameservers(domain)
|
|
||||||
|
|
||||||
|
|
||||||
|
describe domain do
|
||||||
context "when evaluating $DOMAIN (\"#{domain}\") environment variable" do
|
context "when evaluating $DOMAIN (\"#{domain}\") environment variable" do
|
||||||
let (:domain) { ENV['DOMAIN'] }
|
let (:domain) { ENV['DOMAIN'] }
|
||||||
it 'is set' do
|
it 'is set' do
|
||||||
@@ -25,8 +27,30 @@ describe 'xip.io-style domain' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should have at least 2 nameservers" do
|
||||||
|
expect(whois_nameservers.size).to be > 1
|
||||||
|
end
|
||||||
|
|
||||||
whois_nameservers.each do |whois_nameserver|
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user