gman 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +2 -0
- data/gman.gemspec +3 -3
- data/lib/domains.txt +196 -0
- data/lib/gman.rb +14 -27
- data/test/test_gman.rb +4 -4
- metadata +10 -14
- data/lib/domains.yml +0 -184
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 334405ee7b8d7e8277e8fa070f048725e8189f20
|
4
|
+
data.tar.gz: 579a6efbb98841f92c49775fd4902551407303d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbb201ea872a5a481285ff39da33a7b7db6fb75064970e1931edd60f0a55bf30341b65c19534bd82b902b486fd30d8f9a8ef7370b6f28c51394e6a2ecb09b185
|
7
|
+
data.tar.gz: 51e3c96b16b6dec39ca0817ad050489bcb982985b74a34f9a7212f84897ccdd3e1b0190ad4e4c83576ad73c58dfdf29e718b1e5e535fad6330b885081863d1de
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Gman Gem
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/benbalter/gman.png)](https://travis-ci.org/benbalter/gman) [![Gem Version](https://badge.fury.io/rb/gman.png)](http://badge.fury.io/rb/gman)
|
4
|
+
|
3
5
|
A ruby gem to check if the owner of a given email address or website is working for THE MAN (a.k.a verifies government domains). It does this by leveraging the power of the [Public Suffix List](http://publicsuffix.org/), and the associated [Ruby Gem](https://github.com/weppos/publicsuffix-ruby).
|
4
6
|
|
5
7
|
You could theoretically [use regex](https://gist.github.com/benbalter/6147066), but either you'll a bunch of false positives, or your regex will be insanely complicated. `gov.uk`, may be valid, for example, but `gov.fr` is not (it's `gouv.fr`, for what it's worth).
|
data/gman.gemspec
CHANGED
@@ -2,9 +2,9 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = "gman"
|
3
3
|
s.summary = "Check if a given domain or email address belong to a governemnt entity"
|
4
4
|
s.description = "A ruby gem to check if the owner of a given email address is working for THE MAN."
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
s.authors = ["Ben Balter"]
|
7
|
-
s.date = "2013-
|
7
|
+
s.date = "2013-09-30"
|
8
8
|
s.email = "ben.balter@github.com"
|
9
9
|
s.homepage = "https://github.com/benbalter/gman"
|
10
10
|
s.licenses = ["MIT"]
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
"CONTRIBUTING.md",
|
16
16
|
"LICENSE",
|
17
17
|
"lib/gman.rb",
|
18
|
-
"lib/domains.
|
18
|
+
"lib/domains.txt",
|
19
19
|
"script/build",
|
20
20
|
"script/release",
|
21
21
|
"gman.gemspec",
|
data/lib/domains.txt
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
// US Federal
|
2
|
+
fed.us
|
3
|
+
gov
|
4
|
+
mil
|
5
|
+
|
6
|
+
// Non-US gov
|
7
|
+
gc.ca
|
8
|
+
gob.bo
|
9
|
+
gob.cl
|
10
|
+
gob.do
|
11
|
+
gob.ec
|
12
|
+
gob.es
|
13
|
+
gob.gt
|
14
|
+
gob.hn
|
15
|
+
gob.mx
|
16
|
+
gob.pa
|
17
|
+
gob.pe
|
18
|
+
gob.pk
|
19
|
+
gouv.bj
|
20
|
+
gouv.ci
|
21
|
+
gouv.fr
|
22
|
+
gouv.ht
|
23
|
+
gouv.km
|
24
|
+
gouv.ml
|
25
|
+
gouv.rw
|
26
|
+
gouv.sn
|
27
|
+
gov.ac
|
28
|
+
gov.ae
|
29
|
+
gov.af
|
30
|
+
gov.al
|
31
|
+
gov.as
|
32
|
+
gov.au
|
33
|
+
gov.az
|
34
|
+
gov.ba
|
35
|
+
gov.bb
|
36
|
+
gov.bf
|
37
|
+
gov.bh
|
38
|
+
gov.bm
|
39
|
+
gov.bo
|
40
|
+
gov.br
|
41
|
+
gov.bs
|
42
|
+
gov.bt
|
43
|
+
gov.by
|
44
|
+
gov.bz
|
45
|
+
gov.cd
|
46
|
+
gov.cl
|
47
|
+
gov.cm
|
48
|
+
gov.cn
|
49
|
+
gov.co
|
50
|
+
gov.cu
|
51
|
+
gov.cx
|
52
|
+
gov.dm
|
53
|
+
gov.do
|
54
|
+
gov.dz
|
55
|
+
gov.ec
|
56
|
+
gov.ee
|
57
|
+
gov.eg
|
58
|
+
gov.ge
|
59
|
+
gov.gg
|
60
|
+
gov.gh
|
61
|
+
gov.gi
|
62
|
+
gov.gn
|
63
|
+
gov.gr
|
64
|
+
gov.hk
|
65
|
+
gov.ie
|
66
|
+
gov.im
|
67
|
+
gov.in
|
68
|
+
gov.iq
|
69
|
+
gov.ir
|
70
|
+
gov.is
|
71
|
+
gov.it
|
72
|
+
gov.je
|
73
|
+
gov.jo
|
74
|
+
gov.kg
|
75
|
+
gov.ki
|
76
|
+
gov.km
|
77
|
+
gov.kn
|
78
|
+
gov.kp
|
79
|
+
gov.ky
|
80
|
+
gov.kz
|
81
|
+
gov.la
|
82
|
+
gov.lb
|
83
|
+
gov.lc
|
84
|
+
gov.lk
|
85
|
+
gov.lr
|
86
|
+
gov.lt
|
87
|
+
gov.lv
|
88
|
+
gov.ly
|
89
|
+
gov.ma
|
90
|
+
gov.me
|
91
|
+
gov.mg
|
92
|
+
gov.mk
|
93
|
+
gov.ml
|
94
|
+
gov.mn
|
95
|
+
gov.mo
|
96
|
+
gov.mr
|
97
|
+
gov.mu
|
98
|
+
gov.mv
|
99
|
+
gov.mw
|
100
|
+
gov.my
|
101
|
+
gov.ng
|
102
|
+
gov.nr
|
103
|
+
gov.ph
|
104
|
+
gov.pk
|
105
|
+
gov.pl
|
106
|
+
gov.pn
|
107
|
+
gov.pr
|
108
|
+
gov.ps
|
109
|
+
gov.pt
|
110
|
+
gov.py
|
111
|
+
gov.qa
|
112
|
+
gov.rs
|
113
|
+
gov.ru
|
114
|
+
gov.rw
|
115
|
+
gov.sa
|
116
|
+
gov.sb
|
117
|
+
gov.sc
|
118
|
+
gov.sd
|
119
|
+
gov.sg
|
120
|
+
gov.sh
|
121
|
+
gov.sl
|
122
|
+
gov.st
|
123
|
+
gov.sx
|
124
|
+
gov.sy
|
125
|
+
gov.tj
|
126
|
+
gov.tl
|
127
|
+
gov.tm
|
128
|
+
gov.tn
|
129
|
+
gov.to
|
130
|
+
gov.tt
|
131
|
+
gov.tw
|
132
|
+
gov.ua
|
133
|
+
gov.vc
|
134
|
+
gov.ve
|
135
|
+
gov.vn
|
136
|
+
gov.ws
|
137
|
+
gub.uy
|
138
|
+
|
139
|
+
//non-US mil
|
140
|
+
mil.ac
|
141
|
+
mil.ae
|
142
|
+
mil.al
|
143
|
+
mil.az
|
144
|
+
mil.ba
|
145
|
+
mil.bo
|
146
|
+
mil.br
|
147
|
+
mil.by
|
148
|
+
mil.cl
|
149
|
+
mil.cn
|
150
|
+
mil.co
|
151
|
+
mil.do
|
152
|
+
mil.ec
|
153
|
+
mil.eg
|
154
|
+
mil.ge
|
155
|
+
mil.gh
|
156
|
+
mil.gt
|
157
|
+
mil.hn
|
158
|
+
mil.id
|
159
|
+
mil.in
|
160
|
+
mil.iq
|
161
|
+
mil.jo
|
162
|
+
mil.kg
|
163
|
+
mil.km
|
164
|
+
mil.kr
|
165
|
+
mil.kz
|
166
|
+
mil.lv
|
167
|
+
mil.mg
|
168
|
+
mil.mv
|
169
|
+
mil.my
|
170
|
+
mil.no
|
171
|
+
mil.pe
|
172
|
+
mil.ph
|
173
|
+
mil.pl
|
174
|
+
mil.py
|
175
|
+
mil.qa
|
176
|
+
mil.ru
|
177
|
+
mil.rw
|
178
|
+
mil.sh
|
179
|
+
mil.st
|
180
|
+
mil.sy
|
181
|
+
mil.tj
|
182
|
+
mil.tm
|
183
|
+
mil.to
|
184
|
+
mil.tw
|
185
|
+
mil.tz
|
186
|
+
mil.uy
|
187
|
+
mil.vc
|
188
|
+
mil.ve
|
189
|
+
|
190
|
+
// US State, County, Local
|
191
|
+
boudercounty.org
|
192
|
+
ci.champaign.il.us
|
193
|
+
ci.longmont.co.us
|
194
|
+
sfgov.org
|
195
|
+
state.de.us
|
196
|
+
state.or.us
|
data/lib/gman.rb
CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module Gman
|
5
5
|
|
6
|
-
VERSION='0.0.
|
6
|
+
VERSION='0.0.3'
|
7
7
|
|
8
8
|
class << self
|
9
9
|
|
@@ -18,35 +18,22 @@ module Gman
|
|
18
18
|
# Returns boolean true if a government domain
|
19
19
|
def valid?(text)
|
20
20
|
return false if text.nil?
|
21
|
-
text
|
21
|
+
domain = get_domain text
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
match_government_domain?(domain)
|
28
|
-
|
29
|
-
rescue PublicSuffix::DomainInvalid => di
|
30
|
-
false
|
31
|
-
|
32
|
-
rescue PublicSuffix::DomainNotAllowed => dna
|
33
|
-
false
|
34
|
-
end
|
23
|
+
# check using public suffix's standard logic
|
24
|
+
rule = list.find domain
|
25
|
+
return true if !rule.nil? && rule.allow?(domain)
|
35
26
|
|
27
|
+
# also allow for explicit matches to domain list
|
28
|
+
# but still make sure it's at least a valid domain
|
29
|
+
return false unless PublicSuffix.valid? domain
|
30
|
+
list.rules.any? { |rule| rule.value == domain }
|
36
31
|
end
|
37
32
|
|
38
|
-
#
|
39
|
-
#
|
40
|
-
def
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
# Parses YML domain list into an array
|
45
|
-
# TODO: Cache this
|
46
|
-
#
|
47
|
-
# Returns an array of TLD and TLD+SLD known government domains
|
48
|
-
def domains
|
49
|
-
YAML.load_file File.expand_path("../domains.yml", __FILE__)
|
33
|
+
# returns an instance of our custom public suffix list
|
34
|
+
# list behaves like PublicSuffix::List but is limited to our whitelisted domains
|
35
|
+
def list
|
36
|
+
@list || PublicSuffix::List::parse( File.new(File.join(File.dirname(__FILE__), "domains.txt"), "r:utf-8"))
|
50
37
|
end
|
51
38
|
|
52
39
|
# Get the FQDN name from a URL or email address.
|
@@ -54,7 +41,7 @@ module Gman
|
|
54
41
|
# Returns a string with the FQDN; nil if there's an error.
|
55
42
|
# Source: https://github.com/leereilly/swot/blob/master/lib/swot.rb#L190
|
56
43
|
def get_domain(text)
|
57
|
-
|
44
|
+
text.strip.downcase.match(domain_regex).captures.first
|
58
45
|
rescue
|
59
46
|
return nil
|
60
47
|
end
|
data/test/test_gman.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
VALID = ["foo.gov", "http://foo.mil", "foo@bar.gc.ca", "foo.gov.au", "http://www.foo.gouv.fr"]
|
4
|
-
INVALID = ["foo.bar.com", "bar@foo.biz", "http://www.foo.biz", "foo.uk", "gov"]
|
3
|
+
VALID = ["foo.gov", "http://foo.mil", "foo@bar.gc.ca", "foo.gov.au", "http://www.foo.gouv.fr", "foo@ci.champaign.il.us", "foo.bar.baz.gov.au"]
|
4
|
+
INVALID = ["foo.bar.com", "bar@foo.biz", "http://www.foo.biz", "foo.uk", "gov", "foo@k12.champaign.il.us"]
|
5
5
|
|
6
6
|
class TestGman < Test::Unit::TestCase
|
7
7
|
should "recognize government email addresses and domains" do
|
8
8
|
VALID.each do |test|
|
9
|
-
assert_equal Gman::
|
9
|
+
assert_equal true, Gman::valid?(test), "#{test} should be detected as a valid government domain"
|
10
10
|
end
|
11
11
|
INVALID.each do |test|
|
12
|
-
assert_equal Gman::
|
12
|
+
assert_equal false, Gman::valid?(test), "#{test} should be detected as an invalid government domain"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ben Balter
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: public_suffix
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: A ruby gem to check if the owner of a given email address is working
|
@@ -39,7 +36,7 @@ files:
|
|
39
36
|
- CONTRIBUTING.md
|
40
37
|
- LICENSE
|
41
38
|
- lib/gman.rb
|
42
|
-
- lib/domains.
|
39
|
+
- lib/domains.txt
|
43
40
|
- script/build
|
44
41
|
- script/release
|
45
42
|
- gman.gemspec
|
@@ -50,26 +47,25 @@ files:
|
|
50
47
|
homepage: https://github.com/benbalter/gman
|
51
48
|
licenses:
|
52
49
|
- MIT
|
50
|
+
metadata: {}
|
53
51
|
post_install_message:
|
54
52
|
rdoc_options: []
|
55
53
|
require_paths:
|
56
54
|
- lib
|
57
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
56
|
requirements:
|
60
|
-
- -
|
57
|
+
- - '>='
|
61
58
|
- !ruby/object:Gem::Version
|
62
59
|
version: '0'
|
63
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
61
|
requirements:
|
66
|
-
- -
|
62
|
+
- - '>='
|
67
63
|
- !ruby/object:Gem::Version
|
68
64
|
version: '0'
|
69
65
|
requirements: []
|
70
66
|
rubyforge_project:
|
71
|
-
rubygems_version:
|
67
|
+
rubygems_version: 2.0.3
|
72
68
|
signing_key:
|
73
|
-
specification_version:
|
69
|
+
specification_version: 4
|
74
70
|
summary: Check if a given domain or email address belong to a governemnt entity
|
75
71
|
test_files: []
|
data/lib/domains.yml
DELETED
@@ -1,184 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- fed.us
|
3
|
-
- gc.ca
|
4
|
-
- gob.bo
|
5
|
-
- gob.cl
|
6
|
-
- gob.do
|
7
|
-
- gob.ec
|
8
|
-
- gob.es
|
9
|
-
- gob.gt
|
10
|
-
- gob.hn
|
11
|
-
- gob.mx
|
12
|
-
- gob.pa
|
13
|
-
- gob.pe
|
14
|
-
- gob.pk
|
15
|
-
- gouv.bj
|
16
|
-
- gouv.ci
|
17
|
-
- gouv.fr
|
18
|
-
- gouv.ht
|
19
|
-
- gouv.km
|
20
|
-
- gouv.ml
|
21
|
-
- gouv.rw
|
22
|
-
- gouv.sn
|
23
|
-
- gov
|
24
|
-
- gov.ac
|
25
|
-
- gov.ae
|
26
|
-
- gov.af
|
27
|
-
- gov.al
|
28
|
-
- gov.as
|
29
|
-
- gov.au
|
30
|
-
- gov.az
|
31
|
-
- gov.ba
|
32
|
-
- gov.bb
|
33
|
-
- gov.bf
|
34
|
-
- gov.bh
|
35
|
-
- gov.bm
|
36
|
-
- gov.bo
|
37
|
-
- gov.br
|
38
|
-
- gov.bs
|
39
|
-
- gov.bt
|
40
|
-
- gov.by
|
41
|
-
- gov.bz
|
42
|
-
- gov.cd
|
43
|
-
- gov.cl
|
44
|
-
- gov.cm
|
45
|
-
- gov.cn
|
46
|
-
- gov.co
|
47
|
-
- gov.cu
|
48
|
-
- gov.cx
|
49
|
-
- gov.dm
|
50
|
-
- gov.do
|
51
|
-
- gov.dz
|
52
|
-
- gov.ec
|
53
|
-
- gov.ee
|
54
|
-
- gov.eg
|
55
|
-
- gov.ge
|
56
|
-
- gov.gg
|
57
|
-
- gov.gh
|
58
|
-
- gov.gi
|
59
|
-
- gov.gn
|
60
|
-
- gov.gr
|
61
|
-
- gov.hk
|
62
|
-
- gov.ie
|
63
|
-
- gov.im
|
64
|
-
- gov.in
|
65
|
-
- gov.iq
|
66
|
-
- gov.ir
|
67
|
-
- gov.is
|
68
|
-
- gov.it
|
69
|
-
- gov.je
|
70
|
-
- gov.jo
|
71
|
-
- gov.kg
|
72
|
-
- gov.ki
|
73
|
-
- gov.km
|
74
|
-
- gov.kn
|
75
|
-
- gov.kp
|
76
|
-
- gov.ky
|
77
|
-
- gov.kz
|
78
|
-
- gov.la
|
79
|
-
- gov.lb
|
80
|
-
- gov.lc
|
81
|
-
- gov.lk
|
82
|
-
- gov.lr
|
83
|
-
- gov.lt
|
84
|
-
- gov.lv
|
85
|
-
- gov.ly
|
86
|
-
- gov.ma
|
87
|
-
- gov.me
|
88
|
-
- gov.mg
|
89
|
-
- gov.mk
|
90
|
-
- gov.ml
|
91
|
-
- gov.mn
|
92
|
-
- gov.mo
|
93
|
-
- gov.mr
|
94
|
-
- gov.mu
|
95
|
-
- gov.mv
|
96
|
-
- gov.mw
|
97
|
-
- gov.my
|
98
|
-
- gov.ng
|
99
|
-
- gov.nr
|
100
|
-
- gov.ph
|
101
|
-
- gov.pk
|
102
|
-
- gov.pl
|
103
|
-
- gov.pn
|
104
|
-
- gov.pr
|
105
|
-
- gov.ps
|
106
|
-
- gov.pt
|
107
|
-
- gov.py
|
108
|
-
- gov.qa
|
109
|
-
- gov.rs
|
110
|
-
- gov.ru
|
111
|
-
- gov.rw
|
112
|
-
- gov.sa
|
113
|
-
- gov.sb
|
114
|
-
- gov.sc
|
115
|
-
- gov.sd
|
116
|
-
- gov.sg
|
117
|
-
- gov.sh
|
118
|
-
- gov.sl
|
119
|
-
- gov.st
|
120
|
-
- gov.sx
|
121
|
-
- gov.sy
|
122
|
-
- gov.tj
|
123
|
-
- gov.tl
|
124
|
-
- gov.tm
|
125
|
-
- gov.tn
|
126
|
-
- gov.to
|
127
|
-
- gov.tt
|
128
|
-
- gov.tw
|
129
|
-
- gov.ua
|
130
|
-
- gov.vc
|
131
|
-
- gov.ve
|
132
|
-
- gov.vn
|
133
|
-
- gov.ws
|
134
|
-
- gub.uy
|
135
|
-
- mil
|
136
|
-
- mil.ac
|
137
|
-
- mil.ae
|
138
|
-
- mil.al
|
139
|
-
- mil.az
|
140
|
-
- mil.ba
|
141
|
-
- mil.bo
|
142
|
-
- mil.br
|
143
|
-
- mil.by
|
144
|
-
- mil.cl
|
145
|
-
- mil.cn
|
146
|
-
- mil.co
|
147
|
-
- mil.do
|
148
|
-
- mil.ec
|
149
|
-
- mil.eg
|
150
|
-
- mil.ge
|
151
|
-
- mil.gh
|
152
|
-
- mil.gt
|
153
|
-
- mil.hn
|
154
|
-
- mil.id
|
155
|
-
- mil.in
|
156
|
-
- mil.iq
|
157
|
-
- mil.jo
|
158
|
-
- mil.kg
|
159
|
-
- mil.km
|
160
|
-
- mil.kr
|
161
|
-
- mil.kz
|
162
|
-
- mil.lv
|
163
|
-
- mil.mg
|
164
|
-
- mil.mv
|
165
|
-
- mil.my
|
166
|
-
- mil.no
|
167
|
-
- mil.pe
|
168
|
-
- mil.ph
|
169
|
-
- mil.pl
|
170
|
-
- mil.py
|
171
|
-
- mil.qa
|
172
|
-
- mil.ru
|
173
|
-
- mil.rw
|
174
|
-
- mil.sh
|
175
|
-
- mil.st
|
176
|
-
- mil.sy
|
177
|
-
- mil.tj
|
178
|
-
- mil.tm
|
179
|
-
- mil.to
|
180
|
-
- mil.tw
|
181
|
-
- mil.tz
|
182
|
-
- mil.uy
|
183
|
-
- mil.vc
|
184
|
-
- mil.ve
|