distinguished_name 0.0.2
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +7 -0
- data/distinguished_name.gemspec +21 -0
- data/lib/distinguished_name/canonicalize.rb +142 -0
- data/lib/distinguished_name/version.rb +3 -0
- data/lib/distinguished_name.rb +4 -0
- data/test/canonicalize_test.rb +214 -0
- data/test/test_helper.rb +2 -0
- metadata +59 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Midpoint Data Layer
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
|
|
6
|
+
require 'distinguished_name/version'
|
|
7
|
+
|
|
8
|
+
Gem::Specification.new do |gem|
|
|
9
|
+
gem.name = "distinguished_name"
|
|
10
|
+
gem.version = DistinguishedName::VERSION
|
|
11
|
+
gem.authors = ["Team Bavaro"]
|
|
12
|
+
gem.email = [""]
|
|
13
|
+
gem.summary = %q{Methods for interacting with distinguished name strings}
|
|
14
|
+
gem.description = %q{This is a gem for interacting with the string representation of distinguished names, per the RFC-1779 (http://www.ietf.org/rfc/rfc1779.txt)}
|
|
15
|
+
gem.homepage = ""
|
|
16
|
+
|
|
17
|
+
gem.files = `git ls-files`.split($/)
|
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
gem.require_paths = ["lib"]
|
|
21
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'distinguished_name')
|
|
2
|
+
|
|
3
|
+
class DistinguishedName::Canonicalize
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
def reverse(dn, order=['CN','OU','O','C'])
|
|
8
|
+
@dn = dn
|
|
9
|
+
@order = []
|
|
10
|
+
order.each {|o| @order << o + '='}
|
|
11
|
+
@separators = [',', '/']
|
|
12
|
+
return @dn if dn_contains_no_equals || dn_invalid?
|
|
13
|
+
@separators.each do |s|
|
|
14
|
+
@current_separator = s
|
|
15
|
+
@dn_elements = @dn.split(s)
|
|
16
|
+
clean_array
|
|
17
|
+
possibly_join_elements
|
|
18
|
+
break if number_of_elements_matches_given_number_of_equal_signs?
|
|
19
|
+
end
|
|
20
|
+
@order.reverse! if @current_separator == '/'
|
|
21
|
+
reorder_dn
|
|
22
|
+
rejoin_dn
|
|
23
|
+
return @dn
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def comma_separated_format(dn, order=['CN','OU','O','C'])
|
|
27
|
+
return dn if dn.nil? || dn == ""
|
|
28
|
+
return dn if in_comma_separated_format?(dn)
|
|
29
|
+
reverse(dn, order)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def slash_separated_format(dn, order=['CN','OU','O','C'])
|
|
33
|
+
return dn if dn.nil? || dn == ""
|
|
34
|
+
return reverse(reverse(dn, order), order) if in_slash_separated_format?(dn)
|
|
35
|
+
reverse(dn, order)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def rasify(dn)
|
|
39
|
+
comma_separated_format(dn)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def apachify(dn)
|
|
43
|
+
slash_separated_format(dn)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def in_comma_separated_format?(dn)
|
|
47
|
+
return false if dn_does_not_contain_separator(',', dn)
|
|
48
|
+
(((dn.scan('=')).size - (dn.scan('\=')).size) == ((dn.scan(',')).size - (dn.scan('\,')).size) + 1)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def in_slash_separated_format?(dn)
|
|
52
|
+
return false if dn_does_not_contain_separator('/', dn)
|
|
53
|
+
(((dn.scan('=')).size - (dn.scan('\=')).size) == ((dn.scan('/')).size - (dn.scan('\/')).size))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def rejoin_dn
|
|
59
|
+
if @current_separator == ','
|
|
60
|
+
@dn = '/' + @dn_elements.join('/')
|
|
61
|
+
else
|
|
62
|
+
@dn = @dn_elements.join(',')
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def reorder_dn
|
|
67
|
+
tmp_dn_elements = []
|
|
68
|
+
@order.each do |o|
|
|
69
|
+
@dn_elements.each {|e| (tmp_dn_elements << e) if e.downcase.match("^#{o.downcase}")}
|
|
70
|
+
end
|
|
71
|
+
@dn_elements = tmp_dn_elements.reverse!
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def possibly_join_elements
|
|
75
|
+
@dn_elements.each_with_index do |element, index|
|
|
76
|
+
if number_of_unescaped_equal_signs(element) == 0
|
|
77
|
+
join_with_prev(index)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def join_with_prev(index)
|
|
83
|
+
curr = @dn_elements[index]
|
|
84
|
+
prev = @dn_elements[index - 1]
|
|
85
|
+
new_element = [prev, curr].join(@current_separator)
|
|
86
|
+
@dn_elements[index - 1] = new_element
|
|
87
|
+
@dn_elements.delete_at(index)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def clean_array
|
|
91
|
+
@dn_elements.delete_if{ |d| d.nil? || d =="" }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def dn_does_not_contain_separator(separator, dn)
|
|
95
|
+
!((dn.scan(separator).size - dn.scan("\\#{separator}").size) > 0)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def number_of_elements_matches_given_number_of_equal_signs?
|
|
99
|
+
count = 0
|
|
100
|
+
@dn_elements.each do |element|
|
|
101
|
+
count += number_of_unescaped_equal_signs(element)
|
|
102
|
+
element.strip!
|
|
103
|
+
end
|
|
104
|
+
count == @dn_elements.size
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def dn_contains_no_equals
|
|
108
|
+
@dn.count('=') == 0
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def dn_invalid?
|
|
112
|
+
count = 0
|
|
113
|
+
dn_downcase = @dn.downcase
|
|
114
|
+
@order.each do |o|
|
|
115
|
+
curr = dn_downcase.scan(o.downcase)
|
|
116
|
+
if !(curr.nil? || curr == "")
|
|
117
|
+
case curr[0]
|
|
118
|
+
when "c="
|
|
119
|
+
count += 1
|
|
120
|
+
when "cn="
|
|
121
|
+
count += 1
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
count != 2
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def number_of_unescaped_equal_signs(element)
|
|
129
|
+
n = 1
|
|
130
|
+
num_esc_equals = 0
|
|
131
|
+
num_equals = element.count('=')
|
|
132
|
+
while (element.index('\=', n))
|
|
133
|
+
num_esc_equals += 1
|
|
134
|
+
n = element.index('\=', n)
|
|
135
|
+
n += 2
|
|
136
|
+
end
|
|
137
|
+
return (num_equals - num_esc_equals)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
|
+
|
|
3
|
+
class CanonicalizeTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def test_reversing_a_dn_string_with_slashes_happy_path
|
|
6
|
+
dn = '/C=US/O=company_name/OU=developers/CN=John Smith'
|
|
7
|
+
assert_equal 'CN=John Smith,OU=developers,O=company_name,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_putting_a_dn_string_with_slashes_in_comma_separated_format_happy_path
|
|
11
|
+
dn = '/C=US/O=company_name/OU=developers/CN=John Smith'
|
|
12
|
+
assert_equal 'CN=John Smith,OU=developers,O=company_name,C=US', DistinguishedName::Canonicalize.comma_separated_format(dn)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_reversing_a_dn_string_with_commas_happy_path
|
|
16
|
+
dn = 'CN=John Smith,OU=developers,O=company_name,C=US'
|
|
17
|
+
assert_equal '/C=US/O=company_name/OU=developers/CN=John Smith', DistinguishedName::Canonicalize.reverse(dn)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_putting_a_dn_string_with_commas_in_slash_separated_format_happy_path
|
|
21
|
+
dn = 'CN=John Smith,OU=developers,O=company_name,C=US'
|
|
22
|
+
assert_equal '/C=US/O=company_name/OU=developers/CN=John Smith', DistinguishedName::Canonicalize.slash_separated_format(dn)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_reversing_a_dn_string_with_non_default_keys_returns_that_string_unaltered
|
|
26
|
+
dn_with_nonstandard_keys = 'X=person,Y=place,Z=thing'
|
|
27
|
+
assert_equal dn_with_nonstandard_keys, DistinguishedName::Canonicalize.reverse(dn_with_nonstandard_keys)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_reversing_a_dn_string_with_no_equal_signs_just_returns_that_string_unaltered
|
|
31
|
+
dn = '/hi/there/how/are/you?'
|
|
32
|
+
assert_equal dn, DistinguishedName::Canonicalize.reverse(dn)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_reversing_a_dn_string_with_escaped_equal_signs_returns_that_string_unaltered
|
|
36
|
+
dn = 'CN\=foo,OU\=bar,O\=baz,C\=US'
|
|
37
|
+
assert_equal dn, DistinguishedName::Canonicalize.reverse(dn)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_reversing_a_dn_string_with_unescaped_comma_returns_that_string_unaltered
|
|
41
|
+
dn = "CN=boo,OU=foo,choo,voo,O=bar,C=beeeergood"
|
|
42
|
+
assert_equal dn, DistinguishedName::Canonicalize.reverse(dn)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_reversing_a_dn_string_with_only_commas_just_returns_that_string_unaltered
|
|
46
|
+
dn = 'hi,there,how,are,you?'
|
|
47
|
+
assert_equal dn, DistinguishedName::Canonicalize.reverse(dn)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_reversing_a_dn_string_with_empty_slashes_ignores_those_empty_elements
|
|
51
|
+
assert_equal 'CN=b,C=a', DistinguishedName::Canonicalize.reverse('/C=a////CN=b')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_reversing_a_dn_string_with_empty_commas_ignores_those_empty_elements
|
|
55
|
+
assert_equal '/C=b/CN=a', DistinguishedName::Canonicalize.reverse('CN=a,,,,C=b')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_reversing_a_dn_string_with_two_CNs_and_no_Cs_returns_that_string_unaltered_per_the_default_format
|
|
59
|
+
dn = 'CN=John Smith,OU=developers,O=company_name,CN=US'
|
|
60
|
+
assert_equal dn, DistinguishedName::Canonicalize.reverse(dn)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_dn_reversing_strips_spaces
|
|
64
|
+
dn = 'CN=blah, OU=foo, C=bar'
|
|
65
|
+
assert_equal '/C=bar/OU=foo/CN=blah', DistinguishedName::Canonicalize.reverse(dn)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_slashed_dn_with_escaped_comma_can_be_reversed
|
|
69
|
+
dn = '/CN=John Smith\, jr./C=US/OU=developers/O=company_name'
|
|
70
|
+
assert_equal 'CN=John Smith\, jr.,OU=developers,O=company_name,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_slashed_dn_with_escaped_slash_can_be_reversed
|
|
74
|
+
dn = '/C=US/O=company_name/OU=developers\/testers/CN=John Smith'
|
|
75
|
+
assert_equal 'CN=John Smith,OU=developers\/testers,O=company_name,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_slashed_dn_with_escaped_end_comma_can_be_reversed
|
|
79
|
+
dn = '/C=US/O=company_name\, inc./OU=developers/CN=John Smith'
|
|
80
|
+
assert_equal 'CN=John Smith,OU=developers,O=company_name\, inc.,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_comma_dn_with_escaped_comma_can_be_reversed
|
|
84
|
+
dn = 'CN=John Smith\, jr.,OU=developers,O=company_name,C=US'
|
|
85
|
+
assert_equal '/C=US/O=company_name/OU=developers/CN=John Smith\, jr.', DistinguishedName::Canonicalize.reverse(dn)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_comma_dn_with_escaped_slash_can_be_reversed
|
|
89
|
+
dn = 'CN=John Smith,OU=developers\/testers,O=company_name,C=US'
|
|
90
|
+
assert_equal '/C=US/O=company_name/OU=developers\/testers/CN=John Smith', DistinguishedName::Canonicalize.reverse(dn)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_multiple_ou_dn_canonicalized_for_comma_dn
|
|
94
|
+
dn = '/C=US/O=company_name/OU=asdf/OU=blerg/OU=developers/CN=John Smith'
|
|
95
|
+
assert_equal 'CN=John Smith,OU=developers,OU=blerg,OU=asdf,O=company_name,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_removal_of_extra_fields_not_in_order_with_slashy
|
|
99
|
+
dn = '/C=US/O=company_name/OU=asdf/OU=blerg/OU=developers/CN=John Smith/FOO=bar'
|
|
100
|
+
assert_equal 'CN=John Smith,OU=developers,OU=blerg,OU=asdf,O=company_name,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_removal_of_extra_fields_not_in_order_with_commas
|
|
104
|
+
dn = 'FOO=bar,CN=John Smith,CNOODLE=yum,FII=fofum,OU=asdf,OU=blerg,OU=developers,O=company_name,C=US'
|
|
105
|
+
assert_equal '/C=US/O=company_name/OU=developers/OU=blerg/OU=asdf/CN=John Smith', DistinguishedName::Canonicalize.reverse(dn)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_multiple_ou_dn_canonicalized_with_comma
|
|
109
|
+
dn = 'CN=John Smith,OU=asdf,OU=blerg,OU=developers,O=company_name,C=US'
|
|
110
|
+
assert_equal '/C=US/O=company_name/OU=developers/OU=blerg/OU=asdf/CN=John Smith', DistinguishedName::Canonicalize.reverse(dn)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_escaped_equals_in_dn_can_be_reversed
|
|
114
|
+
dn = '/C=US/O=company_name/OU=asdf/CN=login\=John Smith'
|
|
115
|
+
assert_equal 'CN=login\=John Smith,OU=asdf,O=company_name,C=US', DistinguishedName::Canonicalize.reverse(dn)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_escaped_equals_in_dn_is_reverse_canonicalized
|
|
119
|
+
dn = 'CN=login\=John Smith,C=US,OU=asdf,O=company_name'
|
|
120
|
+
assert_equal '/C=US/O=company_name/OU=asdf/CN=login\=John Smith', DistinguishedName::Canonicalize.reverse(dn)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_reversing_a_slash_separated_dn_orders_dn_appropriately_with_non_default_order
|
|
124
|
+
dn = '/C=US/O=Test/OU=abc/CN=xyz'
|
|
125
|
+
assert_equal 'O=Test,OU=abc,C=US,CN=xyz', DistinguishedName::Canonicalize.reverse(dn, ['O', 'OU', 'C', 'CN'])
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_reversing_a_comma_separated_dn_orders_dn_appropriately_with_non_default_order
|
|
129
|
+
dn = 'O=Test,OU=abc,C=US,CN=xyz'
|
|
130
|
+
assert_equal '/CN=xyz/C=US/OU=abc/O=Test', DistinguishedName::Canonicalize.reverse(dn, ['O', 'OU', 'C', 'CN'])
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_comma_separated_format_with_a_comma_separated_style_dn
|
|
134
|
+
dn = 'CN=david,OU=abc,O=Beckham,C=US'
|
|
135
|
+
assert_equal 'CN=david,OU=abc,O=Beckham,C=US', DistinguishedName::Canonicalize.comma_separated_format(dn)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_slash_separated_format_with_a_comma_separated_style_dn
|
|
139
|
+
dn = 'CN=david,OU=abc,O=Beckham,C=US'
|
|
140
|
+
assert_equal '/C=US/O=Beckham/OU=abc/CN=david', DistinguishedName::Canonicalize.slash_separated_format(dn)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def test_comma_separated_format_with_a_slash_separated_style_dn
|
|
144
|
+
dn = '/C=US/O=Beckham/OU=abc/CN=david'
|
|
145
|
+
assert_equal 'CN=david,OU=abc,O=Beckham,C=US', DistinguishedName::Canonicalize.comma_separated_format(dn)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_slash_separated_format_with_a_slash_separated_style_dn
|
|
149
|
+
dn = '/C=US/O=Beckham/OU=abc/CN=david'
|
|
150
|
+
assert_equal '/C=US/O=Beckham/OU=abc/CN=david', DistinguishedName::Canonicalize.slash_separated_format(dn)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def test_comma_separated_format_with_a_comma_separated_style_dn_lowercase
|
|
154
|
+
dn = 'cn=david,ou=abc,o=Beckham,c=US'
|
|
155
|
+
assert_equal 'cn=david,ou=abc,o=Beckham,c=US', DistinguishedName::Canonicalize.comma_separated_format(dn)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_slash_separated_format_with_a_comma_separated_style_dn_lowercase
|
|
159
|
+
dn = 'cn=david,ou=abc,o=Beckham,c=US'
|
|
160
|
+
assert_equal '/c=US/o=Beckham/ou=abc/cn=david', DistinguishedName::Canonicalize.slash_separated_format(dn)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_comma_separated_format_with_a_slash_separated_style_dn_lowercase
|
|
164
|
+
dn = '/c=US/o=Beckham/ou=abc/cn=david'
|
|
165
|
+
assert_equal 'cn=david,ou=abc,o=Beckham,c=US', DistinguishedName::Canonicalize.comma_separated_format(dn)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def test_slash_separated_format_with_a_slash_separated_style_dn_lowercase
|
|
169
|
+
dn = '/c=US/o=Beckham/ou=abc/cn=david'
|
|
170
|
+
assert_equal '/c=US/o=Beckham/ou=abc/cn=david', DistinguishedName::Canonicalize.slash_separated_format(dn)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def test_in_comma_separated_format_returns_true_if_its_given_a_comma_separated_dn
|
|
174
|
+
dn = 'CN=david,OU=abc,O=Beckham,C=US'
|
|
175
|
+
assert DistinguishedName::Canonicalize.in_comma_separated_format?(dn)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def test_in_comma_separated_format_returns_false_if_its_given_a_slash_separated_style_dn
|
|
179
|
+
dn = '/C=US/O=Beckham/OU=abc/CN=david'
|
|
180
|
+
assert !DistinguishedName::Canonicalize.in_comma_separated_format?(dn)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_slash_separated_style_format_with_extra_field_ST_gets_stripped_after_reversing
|
|
184
|
+
dn = '/C=US/ST=NJ/O=My Company, L.L.C./OU=QA/CN=John Smith'
|
|
185
|
+
comma_dn = 'CN=John Smith,OU=QA,O=My Company, L.L.C.,C=US'
|
|
186
|
+
assert_equal comma_dn, DistinguishedName::Canonicalize.reverse(dn)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def test_in_comma_separated_format_must_contain_at_least_one_unescaped_comma_or_else_its_not_in_comma_separated_format
|
|
190
|
+
assert_equal false, DistinguishedName::Canonicalize.in_comma_separated_format?('/C=US/ST=NJ/O=My Company, L.L.C./OU=QA/CN=John Smith')
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def test_in_slash_separated_format_must_contain_at_least_one_unescaped_slash_or_else_its_not_in_slash_separated_format
|
|
194
|
+
assert_equal false, DistinguishedName::Canonicalize.in_slash_separated_format?('CN=John Smith,OU=QA,O=My Company, L.L.C.,C=US')
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_long_dn_sent_from_browser_is_properly_reversed
|
|
198
|
+
sent_from_browser = '/C=US/ST=NJ/O=My Company, L.L.C./OU=QA/CN=John Smith'
|
|
199
|
+
in_db = '/C=US/O=My Company, L.L.C./OU=QA/CN=John Smith'
|
|
200
|
+
assert_equal in_db, DistinguishedName::Canonicalize.slash_separated_format(sent_from_browser)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def test_dn_with_less_than_sign_gets_reversed_properly
|
|
204
|
+
dn = 'CN=lt\<lt,OU=Q\<A,O=My Company, L.L.C.,C=US'
|
|
205
|
+
assert_equal '/C=US/O=My Company, L.L.C./OU=Q\<A/CN=lt\<lt', DistinguishedName::Canonicalize.reverse(dn)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_a_strange_dn_string_does_not_cause_problems
|
|
209
|
+
dn = "CN=escapes \~\`\!\@\$\%\^\*\(\)\-\_\{\}\[\]\|\.\?, OU=A\~\`\!\@\$\%\^\*\(\)\-\_\{\}\[\]\|\.\?A, O=My Company, L.L.C., ST=NJ, C=US"
|
|
210
|
+
assert_equal "/C=US/O=My Company, L.L.C./OU=A~`!@$%^*()-_{}[]|.?A/CN=escapes ~`!@$%^*()-_{}[]|.?", DistinguishedName::Canonicalize.reverse(dn)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: distinguished_name
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Team Bavaro
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: This is a gem for interacting with the string representation of distinguished names, per the RFC-1779 (http://www.ietf.org/rfc/rfc1779.txt)
|
|
15
|
+
email:
|
|
16
|
+
- ''
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- .gitignore
|
|
22
|
+
- Gemfile
|
|
23
|
+
- LICENSE.txt
|
|
24
|
+
- README.md
|
|
25
|
+
- Rakefile
|
|
26
|
+
- distinguished_name.gemspec
|
|
27
|
+
- lib/distinguished_name.rb
|
|
28
|
+
- lib/distinguished_name/canonicalize.rb
|
|
29
|
+
- lib/distinguished_name/version.rb
|
|
30
|
+
- test/canonicalize_test.rb
|
|
31
|
+
- test/test_helper.rb
|
|
32
|
+
homepage: ''
|
|
33
|
+
licenses: []
|
|
34
|
+
post_install_message:
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ! '>='
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
none: false
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ! '>='
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
none: false
|
|
50
|
+
requirements: []
|
|
51
|
+
rubyforge_project:
|
|
52
|
+
rubygems_version: 1.8.24
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 3
|
|
55
|
+
summary: Methods for interacting with distinguished name strings
|
|
56
|
+
test_files:
|
|
57
|
+
- test/canonicalize_test.rb
|
|
58
|
+
- test/test_helper.rb
|
|
59
|
+
...
|