gman 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -2
- data/gman.gemspec +1 -1
- data/lib/domains.txt +9910 -208
- data/test/helper.rb +20 -18
- data/test/test_gman.rb +122 -108
- metadata +2 -2
data/test/helper.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'gman'
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'gman'
|
16
|
+
require 'net/dns'
|
17
|
+
require 'net/dns/resolver'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
end
|
data/test/test_gman.rb
CHANGED
@@ -1,108 +1,122 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
VALID = [ "foo.gov",
|
4
|
-
"http://foo.mil",
|
5
|
-
"foo@bar.gc.ca",
|
6
|
-
"foo.gov.au",
|
7
|
-
"https://www.foo.gouv.fr",
|
8
|
-
"foo@ci.champaign.il.us",
|
9
|
-
"foo.bar.baz.gov.au",
|
10
|
-
"foo@bar.gov.uk",
|
11
|
-
".gov",
|
12
|
-
"foo.fed.us",
|
13
|
-
]
|
14
|
-
|
15
|
-
INVALID = [ "foo.bar.com",
|
16
|
-
"bar@foo.biz",
|
17
|
-
"http://www.foo.biz",
|
18
|
-
"foo.uk",
|
19
|
-
"gov",
|
20
|
-
"foo@k12.champaign.il.us",
|
21
|
-
"foo@kii.gov.by",
|
22
|
-
"foo",
|
23
|
-
"",
|
24
|
-
nil,
|
25
|
-
" ",
|
26
|
-
]
|
27
|
-
|
28
|
-
class TestGman < Test::Unit::TestCase
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
assert_equal
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal
|
69
|
-
assert_equal
|
70
|
-
assert_equal
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
assert_equal
|
107
|
-
|
108
|
-
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
VALID = [ "foo.gov",
|
4
|
+
"http://foo.mil",
|
5
|
+
"foo@bar.gc.ca",
|
6
|
+
"foo.gov.au",
|
7
|
+
"https://www.foo.gouv.fr",
|
8
|
+
"foo@ci.champaign.il.us",
|
9
|
+
"foo.bar.baz.gov.au",
|
10
|
+
"foo@bar.gov.uk",
|
11
|
+
".gov",
|
12
|
+
"foo.fed.us",
|
13
|
+
]
|
14
|
+
|
15
|
+
INVALID = [ "foo.bar.com",
|
16
|
+
"bar@foo.biz",
|
17
|
+
"http://www.foo.biz",
|
18
|
+
"foo.uk",
|
19
|
+
"gov",
|
20
|
+
"foo@k12.champaign.il.us",
|
21
|
+
"foo@kii.gov.by",
|
22
|
+
"foo",
|
23
|
+
"",
|
24
|
+
nil,
|
25
|
+
" ",
|
26
|
+
]
|
27
|
+
|
28
|
+
class TestGman < Test::Unit::TestCase
|
29
|
+
|
30
|
+
def domain_resolves?(domain)
|
31
|
+
res = Net::DNS::Resolver.new
|
32
|
+
res.nameservers = ["8.8.8.8","8.8.4.4", "208.67.222.222", "208.67.220.220"]
|
33
|
+
packet = res.search(domain, Net::DNS::NS)
|
34
|
+
packet.header.anCount > 0
|
35
|
+
end
|
36
|
+
|
37
|
+
should "recognize government email addresses and domains" do
|
38
|
+
VALID.each do |test|
|
39
|
+
assert_equal true, Gman::valid?(test), "#{test} should be detected as a valid government domain"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
should "not recognize non-government email addresses and domains" do
|
44
|
+
INVALID.each do |test|
|
45
|
+
assert_equal false, Gman::valid?(test), "#{test} should be detected as an invalid government domain"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
should "not contain any educational domains" do
|
50
|
+
Gman.list.each do |entry|
|
51
|
+
assert_equal false, Swot::is_academic?(entry.name), "#{entry.name} is an academic domain"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
should "not contain any invalid domains" do
|
56
|
+
Gman.list.each do |entry|
|
57
|
+
assert_equal true, PublicSuffix.valid?("foo.#{entry.name}"), "#{entry.name} is not a valid domain"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
should "not allow educational domains" do
|
62
|
+
assert_equal false, Gman::valid?("foo@gwu.edu")
|
63
|
+
end
|
64
|
+
|
65
|
+
should "properly parse domains from strings" do
|
66
|
+
assert_equal "github.gov", Gman::get_domain("foo@github.gov")
|
67
|
+
assert_equal "foo.github.gov", Gman::get_domain("foo.github.gov")
|
68
|
+
assert_equal "github.gov", Gman::get_domain("http://github.gov")
|
69
|
+
assert_equal "github.gov", Gman::get_domain("https://github.gov")
|
70
|
+
assert_equal ".gov", Gman::get_domain(".gov")
|
71
|
+
assert_equal nil, Gman.get_domain("foo")
|
72
|
+
end
|
73
|
+
|
74
|
+
should "validate mx records when asked" do
|
75
|
+
assert_equal true, Gman.valid?("foo@nasa.gov", true)
|
76
|
+
assert_equal false, Gman.valid?("foo@github.gov", true)
|
77
|
+
assert_equal true, Gman.valid?("foo@github.gov", false)
|
78
|
+
end
|
79
|
+
|
80
|
+
should "pass any url on the list" do
|
81
|
+
Gman.list.each do |entry|
|
82
|
+
assert_equal true, Gman.valid?("http://foo.#{entry.name}/bar"), "http://foo.#{entry.name}/bar is not a valid"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
should "pass any email on the list" do
|
87
|
+
Gman.list.each do |entry|
|
88
|
+
assert_equal true, Gman.valid?("foo@bar.#{entry.name}"), "foo@bar.#{entry.name} is not a valid"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
should "pass any domain on the list" do
|
93
|
+
Gman.list.each do |entry|
|
94
|
+
assert_equal true, Gman.valid?("foo.#{entry.name}"), "foo.#{entry.name} is not a valid domain"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
should "only contain resolvable domains" do
|
99
|
+
Gman.list.each do |entry|
|
100
|
+
assert_equal true, domain_resolves? domain
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
should "not err out on invalid domains" do
|
106
|
+
assert_equal false, Gman.valid?("foo@act.gov.au")
|
107
|
+
assert_equal "act.gov.au", Gman.get_domain("foo@act.gov.au")
|
108
|
+
assert_equal nil, Gman.domain_parts("foo@act.gov.au")
|
109
|
+
end
|
110
|
+
|
111
|
+
should "return public suffix domain" do
|
112
|
+
assert_equal PublicSuffix::Domain, Gman.domain_parts("whitehouse.gov").class
|
113
|
+
assert_equal NilClass, Gman.domain_parts("foo.bar").class
|
114
|
+
end
|
115
|
+
|
116
|
+
should "parse domain parts" do
|
117
|
+
assert_equal "gov", Gman.domain_parts("foo@bar.gov").tld
|
118
|
+
assert_equal "bar", Gman.domain_parts("foo.bar.gov").sld
|
119
|
+
assert_equal "bar", Gman.domain_parts("https://foo.bar.gov").sld
|
120
|
+
assert_equal "bar.gov", Gman.domain_parts("foo@bar.gov").domain
|
121
|
+
end
|
122
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: public_suffix
|