gman 3.1.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/domains.txt +7 -1190
- data/lib/gman.rb +31 -0
- data/lib/gman/version.rb +1 -1
- metadata +2 -9
- data/.gitignore +0 -4
- data/Rakefile +0 -29
- data/gman.gemspec +0 -43
- data/script/build +0 -27
- data/script/release +0 -38
- data/test/helper.rb +0 -21
- data/test/test_gman.rb +0 -94
data/lib/gman.rb
CHANGED
@@ -46,6 +46,28 @@ class Gman
|
|
46
46
|
$
|
47
47
|
}xi
|
48
48
|
|
49
|
+
# Second level .us domains for states and locality
|
50
|
+
# See http://en.wikipedia.org/wiki/.us
|
51
|
+
#
|
52
|
+
# Examples:
|
53
|
+
# * foo.state.il.us
|
54
|
+
# * ci.foo.il.us
|
55
|
+
#
|
56
|
+
# Not:
|
57
|
+
# * state.foo.il.us
|
58
|
+
# * foo.ci.il.us
|
59
|
+
# * k12.il.us
|
60
|
+
# * ci.foo.zx.us
|
61
|
+
LOCALITY_REGEX = %r{
|
62
|
+
(
|
63
|
+
(state|dst|cog)
|
64
|
+
|
|
65
|
+
(ci|town|vil|co)\.[a-z-]+
|
66
|
+
)
|
67
|
+
\.(ak|al|ar|az|ca|co|ct|dc|de|fl|ga|hi|ia|id|il|in|ks|ky|la|ma|md|me|mi|mn|mo|ms|mt|nc|nd|ne|nh|nj|nm|nv|ny|oh|ok|or|pa|ri|sc|sd|tn|tx|um|ut|va|vt|wa|wi|wv|wy)
|
68
|
+
\.us
|
69
|
+
}x
|
70
|
+
|
49
71
|
# Map last part of TLD to alpha2 country code
|
50
72
|
ALPHA2_MAP = {
|
51
73
|
:ac => 'sh',
|
@@ -145,6 +167,9 @@ class Gman
|
|
145
167
|
# Ensure non-edu
|
146
168
|
return false if Swot::is_academic?(domain)
|
147
169
|
|
170
|
+
# Check for locality by regex
|
171
|
+
return true if locality?
|
172
|
+
|
148
173
|
# check using public suffix's standard logic
|
149
174
|
rule = Gman.list.find domain
|
150
175
|
return true if !rule.nil? && rule.allow?(domain)
|
@@ -160,6 +185,11 @@ class Gman
|
|
160
185
|
!!(@text =~ EMAIL_REGEX)
|
161
186
|
end
|
162
187
|
|
188
|
+
# Is this domain a .us state or locality?
|
189
|
+
def locality?
|
190
|
+
!!(domain =~ LOCALITY_REGEX)
|
191
|
+
end
|
192
|
+
|
163
193
|
# Helper function to return the public suffix domain object
|
164
194
|
#
|
165
195
|
# Supports all domain strings (URLs, emails)
|
@@ -196,4 +226,5 @@ class Gman
|
|
196
226
|
def inspect
|
197
227
|
"#<Gman domain=\"#{domain}\" valid=#{valid?}>"
|
198
228
|
end
|
229
|
+
|
199
230
|
end
|
data/lib/gman/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: public_suffix
|
@@ -130,21 +130,14 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
-
- ".gitignore"
|
134
133
|
- CONTRIBUTING.md
|
135
134
|
- Gemfile
|
136
135
|
- LICENSE
|
137
136
|
- README.md
|
138
|
-
- Rakefile
|
139
137
|
- bin/gman_filter
|
140
|
-
- gman.gemspec
|
141
138
|
- lib/domains.txt
|
142
139
|
- lib/gman.rb
|
143
140
|
- lib/gman/version.rb
|
144
|
-
- script/build
|
145
|
-
- script/release
|
146
|
-
- test/helper.rb
|
147
|
-
- test/test_gman.rb
|
148
141
|
homepage: https://github.com/benbalter/gman
|
149
142
|
licenses:
|
150
143
|
- MIT
|
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,29 +0,0 @@
|
|
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 'rake'
|
11
|
-
|
12
|
-
require 'rake/testtask'
|
13
|
-
Rake::TestTask.new(:test) do |test|
|
14
|
-
test.libs << 'lib' << 'test'
|
15
|
-
test.pattern = 'test/**/test_gman*.rb'
|
16
|
-
test.verbose = true
|
17
|
-
end
|
18
|
-
|
19
|
-
desc "Open console with gman loaded"
|
20
|
-
task :console do
|
21
|
-
exec "irb -r ./lib/gman.rb"
|
22
|
-
end
|
23
|
-
|
24
|
-
desc "Validate the domain list"
|
25
|
-
Rake::TestTask.new(:domains) do |test|
|
26
|
-
test.libs << 'lib' << 'test'
|
27
|
-
test.pattern = 'test/**/test_domains*.rb'
|
28
|
-
test.verbose = true
|
29
|
-
end
|
data/gman.gemspec
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.expand_path("lib/gman/version", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "gman"
|
5
|
-
s.summary = "Check if a given domain or email address belong to a governemnt entity"
|
6
|
-
s.description = "A ruby gem to check if the owner of a given email address is working for THE MAN."
|
7
|
-
s.version = Gman::VERSION
|
8
|
-
s.authors = ["Ben Balter"]
|
9
|
-
s.email = "ben.balter@github.com"
|
10
|
-
s.homepage = "https://github.com/benbalter/gman"
|
11
|
-
s.licenses = ["MIT"]
|
12
|
-
|
13
|
-
s.files = [
|
14
|
-
"Gemfile",
|
15
|
-
"README.md",
|
16
|
-
"CONTRIBUTING.md",
|
17
|
-
"LICENSE",
|
18
|
-
"lib/gman.rb",
|
19
|
-
"lib/domains.txt",
|
20
|
-
"lib/gman/version.rb",
|
21
|
-
"script/build",
|
22
|
-
"script/release",
|
23
|
-
"bin/gman_filter",
|
24
|
-
"gman.gemspec",
|
25
|
-
"test/helper.rb",
|
26
|
-
"test/test_gman.rb",
|
27
|
-
"Rakefile",
|
28
|
-
".gitignore"
|
29
|
-
]
|
30
|
-
|
31
|
-
s.executables << "gman_filter"
|
32
|
-
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
s.add_dependency( "public_suffix", '~> 1.4')
|
35
|
-
s.add_dependency( "swot", '~> 0.3.1' )
|
36
|
-
s.add_dependency( "addressable", '~> 2.3' )
|
37
|
-
s.add_dependency( "iso_country_codes", "~> 0.4" )
|
38
|
-
|
39
|
-
s.add_development_dependency( "rake" )
|
40
|
-
s.add_development_dependency( "shoulda" )
|
41
|
-
s.add_development_dependency( "rdoc" )
|
42
|
-
s.add_development_dependency( "bundler" )
|
43
|
-
end
|
data/script/build
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Propagates an initial list of best-guess government domains
|
3
|
-
|
4
|
-
require "public_suffix"
|
5
|
-
require "yaml"
|
6
|
-
|
7
|
-
# https://gist.github.com/benbalter/6147066
|
8
|
-
REGEX = /(\.g[ou]{1,2}(v|b|vt)|\.mil|\.gc|\.fed)(\.[a-z]{2})?$/i
|
9
|
-
|
10
|
-
YAML_FILE = File.dirname(__FILE__) + "/../lib/domains.yml"
|
11
|
-
domains = YAML.load_file YAML_FILE
|
12
|
-
domains = [] unless domains
|
13
|
-
|
14
|
-
PublicSuffix::List.default.each do |rule|
|
15
|
-
domain = nil
|
16
|
-
|
17
|
-
if rule.parts.length == 1
|
18
|
-
domain = rule.parts.first if ".#{rule.value}" =~ REGEX
|
19
|
-
else
|
20
|
-
domain = rule.parts.pop(2).join(".") if ".#{rule.value}" =~ REGEX
|
21
|
-
end
|
22
|
-
|
23
|
-
domains.push domain unless domain.nil? or domains.include? domain
|
24
|
-
end
|
25
|
-
|
26
|
-
domains = domains.sort
|
27
|
-
File.open(YAML_FILE, 'w+') {|f| f.write(domains.to_yaml)}
|
data/script/release
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
# Tag and push a release.
|
3
|
-
|
4
|
-
set -e
|
5
|
-
|
6
|
-
# Make sure we're in the project root.
|
7
|
-
|
8
|
-
cd $(dirname "$0")/..
|
9
|
-
|
10
|
-
# Build a new gem archive.
|
11
|
-
|
12
|
-
rm -rf gman-*.gem
|
13
|
-
gem build -q gman.gemspec
|
14
|
-
|
15
|
-
# Make sure we're on the master branch.
|
16
|
-
|
17
|
-
(git branch | grep -q '* master') || {
|
18
|
-
echo "Only release from the master branch."
|
19
|
-
exit 1
|
20
|
-
}
|
21
|
-
|
22
|
-
# Figure out what version we're releasing.
|
23
|
-
|
24
|
-
tag=v`ls gman-*.gem | sed 's/^gman-\(.*\)\.gem$/\1/'`
|
25
|
-
|
26
|
-
# Make sure we haven't released this version before.
|
27
|
-
|
28
|
-
git fetch -t origin
|
29
|
-
|
30
|
-
(git tag -l | grep -q "$tag") && {
|
31
|
-
echo "Whoops, there's already a '${tag}' tag."
|
32
|
-
exit 1
|
33
|
-
}
|
34
|
-
|
35
|
-
# Tag it and bag it.
|
36
|
-
|
37
|
-
gem push gman-*.gem && git tag "$tag" &&
|
38
|
-
git push origin master && git push origin "$tag"
|
data/test/helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'shoulda'
|
14
|
-
|
15
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
-
require 'gman'
|
18
|
-
require 'net/dns'
|
19
|
-
require 'net/dns/resolver'
|
20
|
-
require './lib/gman/parser'
|
21
|
-
|
data/test/test_gman.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '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 < Minitest::Test
|
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 allow educational domains" do
|
43
|
-
assert_equal false, Gman::valid?("foo@gwu.edu")
|
44
|
-
end
|
45
|
-
|
46
|
-
should "properly parse domains from strings" do
|
47
|
-
assert_equal "github.gov", Gman.new("foo@github.gov").domain
|
48
|
-
assert_equal "foo.github.gov", Gman::new("foo.github.gov").domain
|
49
|
-
assert_equal "github.gov", Gman::new("http://github.gov").domain
|
50
|
-
assert_equal "github.gov", Gman::new("https://github.gov").domain
|
51
|
-
assert_equal ".gov", Gman::new(".gov").domain
|
52
|
-
assert_equal nil, Gman.new("foo").domain
|
53
|
-
end
|
54
|
-
|
55
|
-
should "not err out on invalid domains" do
|
56
|
-
assert_equal false, Gman.valid?("foo@gov.invalid")
|
57
|
-
assert_equal "gov.invalid", Gman.new("foo@gov.invalid").domain
|
58
|
-
assert_equal nil, Gman.new("foo@gov.invalid").domain_parts
|
59
|
-
end
|
60
|
-
|
61
|
-
should "return public suffix domain" do
|
62
|
-
assert_equal PublicSuffix::Domain, Gman.new("whitehouse.gov").domain_parts.class
|
63
|
-
assert_equal NilClass, Gman.new("foo.invalid").domain_parts.class
|
64
|
-
end
|
65
|
-
|
66
|
-
should "parse domain parts" do
|
67
|
-
assert_equal "gov", Gman.new("foo@bar.gov").domain_parts.tld
|
68
|
-
assert_equal "bar", Gman.new("foo.bar.gov").domain_parts.sld
|
69
|
-
assert_equal "bar", Gman.new("https://foo.bar.gov").domain_parts.sld
|
70
|
-
assert_equal "bar.gov", Gman.new("foo@bar.gov").domain_parts.domain
|
71
|
-
end
|
72
|
-
|
73
|
-
should "not err out on invalid hosts" do
|
74
|
-
assert_equal nil, Gman.new("</@foo.com").domain
|
75
|
-
end
|
76
|
-
|
77
|
-
should "returns the path to domains.txt" do
|
78
|
-
assert_equal true, File.exists?(Gman.list_path)
|
79
|
-
end
|
80
|
-
|
81
|
-
should "parse the alpha2" do
|
82
|
-
assert_equal "us", Gman.new("whitehouse.gov").alpha2
|
83
|
-
assert_equal "us", Gman.new("army.mil").alpha2
|
84
|
-
assert_equal "gb", Gman.new("foo.gov.uk").alpha2
|
85
|
-
assert_equal "ca", Gman.new("gov.ca").alpha2
|
86
|
-
end
|
87
|
-
|
88
|
-
should "determine a domain's country" do
|
89
|
-
assert_equal "United States", Gman.new("whitehouse.gov").country.name
|
90
|
-
assert_equal "United States", Gman.new("army.mil").country.name
|
91
|
-
assert_equal "United Kingdom", Gman.new("foo.gov.uk").country.name
|
92
|
-
assert_equal "Canada", Gman.new("foo.gc.ca").country.name
|
93
|
-
end
|
94
|
-
end
|