dkim-query 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'dkim/query/query'
3
+
4
+ describe DKIM::Query do
5
+ subject { described_class }
6
+
7
+ let(:domain) { 'yahoo.com' }
8
+
9
+ describe ".host_without_tld" do
10
+ let(:tld) { ".com" }
11
+
12
+ it "should strip the last component of the domain" do
13
+ expect(subject.host_without_tld(domain)).to be == domain.chomp(tld)
14
+ end
15
+ end
16
+
17
+ describe ".selectors_for" do
18
+ subject { described_class.selectors_for(domain) }
19
+
20
+ described_class::SELECTORS.each do |selector|
21
+ it "should include '#{selector}'" do
22
+ expect(subject).to include(selector)
23
+ end
24
+ end
25
+
26
+ it "should include the domain without the TLD" do
27
+ expect(subject).to include('yahoo')
28
+ end
29
+ end
30
+
31
+ describe ".query" do
32
+ it "should return all found DKIM keys" do
33
+ expect(subject.query(domain)).to be == {
34
+ 's1024' => 'k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB; n=A 1024 bit key;'
35
+ }
36
+ end
37
+
38
+ context "with custom selectors" do
39
+ let(:selectors) { ['google', 's1024'] }
40
+
41
+ it "should query those selectors only" do
42
+ expect(subject.query(domain, selectors: selectors)).to have_key('s1024')
43
+ end
44
+ end
45
+
46
+ context "with no selectors" do
47
+ it "should not find any keys" do
48
+ expect(subject.query(domain, selectors: [])).to be_empty
49
+ end
50
+ end
51
+
52
+ context "when given an invalid domain" do
53
+ let(:domain) { 'foo.bar.com' }
54
+
55
+ it "should return {}" do
56
+ expect(subject.query(domain)).to be == {}
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,13 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require 'rspec'
7
+ require 'dkim/query'
8
+
9
+ include DKIM::Query
10
+
11
+ RSpec.configure do |specs|
12
+ specs
13
+ end
data/tasks/alexa.rb ADDED
@@ -0,0 +1,43 @@
1
+ ##
2
+ # Adapted from gist: https://gist.github.com/zerothabhishek/3015666
3
+ # Orginal author: zerothabhishek
4
+ ##
5
+
6
+ require 'nokogiri'
7
+ require 'open-uri'
8
+ require 'resolv'
9
+ require 'csv'
10
+
11
+ namespace :alexa do
12
+ desc 'Scrapes the Alexa Top 500 and updates spec/data/alexa.csv'
13
+ task :scrape do
14
+ resolver = Resolv::DNS.new
15
+
16
+ CSV.open("spec/data/alexa.csv","w") do |csv|
17
+ (0..19).each do |i|
18
+ url = "http://www.alexa.com/topsites/global;#{i} "
19
+ doc = Nokogiri::HTML(open(url))
20
+
21
+ doc.css(".site-listing").each do |li|
22
+ begin
23
+ site_name = li.css(".desc-container .desc-paragraph a")[0].content
24
+ site_rank = li.css(".count")[0].content
25
+
26
+ puts "Resolving #{site_name} ..."
27
+ dmarc = begin
28
+ resolver.getresource(
29
+ "_dmarc.#{site_name.downcase}",
30
+ Resolv::DNS::Resource::IN::TXT
31
+ ).strings.join
32
+ rescue Resolv::ResolvError
33
+ end
34
+
35
+ csv << [site_rank, site_name, dmarc]
36
+ rescue => exception
37
+ warn exception.message
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dkim-query
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - nicktitle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Search and retrieve DKIM records for any number of hosts
56
+ email:
57
+ - nick.esposito@trailofbits.com
58
+ executables:
59
+ - dkim-query
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - ".yardopts"
67
+ - ChangeLog.md
68
+ - Gemfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/dkim-query
73
+ - dkim-query.gemspec
74
+ - lib/dkim/query.rb
75
+ - lib/dkim/query/domain.rb
76
+ - lib/dkim/query/exceptions.rb
77
+ - lib/dkim/query/key.rb
78
+ - lib/dkim/query/malformed_key.rb
79
+ - lib/dkim/query/parser.rb
80
+ - lib/dkim/query/query.rb
81
+ - lib/dkim/query/version.rb
82
+ - spec/domain_spec.rb
83
+ - spec/key_spec.rb
84
+ - spec/parser_spec.rb
85
+ - spec/query_spec.rb
86
+ - spec/spec_helper.rb
87
+ - tasks/alexa.rb
88
+ homepage: https://github.com/trailofbits/dkim-query#readme
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.9.1
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.7
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: DKIM Retriever and Parser
112
+ test_files:
113
+ - spec/domain_spec.rb
114
+ - spec/key_spec.rb
115
+ - spec/parser_spec.rb
116
+ - spec/query_spec.rb
117
+ - spec/spec_helper.rb
118
+ has_rdoc: