gman 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +6 -2
  2. data/gman.gemspec +1 -1
  3. data/lib/domains.txt +9910 -208
  4. data/test/helper.rb +20 -18
  5. data/test/test_gman.rb +122 -108
  6. metadata +2 -2
@@ -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
- class Test::Unit::TestCase
18
- end
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
@@ -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
- should "recognize government email addresses and domains" do
31
- VALID.each do |test|
32
- assert_equal true, Gman::valid?(test), "#{test} should be detected as a valid government domain"
33
- end
34
- end
35
-
36
- should "not recognize non-government email addresses and domains" do
37
- INVALID.each do |test|
38
- assert_equal false, Gman::valid?(test), "#{test} should be detected as an invalid government domain"
39
- end
40
- end
41
-
42
- should "not contain any educational domains" do
43
- Gman.list.each do |entry|
44
- assert_equal false, Swot::is_academic?(entry.name), "#{entry.name} is an academic domain"
45
- end
46
- end
47
-
48
- should "not contain any invalid domains" do
49
- Gman.list.each do |entry|
50
- assert_equal true, PublicSuffix.valid?("foo.#{entry.name}"), "#{entry.name} is not a valid domain"
51
- end
52
- end
53
-
54
- should "not allow educational domains" do
55
- assert_equal false, Gman::valid?("foo@gwu.edu")
56
- end
57
-
58
- should "properly parse domains from strings" do
59
- assert_equal "github.gov", Gman::get_domain("foo@github.gov")
60
- assert_equal "foo.github.gov", Gman::get_domain("foo.github.gov")
61
- assert_equal "github.gov", Gman::get_domain("http://github.gov")
62
- assert_equal "github.gov", Gman::get_domain("https://github.gov")
63
- assert_equal ".gov", Gman::get_domain(".gov")
64
- assert_equal nil, Gman.get_domain("foo")
65
- end
66
-
67
- should "validate mx records when asked" do
68
- assert_equal true, Gman.valid?("foo@nasa.gov", true)
69
- assert_equal false, Gman.valid?("foo@github.gov", true)
70
- assert_equal true, Gman.valid?("foo@github.gov", false)
71
- end
72
-
73
- should "pass any url on the list" do
74
- Gman.list.each do |entry|
75
- assert_equal true, Gman.valid?("http://foo.#{entry.name}/bar"), "http://foo.#{entry.name}/bar is not a valid"
76
- end
77
- end
78
-
79
- should "pass any email on the list" do
80
- Gman.list.each do |entry|
81
- assert_equal true, Gman.valid?("foo@bar.#{entry.name}"), "foo@bar.#{entry.name} is not a valid"
82
- end
83
- end
84
-
85
- should "pass any domain on the list" do
86
- Gman.list.each do |entry|
87
- assert_equal true, Gman.valid?("foo.#{entry.name}"), "foo.#{entry.name} is not a valid domain"
88
- end
89
- end
90
-
91
- should "not err out on invalid domains" do
92
- assert_equal false, Gman.valid?("foo@act.gov.au")
93
- assert_equal "act.gov.au", Gman.get_domain("foo@act.gov.au")
94
- assert_equal nil, Gman.domain_parts("foo@act.gov.au")
95
- end
96
-
97
- should "return public suffix domain" do
98
- assert_equal PublicSuffix::Domain, Gman.domain_parts("whitehouse.gov").class
99
- assert_equal NilClass, Gman.domain_parts("foo.bar").class
100
- end
101
-
102
- should "parse domain parts" do
103
- assert_equal "gov", Gman.domain_parts("foo@bar.gov").tld
104
- assert_equal "bar", Gman.domain_parts("foo.bar.gov").sld
105
- assert_equal "bar", Gman.domain_parts("https://foo.bar.gov").sld
106
- assert_equal "bar.gov", Gman.domain_parts("foo@bar.gov").domain
107
- end
108
- end
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.2.1
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-11-28 00:00:00.000000000 Z
12
+ date: 2013-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: public_suffix