Skip to content

Commit

Permalink
Starting with spec tests this time!
Browse files Browse the repository at this point in the history
  • Loading branch information
jpf committed Jul 7, 2009
1 parent 49a2ee6 commit 5530c31
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Rakefile
@@ -0,0 +1,15 @@
require 'rake'
require 'spec/rake/spectask'

desc "Run all examples with RCov"
Spec::Rake::SpecTask.new('spec:rcov') do |t|
t.spec_files = FileList['spec/']
t.rcov = true
t.rcov_opts = lambda do
IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
end
end
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_files = FileList['spec/']
t.spec_opts << '--options' << 'spec/spec.opts'
end
25 changes: 25 additions & 0 deletions TODO
@@ -0,0 +1,25 @@
# paid for:
# x registrar
# x hosting
# x dns hosting
# x email hosting
# x ssl certificate
#
# made decision:
# - [dns ] outsourced email?
# x [dns ] spf?
# x [dns ] ttl's on DNS?
# - [ssl ] ssl expires
# - [whoi] domain expires
# - [as ] different ASes
# - [as ] multi-homing dns?
# - [as ] all services in same as?
# - [curl] valid xhtml?
# - [curl] frontend type
# - [nmap] port scan
# - [dns+] check for *.records

Sources:
- dns
- whois
- ssl
Empty file added lib/domain-profile.rb
Empty file.
32 changes: 32 additions & 0 deletions lib/domain-profile/dns.rb
@@ -0,0 +1,32 @@

class DNSType
def initialize(input)
@input = input
end
def method_missing(type)
@input.map { |a| a[type] }.sort
end
end

class DNSQuery
def initialize(input)
lookup = [:query,:ttl,:cl,:type,:answer]
@query = input.grep(/^[^;]/).map do |line|
Hash[*lookup.zip(line.gsub("\t\t","\t").split("\t")).flatten]
end
end
def method_missing(type)
rv = @query.map { |record| if record[:type] == type.to_s.upcase; record; else; nil; end }.compact
DNSType.new(rv)
end
end

class DNS
def parse(data)
@data = data.split("\n")
end
def method_missing(type)
query = DNSQuery.new(@data)
query.send(type)
end
end
9 changes: 9 additions & 0 deletions lib/domain-profile/ssl.rb
@@ -0,0 +1,9 @@

class SSL
def parse(data)
@data = data.split("\n")
end
def ca
@data.grep(/^ 1 s:/).to_s.match(/O=([^\/]+)\/[A-Z]/)[1]
end
end
9 changes: 9 additions & 0 deletions lib/domain-profile/whois.rb
@@ -0,0 +1,9 @@

class Whois
def parse(data)
@data = data.split("\n")
end
def registrar
@data.grep(/Registrar:/).to_s.split(': ')[1]
end
end
37 changes: 37 additions & 0 deletions spec/dns/dns_spec.rb
@@ -0,0 +1,37 @@
# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
require 'domain-profile/dns'

describe DNS do
before(:all) do
filename = File.expand_path(File.dirname(__FILE__) + '/fixtures/dns.raw.dump')
data = `cat #{filename}`
@dns = DNS.new
@dns.parse(data)
end

it "knows what the 'answer' is for the SOA record" do
@dns.soa.answer.should == ["ns1.zombo.com. ooaahh.yahoo.com. 2008111600 86400 7200 3600000 86400"]
end

it "knows what the 'answer' is for the NS record" do
@dns.ns.answer.should == ["ns1.zombo.com.", "ns2.zombo.com."]
end

it "knows what the 'answer' is for the MX record" do
@dns.mx.answer.should == ['0 zombo.com.']
end

it "knows what the 'answer' is for the A record" do
@dns.a.answer.should == ['69.16.230.117']
end

it "knows what the TTL is for the A record" do
@dns.a.ttl.should == ['10563']
end

it "knows what the query was for the A record" do
@dns.a.query.should == ['zombo.com.']
end

end
77 changes: 77 additions & 0 deletions spec/dns/fixtures/dns.raw.dump
@@ -0,0 +1,77 @@

; <<>> DiG 9.4.3-P1 <<>> @4.2.2.2 ns zombo.com
; (1 server found)
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28712
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;zombo.com. IN NS

;; ANSWER SECTION:
zombo.com. 39363 IN NS ns2.zombo.com.
zombo.com. 39363 IN NS ns1.zombo.com.

;; Query time: 12 msec
;; SERVER: 4.2.2.2#53(4.2.2.2)
;; WHEN: Mon Jul 6 23:22:38 2009
;; MSG SIZE rcvd: 63


; <<>> DiG 9.4.3-P1 <<>> @4.2.2.2 a zombo.com
; (1 server found)
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2940
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;zombo.com. IN A

;; ANSWER SECTION:
zombo.com. 10563 IN A 69.16.230.117

;; Query time: 11 msec
;; SERVER: 4.2.2.2#53(4.2.2.2)
;; WHEN: Mon Jul 6 23:22:38 2009
;; MSG SIZE rcvd: 43


; <<>> DiG 9.4.3-P1 <<>> @4.2.2.2 mx zombo.com
; (1 server found)
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28675
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;zombo.com. IN MX

;; ANSWER SECTION:
zombo.com. 14400 IN MX 0 zombo.com.

;; Query time: 75 msec
;; SERVER: 4.2.2.2#53(4.2.2.2)
;; WHEN: Mon Jul 6 23:22:39 2009
;; MSG SIZE rcvd: 43


; <<>> DiG 9.4.3-P1 <<>> @4.2.2.2 txt zombo.com
; (1 server found)
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55106
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;zombo.com. IN TXT

;; AUTHORITY SECTION:
zombo.com. 900 IN SOA ns1.zombo.com. ooaahh.yahoo.com. 2008111600 86400 7200 3600000 86400

;; Query time: 73 msec
;; SERVER: 4.2.2.2#53(4.2.2.2)
;; WHEN: Mon Jul 6 23:22:39 2009
;; MSG SIZE rcvd: 80

4 changes: 4 additions & 0 deletions spec/rcov.opts
@@ -0,0 +1,4 @@
--exclude spec,gem
--text-summary
--spec-only
--sort coverage --sort-reverse
2 changes: 2 additions & 0 deletions spec/spec.opts
@@ -0,0 +1,2 @@
--format specdoc
--colour
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,4 @@
# encoding: UTF-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'domain-profile'
52 changes: 52 additions & 0 deletions spec/ssl/fixtures/openssl.raw.dump
@@ -0,0 +1,52 @@
depth=1 /C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
verify error:num=20:unable to get local issuer certificate
verify return:0
CONNECTED(00000003)
---
Certificate chain
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
i:/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
1 s:/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
i:/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDITCCAoqgAwIBAgIQASo5dg0/T8kL570rz5UuejANBgkqhkiG9w0BAQUFADBM
MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg
THRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBDQTAeFw0wOTAzMjcyMjIwMDdaFw0x
MDAzMjcyMjIwMDdaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlh
MRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRcw
FQYDVQQDEw53d3cuZ29vZ2xlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
gYEA1rnhrbhhCx9OtjwJPavo4yu26KQ6eC/TUSAiRZXYAJEzmqeiSOowVyaXZsda
7/GbDD/huX97w8fMr5zQHzyBFRBY/Aazv7ycArlR3PumuRdC5kbnIs9sJxD+VOaS
bAxgdprO+H+suFoIStyxZL2gdEGyrI+GnRreWAn9bAol4HkCAwEAAaOB5zCB5DAo
BgNVHSUEITAfBggrBgEFBQcDAQYIKwYBBQUHAwIGCWCGSAGG+EIEATA2BgNVHR8E
LzAtMCugKaAnhiVodHRwOi8vY3JsLnRoYXd0ZS5jb20vVGhhd3RlU0dDQ0EuY3Js
MHIGCCsGAQUFBwEBBGYwZDAiBggrBgEFBQcwAYYWaHR0cDovL29jc3AudGhhd3Rl
LmNvbTA+BggrBgEFBQcwAoYyaHR0cDovL3d3dy50aGF3dGUuY29tL3JlcG9zaXRv
cnkvVGhhd3RlX1NHQ19DQS5jcnQwDAYDVR0TAQH/BAIwADANBgkqhkiG9w0BAQUF
AAOBgQA5tvsRvDMsw5BI427DmzixQtEACVhjoOGYHIXy7xAdYE5RCWL1Bb2dT4ds
mHIHgMNZSBTi1u/QjzNqaDH6t7uFzPfHR3tnkzzDFlGbb4cg/WdMK+pqSdsR0b3X
lSJDegZ7TvY3jqK5zx+l0r07BJc5sw/6OLWvVSCIYJPy3tv/3w==
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
issuer=/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA
---
No client certificate CA names sent
---
SSL handshake has read 1765 bytes and written 304 bytes
---
New, TLSv1/SSLv3, Cipher is RC4-SHA
Server public key is 1024 bit
SSL-Session:
Protocol : TLSv1
Cipher : RC4-SHA
Session-ID: DFBA5390BB979D51A6090DF7259D94BA2C8BC5DF2351AB76F01CDE00732B0FA4
Session-ID-ctx:
Master-Key: 7AC127C6EFB7810C258CA8EA50051A71786116A9FD154F0C4D59DDE29F70C59A18782DC3908C2DFDDF31E66751671782
Key-Arg : None
Start Time: 1246948332
Timeout : 300 (sec)
Verify return code: 20 (unable to get local issuer certificate)
---
DONE
17 changes: 17 additions & 0 deletions spec/ssl/ssl_spec.rb
@@ -0,0 +1,17 @@
# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
require 'domain-profile/ssl'

describe SSL do
before(:all) do
filename = File.expand_path(File.dirname(__FILE__) + '/fixtures/openssl.raw.dump')
data = `cat #{filename}`
@ssl = SSL.new
@ssl.parse(data)
end

it "knows the name of the certificate authority" do
@ssl.ca.should == 'Thawte Consulting (Pty) Ltd.'
end

end

0 comments on commit 5530c31

Please sign in to comment.