coppertone 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98149a0b1ea7cda00c82becc04efa776fe05d04c
4
- data.tar.gz: 4b5c342217d8ea99622fc3b7e0d75a2d49d008b5
3
+ metadata.gz: eab9d4a15947e26efa6ff34c18a0af365d26da20
4
+ data.tar.gz: 36a361ab1ce2daffd730e3ca7fa7057fea5ca1bf
5
5
  SHA512:
6
- metadata.gz: 3e739ea5580ee84d251ffae5f170d1116e40a5c789b94320878727de04c4a3dc8e6ea00641e14a0454c8aba087b9579c133362b1075ca20d1a25cdbc3188e2ff
7
- data.tar.gz: 89ce502d95dd1e60dafe3398d39788548f70758f3b435e3949f9fe7d62bc9356d12765b4898dd96d24eb6db76a6824dabbb74f0c5e05705c7ba015702092d9a3
6
+ metadata.gz: 089c7ed04c2396bb0f7aa2982b22eb471f68e5f1afa353a30489df75817714227b36aae6bf1afd6f9435f2d1e5af8d86ec8bdeb584f130e9134f423cf4ef48f5
7
+ data.tar.gz: ef9e3c6459a1b1900826fcdc37cd58f6e621ed56da3aa237dce3c97ae4cc18cf50e208474bbed400ef69340fcecacd9a5c3fdb1b835bfa99d78bc0e2d06ec2b9
@@ -4,6 +4,7 @@ env:
4
4
  rvm:
5
5
  - 2.0.0
6
6
  - 2.1.2
7
+ - 2.2.1
7
8
  - jruby-19mode
8
9
  - rbx-2.2.10
9
10
  allow_failures:
@@ -7,7 +7,7 @@ module Coppertone
7
7
  class DomainUtils
8
8
  def self.valid?(domain)
9
9
  return false if domain.blank?
10
- labels = to_labels(domain)
10
+ labels = to_ascii_labels(domain)
11
11
  return false if labels.length <= 1
12
12
  return false if domain.length > 253
13
13
  return false if labels.any? { |l| !valid_label?(l) }
@@ -15,7 +15,22 @@ module Coppertone
15
15
  end
16
16
 
17
17
  def self.to_labels(domain)
18
- Addressable::IDNA.to_ascii(domain).split('.')
18
+ domain.split('.')
19
+ end
20
+
21
+ def self.parent_domain(domain)
22
+ labels = to_labels(domain)
23
+ return '.' if labels.size == 1
24
+ labels.shift
25
+ return labels.join('.')
26
+ end
27
+
28
+ def self.to_ascii_labels(domain)
29
+ Addressable::IDNA.to_ascii(domain).split('.').map { |d| d.downcase }
30
+ end
31
+
32
+ def self.normalized_domain(domain)
33
+ to_ascii_labels(domain).join('.')
19
34
  end
20
35
 
21
36
  NO_DASH_REGEXP = /\A[a-zA-Z0-9]*[a-zA-Z]+[a-zA-Z0-9]*\z/
@@ -28,7 +43,7 @@ module Coppertone
28
43
 
29
44
  def self.valid_ldh_domain?(domain)
30
45
  return false unless valid?(domain)
31
- to_labels(domain).all? { |l| valid_hostname_label?(l) }
46
+ to_ascii_labels(domain).all? { |l| valid_hostname_label?(l) }
32
47
  end
33
48
 
34
49
  def self.valid_label?(l)
@@ -37,7 +52,7 @@ module Coppertone
37
52
 
38
53
  def self.macro_expanded_domain(domain)
39
54
  return nil if domain.blank?
40
- labels = to_labels(domain)
55
+ labels = to_ascii_labels(domain)
41
56
  domain = labels.join('.')
42
57
  while domain.length > 253
43
58
  labels = labels.drop(1)
@@ -47,8 +62,8 @@ module Coppertone
47
62
  end
48
63
 
49
64
  def self.subdomain_of?(subdomain_candidate, domain)
50
- subdomain_labels = to_labels(subdomain_candidate)
51
- domain_labels = to_labels(domain)
65
+ subdomain_labels = to_ascii_labels(subdomain_candidate)
66
+ domain_labels = to_ascii_labels(domain)
52
67
  num_labels_in_domain = domain_labels.length
53
68
  return false if subdomain_labels.length <= domain_labels.length
54
69
  subdomain_labels.last(num_labels_in_domain) == domain_labels
@@ -56,7 +71,7 @@ module Coppertone
56
71
 
57
72
  def self.subdomain_or_same?(candidate, domain)
58
73
  return false unless valid?(domain) && valid?(candidate)
59
- return true if domain == candidate
74
+ return true if normalized_domain(domain) == normalized_domain(candidate)
60
75
  subdomain_of?(candidate, domain)
61
76
  end
62
77
  end
@@ -1,3 +1,3 @@
1
1
  module Coppertone # rubocop:disable Style/Documentation
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.0.5'.freeze
3
3
  end
@@ -42,6 +42,11 @@ describe Coppertone::Utils::DomainUtils do
42
42
  .to eq('fermion.mit.edu')
43
43
  end
44
44
 
45
+ it 'returns the downcased domain for an ASCII domain' do
46
+ expect(subject.macro_expanded_domain('FERMION.mIt.edu'))
47
+ .to eq('fermion.mit.edu')
48
+ end
49
+
45
50
  it 'returns the ASCII domain for an IDNA domain' do
46
51
  expect(subject.macro_expanded_domain('清华大学.cn'))
47
52
  .to eq('xn--xkry9kk1bz66a.cn')
@@ -57,4 +62,25 @@ describe Coppertone::Utils::DomainUtils do
57
62
  .to eq(truncated_domain)
58
63
  end
59
64
  end
65
+
66
+ context '#parent_domain' do
67
+ it 'should handle hostnames correctly' do
68
+ expect(subject.parent_domain('abc.xyz.example.com')).to eq('xyz.example.com')
69
+ end
70
+
71
+ it 'should handle TLDs correctly' do
72
+ expect(subject.parent_domain('com')).to eq('.')
73
+ end
74
+ end
75
+
76
+ context '#normalized_domain' do
77
+ it 'should handle ASCII hostnames correctly' do
78
+ expect(subject.normalized_domain('abc.xyz.example.com')).to eq('abc.xyz.example.com')
79
+ expect(subject.normalized_domain('ABc.xYz.exAMPle.COM')).to eq('abc.xyz.example.com')
80
+ end
81
+
82
+ it 'should handle Unicode domains correctly' do
83
+ expect(subject.normalized_domain('FERMIon.清华大学.cn')).to eq('fermion.xn--xkry9kk1bz66a.cn')
84
+ end
85
+ end
60
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coppertone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter M. Goldstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dns_adapter
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  version: '0'
267
267
  requirements: []
268
268
  rubyforge_project:
269
- rubygems_version: 2.4.4
269
+ rubygems_version: 2.4.6
270
270
  signing_key:
271
271
  specification_version: 4
272
272
  summary: A Sender Policy Framework (SPF) toolkit