1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.client5.http.ssl;
29
30 import static org.hamcrest.MatcherAssert.assertThat;
31
32 import java.util.Arrays;
33
34 import org.apache.hc.core5.http.NameValuePair;
35 import org.apache.hc.core5.http.message.BasicNameValuePair;
36 import org.hamcrest.CoreMatchers;
37 import org.junit.jupiter.api.BeforeEach;
38 import org.junit.jupiter.api.Test;
39
40
41
42
43 class TestDistinguishedNameParser {
44
45 private DistinguishedNameParser impl;
46
47 @BeforeEach
48 void setup() {
49 impl = DistinguishedNameParser.INSTANCE;
50 }
51
52 @Test
53 void testParseBasic() {
54 assertThat(impl.parse("cn=blah, ou=yada, o=booh"),
55 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
56 new BasicNameValuePair("cn", "blah"),
57 new BasicNameValuePair("ou", "yada"),
58 new BasicNameValuePair("o", "booh"))));
59 }
60
61 @Test
62 void testParseRepeatedElements() {
63 assertThat(impl.parse("cn=blah, cn=yada, cn=booh"),
64 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
65 new BasicNameValuePair("cn", "blah"),
66 new BasicNameValuePair("cn", "yada"),
67 new BasicNameValuePair("cn", "booh"))));
68 }
69
70 @Test
71 void testParseBlanks() {
72 assertThat(impl.parse("c = pampa , cn = blah , ou = blah , o = blah"),
73 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
74 new BasicNameValuePair("c", "pampa"),
75 new BasicNameValuePair("cn", "blah"),
76 new BasicNameValuePair("ou", "blah"),
77 new BasicNameValuePair("o", "blah"))));
78 }
79
80 @Test
81 void testParseQuotes() {
82 assertThat(impl.parse("cn=\"blah\", ou=yada, o=booh"),
83 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
84 new BasicNameValuePair("cn", "blah"),
85 new BasicNameValuePair("ou", "yada"),
86 new BasicNameValuePair("o", "booh"))));
87 }
88
89 @Test
90 void testParseQuotes2() {
91 assertThat(impl.parse("cn=\"blah blah\", ou=yada, o=booh"),
92 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
93 new BasicNameValuePair("cn", "blah blah"),
94 new BasicNameValuePair("ou", "yada"),
95 new BasicNameValuePair("o", "booh"))));
96 }
97
98 @Test
99 void testParseQuotes3() {
100 assertThat(impl.parse("cn=\"blah, blah\", ou=yada, o=booh"),
101 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
102 new BasicNameValuePair("cn", "blah, blah"),
103 new BasicNameValuePair("ou", "yada"),
104 new BasicNameValuePair("o", "booh"))));
105 }
106
107 @Test
108 void testParseEscape() {
109 assertThat(impl.parse("cn=blah\\, blah, ou=yada, o=booh"),
110 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
111 new BasicNameValuePair("cn", "blah, blah"),
112 new BasicNameValuePair("ou", "yada"),
113 new BasicNameValuePair("o", "booh"))));
114 }
115
116 @Test
117 void testParseUnescapedEqual() {
118 assertThat(impl.parse("c = cn=uuh, cn=blah, ou=yada, o=booh"),
119 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
120 new BasicNameValuePair("c", "cn=uuh"),
121 new BasicNameValuePair("cn", "blah"),
122 new BasicNameValuePair("ou", "yada"),
123 new BasicNameValuePair("o", "booh"))));
124 }
125
126 @Test
127 void testParseInvalid() {
128 assertThat(impl.parse("blah,blah"),
129 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
130 new BasicNameValuePair("blah", null),
131 new BasicNameValuePair("blah", null))));
132 }
133
134 @Test
135 void testParseInvalid2() {
136 assertThat(impl.parse("cn,o=blah"),
137 CoreMatchers.equalTo(Arrays.<NameValuePair>asList(
138 new BasicNameValuePair("cn", null),
139 new BasicNameValuePair("o", "blah"))));
140 }
141
142 }