public_suffix 4.0.6 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +20 -3
  5. data/SECURITY.md +2 -81
  6. data/data/list.txt +4262 -2211
  7. data/lib/public_suffix/domain.rb +1 -1
  8. data/lib/public_suffix/errors.rb +1 -1
  9. data/lib/public_suffix/list.rb +4 -4
  10. data/lib/public_suffix/rule.rb +16 -16
  11. data/lib/public_suffix/version.rb +5 -4
  12. data/lib/public_suffix.rb +12 -14
  13. metadata +10 -64
  14. data/.github/FUNDING.yml +0 -12
  15. data/.github/workflows/tests.yml +0 -36
  16. data/.gitignore +0 -8
  17. data/.rubocop.yml +0 -36
  18. data/.rubocop_opinionated.yml +0 -157
  19. data/.travis.yml +0 -23
  20. data/Gemfile +0 -15
  21. data/Rakefile +0 -51
  22. data/bin/console +0 -15
  23. data/codecov.yml +0 -12
  24. data/public_suffix.gemspec +0 -29
  25. data/test/.empty +0 -2
  26. data/test/acceptance_test.rb +0 -131
  27. data/test/benchmarks/bm_find.rb +0 -66
  28. data/test/benchmarks/bm_find_all.rb +0 -102
  29. data/test/benchmarks/bm_names.rb +0 -91
  30. data/test/benchmarks/bm_select.rb +0 -26
  31. data/test/benchmarks/bm_select_incremental.rb +0 -25
  32. data/test/benchmarks/bm_valid.rb +0 -101
  33. data/test/profilers/domain_profiler.rb +0 -12
  34. data/test/profilers/find_profiler.rb +0 -12
  35. data/test/profilers/find_profiler_jp.rb +0 -12
  36. data/test/profilers/initialization_profiler.rb +0 -11
  37. data/test/profilers/list_profsize.rb +0 -11
  38. data/test/profilers/object_binsize.rb +0 -57
  39. data/test/psl_test.rb +0 -52
  40. data/test/test_helper.rb +0 -18
  41. data/test/tests.txt +0 -98
  42. data/test/unit/domain_test.rb +0 -106
  43. data/test/unit/errors_test.rb +0 -25
  44. data/test/unit/list_test.rb +0 -241
  45. data/test/unit/public_suffix_test.rb +0 -188
  46. data/test/unit/rule_test.rb +0 -222
@@ -1,188 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class PublicSuffixTest < Minitest::Test
6
-
7
- def test_private_domains_enabled_by_default
8
- domain = PublicSuffix.parse("www.example.blogspot.com")
9
- assert_equal "blogspot.com", domain.tld
10
- end
11
-
12
- def test_private_domains_disable
13
- data = File.read(PublicSuffix::List::DEFAULT_LIST_PATH)
14
- PublicSuffix::List.default = PublicSuffix::List.parse(data, private_domains: false)
15
- domain = PublicSuffix.parse("www.example.blogspot.com")
16
- assert_equal "com", domain.tld
17
- ensure
18
- PublicSuffix::List.default = nil
19
- end
20
-
21
-
22
- def test_self_parse_a_domain_with_tld_and_sld
23
- domain = PublicSuffix.parse("example.com")
24
- assert_instance_of PublicSuffix::Domain, domain
25
- assert_equal "com", domain.tld
26
- assert_equal "example", domain.sld
27
- assert_nil domain.trd
28
-
29
- domain = PublicSuffix.parse("example.co.uk")
30
- assert_instance_of PublicSuffix::Domain, domain
31
- assert_equal "co.uk", domain.tld
32
- assert_equal "example", domain.sld
33
- assert_nil domain.trd
34
- end
35
-
36
- def test_self_parse_a_domain_with_tld_and_sld_and_trd
37
- domain = PublicSuffix.parse("alpha.example.com")
38
- assert_instance_of PublicSuffix::Domain, domain
39
- assert_equal "com", domain.tld
40
- assert_equal "example", domain.sld
41
- assert_equal "alpha", domain.trd
42
-
43
- domain = PublicSuffix.parse("alpha.example.co.uk")
44
- assert_instance_of PublicSuffix::Domain, domain
45
- assert_equal "co.uk", domain.tld
46
- assert_equal "example", domain.sld
47
- assert_equal "alpha", domain.trd
48
- end
49
-
50
- def test_self_parse_a_domain_with_tld_and_sld_and_4rd
51
- domain = PublicSuffix.parse("one.two.example.com")
52
- assert_instance_of PublicSuffix::Domain, domain
53
- assert_equal "com", domain.tld
54
- assert_equal "example", domain.sld
55
- assert_equal "one.two", domain.trd
56
-
57
- domain = PublicSuffix.parse("one.two.example.co.uk")
58
- assert_instance_of PublicSuffix::Domain, domain
59
- assert_equal "co.uk", domain.tld
60
- assert_equal "example", domain.sld
61
- assert_equal "one.two", domain.trd
62
- end
63
-
64
- def test_self_parse_name_fqdn
65
- domain = PublicSuffix.parse("www.example.com.")
66
- assert_instance_of PublicSuffix::Domain, domain
67
- assert_equal "com", domain.tld
68
- assert_equal "example", domain.sld
69
- assert_equal "www", domain.trd
70
- end
71
-
72
- def test_self_parse_with_custom_list
73
- list = PublicSuffix::List.new
74
- list << PublicSuffix::Rule.factory("test")
75
-
76
- domain = PublicSuffix.parse("www.example.test", list: list)
77
- assert_instance_of PublicSuffix::Domain, domain
78
- assert_equal "test", domain.tld
79
- assert_equal "example", domain.sld
80
- assert_equal "www", domain.trd
81
- end
82
-
83
- def test_self_parse_with_notlisted_name
84
- domain = PublicSuffix.parse("example.tldnotlisted")
85
- assert_instance_of PublicSuffix::Domain, domain
86
- assert_equal "tldnotlisted", domain.tld
87
- assert_equal "example", domain.sld
88
- assert_nil domain.trd
89
- end
90
-
91
- def test_self_parse_with_unallowed_domain
92
- error = assert_raises(PublicSuffix::DomainNotAllowed) { PublicSuffix.parse("example.bd") }
93
- assert_match(/example\.bd/, error.message)
94
- end
95
-
96
- def test_self_parse_with_uri
97
- error = assert_raises(PublicSuffix::DomainInvalid) { PublicSuffix.parse("http://google.com") }
98
- assert_match(%r{http://google\.com}, error.message)
99
- end
100
-
101
-
102
- def test_self_valid
103
- assert PublicSuffix.valid?("google.com")
104
- assert PublicSuffix.valid?("www.google.com")
105
- assert PublicSuffix.valid?("google.co.uk")
106
- assert PublicSuffix.valid?("www.google.co.uk")
107
- end
108
-
109
- def test_self_valid_with_notlisted_name
110
- assert PublicSuffix.valid?("google.tldnotlisted")
111
- assert PublicSuffix.valid?("www.google.tldnotlisted")
112
- end
113
-
114
- # def test_self_valid_with_fully_qualified_domain_name
115
- # assert PublicSuffix.valid?("google.com.")
116
- # assert PublicSuffix.valid?("google.co.uk.")
117
- # assert !PublicSuffix.valid?("google.tldnotlisted.")
118
- # end
119
-
120
-
121
- def test_self_domain
122
- assert_equal "google.com", PublicSuffix.domain("google.com")
123
- assert_equal "google.com", PublicSuffix.domain("www.google.com")
124
- assert_equal "google.co.uk", PublicSuffix.domain("google.co.uk")
125
- assert_equal "google.co.uk", PublicSuffix.domain("www.google.co.uk")
126
- end
127
-
128
- def test_self_domain_with_notlisted_name
129
- assert_equal "example.tldnotlisted", PublicSuffix.domain("example.tldnotlisted")
130
- end
131
-
132
- def test_self_domain_with_unallowed_name
133
- assert_nil PublicSuffix.domain("example.bd")
134
- end
135
-
136
- def test_self_domain_with_blank_sld
137
- assert_nil PublicSuffix.domain("com")
138
- assert_nil PublicSuffix.domain(".com")
139
- end
140
-
141
-
142
- def test_self_normalize
143
- [
144
- ["com", "com"],
145
- ["example.com", "example.com"],
146
- ["www.example.com", "www.example.com"],
147
-
148
- ["example.com.", "example.com"], # strip FQDN
149
- [" example.com ", "example.com"], # strip spaces
150
- ["Example.COM", "example.com"], # downcase
151
- ].each do |input, output|
152
- assert_equal output, PublicSuffix.normalize(input)
153
- end
154
- end
155
-
156
- def test_normalize_blank
157
- [
158
- nil,
159
- "",
160
- " ",
161
- ].each do |input|
162
- error = PublicSuffix.normalize(input)
163
- assert_instance_of PublicSuffix::DomainInvalid, error
164
- assert_equal "Name is blank", error.message
165
- end
166
- end
167
-
168
- def test_normalize_scheme
169
- [
170
- "https://google.com",
171
- ].each do |input|
172
- error = PublicSuffix.normalize(input)
173
- assert_instance_of PublicSuffix::DomainInvalid, error
174
- assert_match(/scheme/, error.message)
175
- end
176
- end
177
-
178
- def test_normalize_leading_dot
179
- [
180
- ".google.com",
181
- ].each do |input|
182
- error = PublicSuffix.normalize(input)
183
- assert_instance_of PublicSuffix::DomainInvalid, error
184
- assert_match "Name starts with a dot", error.message
185
- end
186
- end
187
-
188
- end
@@ -1,222 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class PublicSuffix::RuleTest < Minitest::Test
6
-
7
- def test_factory_should_return_rule_normal
8
- rule = PublicSuffix::Rule.factory("com")
9
- assert_instance_of PublicSuffix::Rule::Normal, rule
10
-
11
- rule = PublicSuffix::Rule.factory("verona.it")
12
- assert_instance_of PublicSuffix::Rule::Normal, rule
13
- end
14
-
15
- def test_factory_should_return_rule_exception
16
- rule = PublicSuffix::Rule.factory("!british-library.uk")
17
- assert_instance_of PublicSuffix::Rule::Exception, rule
18
- end
19
-
20
- def test_factory_should_return_rule_wildcard
21
- rule = PublicSuffix::Rule.factory("*.do")
22
- assert_instance_of PublicSuffix::Rule::Wildcard, rule
23
-
24
- rule = PublicSuffix::Rule.factory("*.sch.uk")
25
- assert_instance_of PublicSuffix::Rule::Wildcard, rule
26
- end
27
-
28
-
29
- def test_default_returns_default_wildcard
30
- default = PublicSuffix::Rule.default
31
- assert_equal PublicSuffix::Rule::Wildcard.build("*"), default
32
- assert_equal %w( example tldnotlisted ), default.decompose("example.tldnotlisted")
33
- assert_equal %w( www.example tldnotlisted ), default.decompose("www.example.tldnotlisted")
34
- end
35
-
36
- end
37
-
38
-
39
- class PublicSuffix::RuleBaseTest < Minitest::Test
40
-
41
- class ::PublicSuffix::Rule::Test < ::PublicSuffix::Rule::Base
42
- end
43
-
44
- def setup
45
- @klass = PublicSuffix::Rule::Base
46
- end
47
-
48
-
49
- def test_initialize
50
- rule = @klass.new(value: "verona.it")
51
- assert_instance_of @klass, rule
52
- assert_equal "verona.it", rule.value
53
- end
54
-
55
-
56
- def test_equality_with_self
57
- rule = PublicSuffix::Rule::Base.new(value: "foo")
58
- assert_equal rule, rule
59
- end
60
-
61
- # rubocop:disable Style/SingleLineMethods
62
- def test_equality_with_internals
63
- assert_equal @klass.new(value: "foo"), @klass.new(value: "foo")
64
- refute_equal @klass.new(value: "foo"), @klass.new(value: "bar")
65
- refute_equal @klass.new(value: "foo"), PublicSuffix::Rule::Test.new(value: "foo")
66
- refute_equal @klass.new(value: "foo"), PublicSuffix::Rule::Test.new(value: "bar")
67
- refute_equal @klass.new(value: "foo"), Class.new { def name; foo; end }.new
68
- end
69
- # rubocop:enable Style/SingleLineMethods
70
-
71
- def test_match
72
- [
73
- # standard match
74
- [PublicSuffix::Rule.factory("uk"), "uk", true],
75
- [PublicSuffix::Rule.factory("uk"), "example.uk", true],
76
- [PublicSuffix::Rule.factory("uk"), "example.co.uk", true],
77
- [PublicSuffix::Rule.factory("co.uk"), "example.co.uk", true],
78
-
79
- # FIXME
80
- # [PublicSuffix::Rule.factory("*.com"), "com", false],
81
- [PublicSuffix::Rule.factory("*.com"), "example.com", true],
82
- [PublicSuffix::Rule.factory("*.com"), "foo.example.com", true],
83
- [PublicSuffix::Rule.factory("!example.com"), "com", false],
84
- [PublicSuffix::Rule.factory("!example.com"), "example.com", true],
85
- [PublicSuffix::Rule.factory("!example.com"), "foo.example.com", true],
86
-
87
- # TLD mismatch
88
- [PublicSuffix::Rule.factory("gk"), "example.uk", false],
89
- [PublicSuffix::Rule.factory("gk"), "example.co.uk", false],
90
- [PublicSuffix::Rule.factory("co.uk"), "uk", false],
91
-
92
- # general mismatch
93
- [PublicSuffix::Rule.factory("uk.co"), "example.co.uk", false],
94
- [PublicSuffix::Rule.factory("go.uk"), "example.co.uk", false],
95
- [PublicSuffix::Rule.factory("co.uk"), "uk", false],
96
-
97
- # partial matches/mismatches
98
- [PublicSuffix::Rule.factory("co"), "example.co.uk", false],
99
- [PublicSuffix::Rule.factory("example"), "example.uk", false],
100
- [PublicSuffix::Rule.factory("le.it"), "example.it", false],
101
- [PublicSuffix::Rule.factory("le.it"), "le.it", true],
102
- [PublicSuffix::Rule.factory("le.it"), "foo.le.it", true],
103
-
104
- ].each do |rule, input, expected|
105
- assert_equal expected, rule.match?(input)
106
- end
107
- end
108
-
109
-
110
- def test_parts
111
- assert_raises(NotImplementedError) { @klass.new(value: "com").parts }
112
- end
113
-
114
- def test_decompose
115
- assert_raises(NotImplementedError) { @klass.new(value: "com").decompose("google.com") }
116
- end
117
-
118
- end
119
-
120
-
121
- class PublicSuffix::RuleNormalTest < Minitest::Test
122
-
123
- def setup
124
- @klass = PublicSuffix::Rule::Normal
125
- end
126
-
127
-
128
- def test_build
129
- rule = @klass.build("verona.it")
130
- assert_instance_of @klass, rule
131
- assert_equal "verona.it", rule.value
132
- assert_equal "verona.it", rule.rule
133
- end
134
-
135
-
136
- def test_length
137
- assert_equal 1, @klass.build("com").length
138
- assert_equal 2, @klass.build("co.com").length
139
- assert_equal 3, @klass.build("mx.co.com").length
140
- end
141
-
142
- def test_parts
143
- assert_equal %w(com), @klass.build("com").parts
144
- assert_equal %w(co com), @klass.build("co.com").parts
145
- assert_equal %w(mx co com), @klass.build("mx.co.com").parts
146
- end
147
-
148
- def test_decompose
149
- assert_equal [nil, nil], @klass.build("com").decompose("com")
150
- assert_equal %w( example com ), @klass.build("com").decompose("example.com")
151
- assert_equal %w( foo.example com ), @klass.build("com").decompose("foo.example.com")
152
- end
153
-
154
- end
155
-
156
-
157
- class PublicSuffix::RuleExceptionTest < Minitest::Test
158
-
159
- def setup
160
- @klass = PublicSuffix::Rule::Exception
161
- end
162
-
163
-
164
- def test_initialize
165
- rule = @klass.build("!british-library.uk")
166
- assert_instance_of @klass, rule
167
- assert_equal "british-library.uk", rule.value
168
- assert_equal "!british-library.uk", rule.rule
169
- end
170
-
171
-
172
- def test_length
173
- assert_equal 2, @klass.build("!british-library.uk").length
174
- assert_equal 3, @klass.build("!foo.british-library.uk").length
175
- end
176
-
177
- def test_parts
178
- assert_equal %w( uk ), @klass.build("!british-library.uk").parts
179
- assert_equal %w( tokyo jp ), @klass.build("!metro.tokyo.jp").parts
180
- end
181
-
182
- def test_decompose
183
- assert_equal [nil, nil], @klass.build("!british-library.uk").decompose("uk")
184
- assert_equal %w( british-library uk ), @klass.build("!british-library.uk").decompose("british-library.uk")
185
- assert_equal %w( foo.british-library uk ), @klass.build("!british-library.uk").decompose("foo.british-library.uk")
186
- end
187
-
188
- end
189
-
190
-
191
- class PublicSuffix::RuleWildcardTest < Minitest::Test
192
-
193
- def setup
194
- @klass = PublicSuffix::Rule::Wildcard
195
- end
196
-
197
-
198
- def test_initialize
199
- rule = @klass.build("*.aichi.jp")
200
- assert_instance_of @klass, rule
201
- assert_equal "aichi.jp", rule.value
202
- assert_equal "*.aichi.jp", rule.rule
203
- end
204
-
205
-
206
- def test_length
207
- assert_equal 2, @klass.build("*.uk").length
208
- assert_equal 3, @klass.build("*.co.uk").length
209
- end
210
-
211
- def test_parts
212
- assert_equal %w( uk ), @klass.build("*.uk").parts
213
- assert_equal %w( co uk ), @klass.build("*.co.uk").parts
214
- end
215
-
216
- def test_decompose
217
- assert_equal [nil, nil], @klass.build("*.do").decompose("nic.do")
218
- assert_equal %w( google co.uk ), @klass.build("*.uk").decompose("google.co.uk")
219
- assert_equal %w( foo.google co.uk ), @klass.build("*.uk").decompose("foo.google.co.uk")
220
- end
221
-
222
- end