1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.common.attachment;
20
21 import org.junit.jupiter.api.Test;
22 import org.apache.wss4j.common.util.AttachmentUtils;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26
27 public class AttachmentTest {
28
29 @Test
30 public void testMatch() {
31 assertTrue("text/xml".matches("(?i)(text/xml).*"));
32 assertTrue("TEXT/XML".matches("(?i)(text/xml).*"));
33 assertTrue("application/xml".matches("(?i)(application/xml).*"));
34 assertTrue("APPLICATION/XML".matches("(?i)(application/xml).*"));
35 assertTrue("text/plain".matches("(?i)(text/).*"));
36 assertTrue("TEXT/PLAIN".matches("(?i)(text/).*"));
37 }
38
39 @Test
40 public void testMimeHeaderUncomment_1() throws Exception {
41 assertEquals(
42 "\"a\" \"(b)\" c test",
43 AttachmentUtils.uncomment("\"a\" \"(b)\" c ((\"d\")) test"));
44 }
45
46 @Test
47 public void testMimeHeaderUncomment_2() throws Exception {
48 assertEquals(
49 "",
50 AttachmentUtils.uncomment("(\"a\" \"(b)\" c ((\"d\")) test)"));
51 }
52
53 @Test
54 public void testMimeHeaderUncomment_3() throws Exception {
55 assertEquals(
56 "\"a\" \"(\"b\")\" test",
57 AttachmentUtils.uncomment("\"a\" \"(\"b\")\" (c(\"d\"))test"));
58 }
59
60 @Test
61 public void testMimeHeaderUnfold_1() throws Exception {
62 assertEquals(
63 "\r\n",
64 AttachmentUtils.unfold("\r\n"));
65 }
66
67 @Test
68 public void testMimeHeaderUnfold_2() throws Exception {
69 assertEquals(
70 "\r\na",
71 AttachmentUtils.unfold("\r\na"));
72 }
73
74 @Test
75 public void testMimeHeaderUnfold_3() throws Exception {
76 assertEquals(
77 "",
78 AttachmentUtils.unfold("\r\n "));
79 }
80
81 @Test
82 public void testMimeHeaderUnfold_4() throws Exception {
83 assertEquals(
84 "",
85 AttachmentUtils.unfold("\r\n\t"));
86 }
87
88 @Test
89 public void testMimeHeaderUnfold_5() throws Exception {
90 assertEquals(
91 "aa",
92 AttachmentUtils.unfold("a\r\n\ta"));
93 }
94
95 @Test
96 public void testMimeHeaderUnfold_6() throws Exception {
97 assertEquals(
98 "aaa",
99 AttachmentUtils.unfold("a\r\n\taa"));
100 }
101
102 @Test
103 public void testMimeHeaderUnfold_7() throws Exception {
104 assertEquals(
105 "aaaa",
106 AttachmentUtils.unfold("\r\n\taaaa"));
107 }
108
109 @Test
110 public void testMimeHeaderUnfold_8() throws Exception {
111 assertEquals(
112 "a",
113 AttachmentUtils.unfold("\r\n\ta\r\n "));
114 }
115
116 @Test
117 public void testMimeHeaderUnfold_9() throws Exception {
118 assertEquals(
119 "\r\n\ra",
120 AttachmentUtils.unfold("\r\n\ra\r\n "));
121 }
122
123 @Test
124 public void testMimeHeaderUnfold_10() throws Exception {
125 assertEquals(
126 "\r\n",
127 AttachmentUtils.unfold("\r\n \r\n \r\n"));
128 }
129
130 @Test
131 public void testMimeHeaderUnfoldWS_1() throws Exception {
132 assertEquals(
133 "a ",
134 AttachmentUtils.unfoldWhitespace(" a "));
135 }
136
137 @Test
138 public void testMimeHeaderUnfoldWS_2() throws Exception {
139 assertEquals(
140 "",
141 AttachmentUtils.unfoldWhitespace(""));
142 }
143
144 @Test
145 public void testMimeHeaderUnfoldWS_3() throws Exception {
146 assertEquals(
147 "",
148 AttachmentUtils.unfoldWhitespace(" \t \t\t "));
149 }
150
151 @Test
152 public void testMimeHeaderUnfoldWS_4() throws Exception {
153 assertEquals(
154 "a\ta\t a",
155 AttachmentUtils.unfoldWhitespace(" \t a\ta\t a"));
156 }
157
158 @Test
159 public void testMimeHeaderDecodeRfc2184_1() throws Exception {
160 assertEquals(
161 "message/external-body;access-type=\"URL\";" +
162 "test=\"true\";" +
163 "url=\"ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\""
164 ,
165 AttachmentUtils.decodeRfc2184(
166 "Message/External-Body; access-type=URL;" +
167 "URL*0=\"ftp://\";" +
168 "URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\";" +
169 "test=true"));
170 }
171
172 @Test
173 public void testMimeHeaderDecodeRfc2184_2() throws Exception {
174 assertEquals(
175 "message/external-body;access-type=\"URL\";" +
176 "url=\"ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"",
177 AttachmentUtils.decodeRfc2184(
178 "Message/External-Body; access-type=URL;" +
179 "URL*0=\"ftp://\";" +
180 "URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\""
181 )
182 );
183 }
184
185 @Test
186 public void testMimeHeaderDecodeRfc2184_3() throws Exception {
187 assertEquals(
188 "application/x-stuff;" +
189 "title=\"This is ***fun***\"",
190 AttachmentUtils.decodeRfc2184(
191 "application/x-stuff;" +
192 "title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A"
193 )
194 );
195 }
196
197 @Test
198 public void testMimeHeaderDecodeRfc2184_4() throws Exception {
199 assertEquals(
200 "application/x-stuff;" +
201 "title=\"This is even more ***fun*** isn't it!\"",
202 AttachmentUtils.decodeRfc2184(
203 "application/x-stuff;" +
204 "title*1*=us-ascii'en'This%20is%20even%20more%20;" +
205 "title*2*=%2A%2A%2Afun%2A%2A%2A%20;" +
206 "title*3=\"isn't it!\""
207 )
208 );
209 }
210
211 @Test
212 public void testMimeHeaderUnquoteInnerText_1() throws Exception {
213 assertEquals(
214 "\"\\\"\\\"\\\\A\"",
215 AttachmentUtils.unquoteInnerText(
216 "\\\"\"\"\\\\\\A\\\""
217 )
218 );
219 }
220
221 @Test
222 public void testMimeHeaderUnquoteInnerText_2() throws Exception {
223 assertEquals(
224 "\"a\"",
225 AttachmentUtils.unquoteInnerText(
226 "\\\"a\\\""
227 )
228 );
229 }
230 }