source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/routines/UrlValidatorTest.java@ 11621

Last change on this file since 11621 was 11621, checked in by Don-vip, 7 years ago

checkstyle - fix CommentsIndentation errors

  • Property svn:eol-style set to native
File size: 27.2 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package org.openstreetmap.josm.data.validation.routines;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertTrue;
22
23import org.junit.Before;
24import org.junit.Test;
25
26/**
27 * Performs Validation Test for url validations.
28 *
29 * @version $Revision: 1741724 $
30 */
31public class UrlValidatorTest {
32
33 private static final boolean printStatus = false;
34 private static final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using.
35
36 /**
37 * Setup
38 */
39 @Before
40 public void setUp() {
41 for (int index = 0; index < testPartsIndex.length - 1; index++) {
42 testPartsIndex[index] = 0;
43 }
44 }
45
46 /**
47 * Test is valid
48 */
49 @Test
50 public void testIsValid() {
51 testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES);
52 setUp();
53 long options =
54 UrlValidator.ALLOW_2_SLASHES
55 + UrlValidator.ALLOW_ALL_SCHEMES
56 + UrlValidator.NO_FRAGMENTS;
57
58 testIsValid(testUrlPartsOptions, options);
59 }
60
61 /**
62 * Test is valid scheme
63 */
64 @Test
65 public void testIsValidScheme() {
66 if (printStatus) {
67 System.out.print("\n testIsValidScheme() ");
68 }
69 //UrlValidator urlVal = new UrlValidator(schemes,false,false,false);
70 UrlValidator urlVal = new UrlValidator(schemes, 0);
71 for (int sIndex = 0; sIndex < testScheme.length; sIndex++) {
72 ResultPair testPair = testScheme[sIndex];
73 boolean result = urlVal.isValidScheme(testPair.item);
74 assertEquals(testPair.item, testPair.valid, result);
75 if (printStatus) {
76 if (result == testPair.valid) {
77 System.out.print('.');
78 } else {
79 System.out.print('X');
80 }
81 }
82 }
83 if (printStatus) {
84 System.out.println();
85 }
86 }
87
88 /**
89 * Create set of tests by taking the testUrlXXX arrays and
90 * running through all possible permutations of their combinations.
91 *
92 * @param testObjects Used to create a url.
93 * @param options options
94 */
95 private void testIsValid(Object[] testObjects, long options) {
96 UrlValidator urlVal = new UrlValidator(null, null, options);
97 assertTrue(urlVal.isValid("http://www.google.com"));
98 assertTrue(urlVal.isValid("http://www.google.com/"));
99 int statusPerLine = 60;
100 int printed = 0;
101 if (printIndex) {
102 statusPerLine = 6;
103 }
104 do {
105 StringBuilder testBuffer = new StringBuilder();
106 boolean expected = true;
107 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
108 int index = testPartsIndex[testPartsIndexIndex];
109 ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex];
110 testBuffer.append(part[index].item);
111 expected &= part[index].valid;
112 }
113 String url = testBuffer.toString();
114 boolean result = urlVal.isValid(url);
115 assertEquals(url, expected, result);
116 if (printStatus) {
117 if (printIndex) {
118 System.out.print(testPartsIndextoString());
119 } else {
120 if (result == expected) {
121 System.out.print('.');
122 } else {
123 System.out.print('X');
124 }
125 }
126 printed++;
127 if (printed == statusPerLine) {
128 System.out.println();
129 printed = 0;
130 }
131 }
132 } while (incrementTestPartsIndex(testPartsIndex, testObjects));
133 if (printStatus) {
134 System.out.println();
135 }
136 }
137
138 /**
139 * Non-regression test for VALIDATOR-202
140 */
141 @Test
142 public void testValidator202() {
143 String[] schemes = {"http", "https"};
144 UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS);
145 assertTrue(urlValidator.isValid(
146 "http://l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.l.org"));
147 }
148
149 /**
150 * Non-regression test for VALIDATOR-204
151 */
152 @Test
153 public void testValidator204() {
154 String[] schemes = {"http", "https"};
155 UrlValidator urlValidator = new UrlValidator(schemes);
156 assertTrue(urlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
157 }
158
159 /**
160 * Non-regression test for VALIDATOR-218
161 */
162 @Test
163 public void testValidator218() {
164 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
165 assertTrue("parentheses should be valid in URLs",
166 validator.isValid("http://somewhere.com/pathxyz/file(1).html"));
167 }
168
169 /**
170 * Non-regression test for VALIDATOR-235
171 */
172 @Test
173 public void testValidator235() {
174 String version = System.getProperty("java.version");
175 if (version.compareTo("1.6") < 0) {
176 System.out.println("Cannot run Unicode IDN tests");
177 return; // Cannot run the test
178 }
179 UrlValidator validator = new UrlValidator();
180 assertTrue("xn--d1abbgf6aiiy.xn--p1ai should validate", validator.isValid("http://xn--d1abbgf6aiiy.xn--p1ai"));
181 assertTrue("президент.рф should validate", validator.isValid("http://президент.рф"));
182 assertTrue("www.b\u00fccher.ch should validate", validator.isValid("http://www.b\u00fccher.ch"));
183 assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("http://www.\uFFFD.ch"));
184 assertTrue("www.b\u00fccher.ch should validate", validator.isValid("ftp://www.b\u00fccher.ch"));
185 assertFalse("www.\uFFFD.ch FFFD should fail", validator.isValid("ftp://www.\uFFFD.ch"));
186 }
187
188 /**
189 * Non-regression test for VALIDATOR-248
190 */
191 @Test
192 public void testValidator248() {
193 RegexValidator regex = new RegexValidator(new String[] {"localhost", ".*\\.my-testing"});
194 UrlValidator validator = new UrlValidator(regex, 0);
195
196 assertTrue("localhost URL should validate",
197 validator.isValid("http://localhost/test/index.html"));
198 assertTrue("first.my-testing should validate",
199 validator.isValid("http://first.my-testing/test/index.html"));
200 assertTrue("sup3r.my-testing should validate",
201 validator.isValid("http://sup3r.my-testing/test/index.html"));
202
203 assertFalse("broke.my-test should not validate",
204 validator.isValid("http://broke.my-test/test/index.html"));
205
206 assertTrue("www.apache.org should still validate",
207 validator.isValid("http://www.apache.org/test/index.html"));
208
209 // Now check using options
210 validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
211
212 assertTrue("localhost URL should validate",
213 validator.isValid("http://localhost/test/index.html"));
214
215 assertTrue("machinename URL should validate",
216 validator.isValid("http://machinename/test/index.html"));
217
218 assertTrue("www.apache.org should still validate",
219 validator.isValid("http://www.apache.org/test/index.html"));
220 }
221
222 /**
223 * Non-regression test for VALIDATOR-288
224 */
225 @Test
226 public void testValidator288() {
227 UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
228
229 assertTrue("hostname should validate",
230 validator.isValid("http://hostname"));
231
232 assertTrue("hostname with path should validate",
233 validator.isValid("http://hostname/test/index.html"));
234
235 assertTrue("localhost URL should validate",
236 validator.isValid("http://localhost/test/index.html"));
237
238 assertFalse("first.my-testing should not validate",
239 validator.isValid("http://first.my-testing/test/index.html"));
240
241 assertFalse("broke.hostname should not validate",
242 validator.isValid("http://broke.hostname/test/index.html"));
243
244 assertTrue("www.apache.org should still validate",
245 validator.isValid("http://www.apache.org/test/index.html"));
246
247 // Turn it off, and check
248 validator = new UrlValidator(0);
249
250 assertFalse("hostname should no longer validate",
251 validator.isValid("http://hostname"));
252
253 assertFalse("localhost URL should no longer validate",
254 validator.isValid("http://localhost/test/index.html"));
255
256 assertTrue("www.apache.org should still validate",
257 validator.isValid("http://www.apache.org/test/index.html"));
258 }
259
260 /**
261 * Non-regression test for VALIDATOR-276
262 */
263 @Test
264 public void testValidator276() {
265 // file:// isn't allowed by default
266 UrlValidator validator = new UrlValidator();
267
268 assertTrue("http://apache.org/ should be allowed by default",
269 validator.isValid("http://www.apache.org/test/index.html"));
270
271 assertFalse("file:///c:/ shouldn't be allowed by default",
272 validator.isValid("file:///C:/some.file"));
273
274 assertFalse("file:///c:\\ shouldn't be allowed by default",
275 validator.isValid("file:///C:\\some.file"));
276
277 assertFalse("file:///etc/ shouldn't be allowed by default",
278 validator.isValid("file:///etc/hosts"));
279
280 assertFalse("file://localhost/etc/ shouldn't be allowed by default",
281 validator.isValid("file://localhost/etc/hosts"));
282
283 assertFalse("file://localhost/c:/ shouldn't be allowed by default",
284 validator.isValid("file://localhost/c:/some.file"));
285
286 // Turn it on, and check
287 // Note - we need to enable local urls when working with file:
288 validator = new UrlValidator(new String[] {"http", "file"}, UrlValidator.ALLOW_LOCAL_URLS);
289
290 assertTrue("http://apache.org/ should be allowed by default",
291 validator.isValid("http://www.apache.org/test/index.html"));
292
293 assertTrue("file:///c:/ should now be allowed",
294 validator.isValid("file:///C:/some.file"));
295
296 // Currently, we don't support the c:\ form
297 assertFalse("file:///c:\\ shouldn't be allowed",
298 validator.isValid("file:///C:\\some.file"));
299
300 assertTrue("file:///etc/ should now be allowed",
301 validator.isValid("file:///etc/hosts"));
302
303 assertTrue("file://localhost/etc/ should now be allowed",
304 validator.isValid("file://localhost/etc/hosts"));
305
306 assertTrue("file://localhost/c:/ should now be allowed",
307 validator.isValid("file://localhost/c:/some.file"));
308
309 // These are never valid
310 assertFalse("file://c:/ shouldn't ever be allowed, needs file:///c:/",
311 validator.isValid("file://C:/some.file"));
312
313 assertFalse("file://c:\\ shouldn't ever be allowed, needs file:///c:/",
314 validator.isValid("file://C:\\some.file"));
315 }
316
317 /**
318 * Non-regression test for VALIDATOR-309
319 */
320 @Test
321 public void testValidator309() {
322 UrlValidator urlValidator = new UrlValidator();
323 assertTrue(urlValidator.isValid("http://sample.ondemand.com/"));
324 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/"));
325 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/"));
326 urlValidator = new UrlValidator(new String[] {"HTTP", "HTTPS"});
327 assertTrue(urlValidator.isValid("http://sample.ondemand.com/"));
328 assertTrue(urlValidator.isValid("hTtP://sample.ondemand.CoM/"));
329 assertTrue(urlValidator.isValid("httpS://SAMPLE.ONEMAND.COM/"));
330 }
331
332 /**
333 * Non-regression test for VALIDATOR-339
334 */
335 @Test
336 public void testValidator339() {
337 UrlValidator urlValidator = new UrlValidator();
338 assertTrue(urlValidator.isValid("http://www.cnn.com/WORLD/?hpt=sitenav")); // without
339 assertTrue(urlValidator.isValid("http://www.cnn.com./WORLD/?hpt=sitenav")); // with
340 assertFalse(urlValidator.isValid("http://www.cnn.com../")); // doubly dotty
341 assertFalse(urlValidator.isValid("http://www.cnn.invalid/"));
342 assertFalse(urlValidator.isValid("http://www.cnn.invalid./")); // check . does not affect invalid domains
343 }
344
345 /**
346 * Non-regression test for VALIDATOR-339 - IDN
347 */
348 @Test
349 public void testValidator339IDN() {
350 UrlValidator urlValidator = new UrlValidator();
351 assertTrue(urlValidator.isValid("http://президент.рф/WORLD/?hpt=sitenav")); // without
352 assertTrue(urlValidator.isValid("http://президент.рф./WORLD/?hpt=sitenav")); // with
353 assertFalse(urlValidator.isValid("http://президент.рф..../")); // very dotty
354 assertFalse(urlValidator.isValid("http://президент.рф.../")); // triply dotty
355 assertFalse(urlValidator.isValid("http://президент.рф../")); // doubly dotty
356 }
357
358 /**
359 * Non-regression test for VALIDATOR-342
360 */
361 @Test
362 public void testValidator342() {
363 UrlValidator urlValidator = new UrlValidator();
364 assertTrue(urlValidator.isValid("http://example.rocks/"));
365 assertTrue(urlValidator.isValid("http://example.rocks"));
366 }
367
368 static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) {
369 boolean carry = true; //add 1 to lowest order part.
370 boolean maxIndex = true;
371 for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) {
372 int index = testPartsIndex[testPartsIndexIndex];
373 ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex];
374 if (carry) {
375 if (index < part.length - 1) {
376 index++;
377 testPartsIndex[testPartsIndexIndex] = index;
378 carry = false;
379 } else {
380 testPartsIndex[testPartsIndexIndex] = 0;
381 carry = true;
382 }
383 }
384 maxIndex &= (index == (part.length - 1));
385 }
386
387 return (!maxIndex);
388 }
389
390 private String testPartsIndextoString() {
391 StringBuilder carryMsg = new StringBuilder("{");
392 for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
393 carryMsg.append(testPartsIndex[testPartsIndexIndex]);
394 if (testPartsIndexIndex < testPartsIndex.length - 1) {
395 carryMsg.append(',');
396 } else {
397 carryMsg.append('}');
398 }
399 }
400 return carryMsg.toString();
401 }
402
403 /**
404 * Non-regression test for VALIDATOR-290
405 */
406 @Test
407 public void testValidator290() {
408 UrlValidator validator = new UrlValidator();
409 assertTrue(validator.isValid("http://xn--h1acbxfam.idn.icann.org/"));
410 // Internationalized country code top-level domains
411 assertTrue(validator.isValid("http://test.xn--lgbbat1ad8j")); //Algeria
412 assertTrue(validator.isValid("http://test.xn--fiqs8s")); // China
413 assertTrue(validator.isValid("http://test.xn--fiqz9s")); // China
414 assertTrue(validator.isValid("http://test.xn--wgbh1c")); // Egypt
415 assertTrue(validator.isValid("http://test.xn--j6w193g")); // Hong Kong
416 assertTrue(validator.isValid("http://test.xn--h2brj9c")); // India
417 assertTrue(validator.isValid("http://test.xn--mgbbh1a71e")); // India
418 assertTrue(validator.isValid("http://test.xn--fpcrj9c3d")); // India
419 assertTrue(validator.isValid("http://test.xn--gecrj9c")); // India
420 assertTrue(validator.isValid("http://test.xn--s9brj9c")); // India
421 assertTrue(validator.isValid("http://test.xn--xkc2dl3a5ee0h")); // India
422 assertTrue(validator.isValid("http://test.xn--45brj9c")); // India
423 assertTrue(validator.isValid("http://test.xn--mgba3a4f16a")); // Iran
424 assertTrue(validator.isValid("http://test.xn--mgbayh7gpa")); // Jordan
425 assertTrue(validator.isValid("http://test.xn--mgbc0a9azcg")); // Morocco
426 assertTrue(validator.isValid("http://test.xn--ygbi2ammx")); // Palestinian Territory
427 assertTrue(validator.isValid("http://test.xn--wgbl6a")); // Qatar
428 assertTrue(validator.isValid("http://test.xn--p1ai")); // Russia
429 assertTrue(validator.isValid("http://test.xn--mgberp4a5d4ar")); // Saudi Arabia
430 assertTrue(validator.isValid("http://test.xn--90a3ac")); // Serbia
431 assertTrue(validator.isValid("http://test.xn--yfro4i67o")); // Singapore
432 assertTrue(validator.isValid("http://test.xn--clchc0ea0b2g2a9gcd")); // Singapore
433 assertTrue(validator.isValid("http://test.xn--3e0b707e")); // South Korea
434 assertTrue(validator.isValid("http://test.xn--fzc2c9e2c")); // Sri Lanka
435 assertTrue(validator.isValid("http://test.xn--xkc2al3hye2a")); // Sri Lanka
436 assertTrue(validator.isValid("http://test.xn--ogbpf8fl")); // Syria
437 assertTrue(validator.isValid("http://test.xn--kprw13d")); // Taiwan
438 assertTrue(validator.isValid("http://test.xn--kpry57d")); // Taiwan
439 assertTrue(validator.isValid("http://test.xn--o3cw4h")); // Thailand
440 assertTrue(validator.isValid("http://test.xn--pgbs0dh")); // Tunisia
441 assertTrue(validator.isValid("http://test.xn--mgbaam7a8h")); // United Arab Emirates
442 }
443
444 /**
445 * Non-regression test for VALIDATOR-361
446 */
447 @Test
448 public void testValidator361() {
449 UrlValidator validator = new UrlValidator();
450 assertTrue(validator.isValid("http://hello.tokyo/"));
451 }
452
453 /**
454 * Non-regression test for VALIDATOR-363
455 */
456 @Test
457 public void testValidator363() {
458 UrlValidator urlValidator = new UrlValidator();
459 assertTrue(urlValidator.isValid("http://www.example.org/a/b/hello..world"));
460 assertTrue(urlValidator.isValid("http://www.example.org/a/hello..world"));
461 assertTrue(urlValidator.isValid("http://www.example.org/hello.world/"));
462 assertTrue(urlValidator.isValid("http://www.example.org/hello..world/"));
463 assertTrue(urlValidator.isValid("http://www.example.org/hello.world"));
464 assertTrue(urlValidator.isValid("http://www.example.org/hello..world"));
465 assertTrue(urlValidator.isValid("http://www.example.org/..world"));
466 assertTrue(urlValidator.isValid("http://www.example.org/.../world"));
467 assertFalse(urlValidator.isValid("http://www.example.org/../world"));
468 assertFalse(urlValidator.isValid("http://www.example.org/.."));
469 assertFalse(urlValidator.isValid("http://www.example.org/../"));
470 assertFalse(urlValidator.isValid("http://www.example.org/./.."));
471 assertFalse(urlValidator.isValid("http://www.example.org/././.."));
472 assertTrue(urlValidator.isValid("http://www.example.org/..."));
473 assertTrue(urlValidator.isValid("http://www.example.org/.../"));
474 assertTrue(urlValidator.isValid("http://www.example.org/.../.."));
475 }
476
477 /**
478 * Non-regression test for VALIDATOR-375
479 */
480 @Test
481 public void testValidator375() {
482 UrlValidator validator = new UrlValidator();
483 String url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html";
484 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url));
485 url = "http://[::1]:80/index.html";
486 assertTrue("IPv6 address URL should validate: " + url, validator.isValid(url));
487 url = "http://FEDC:BA98:7654:3210:FEDC:BA98:7654:3210:80/index.html";
488 assertFalse("IPv6 address without [] should not validate: " + url, validator.isValid(url));
489 }
490
491 /**
492 * Non-regression test for VALIDATOR-353
493 */
494 @Test
495 public void testValidator353() { // userinfo
496 UrlValidator validator = new UrlValidator();
497 assertTrue(validator.isValid("http://www.apache.org:80/path"));
498 assertTrue(validator.isValid("http://user:pass@www.apache.org:80/path"));
499 assertTrue(validator.isValid("http://user:@www.apache.org:80/path"));
500 assertTrue(validator.isValid("http://us%00er:-._~!$&'()*+,;=@www.apache.org:80/path"));
501 assertFalse(validator.isValid("http://:pass@www.apache.org:80/path"));
502 assertFalse(validator.isValid("http://:@www.apache.org:80/path"));
503 assertFalse(validator.isValid("http://user:pa:ss@www.apache.org/path"));
504 assertFalse(validator.isValid("http://user:pa@ss@www.apache.org/path"));
505 }
506
507 /**
508 * Non-regression test for VALIDATOR-382
509 */
510 @Test
511 public void testValidator382() {
512 UrlValidator validator = new UrlValidator();
513 assertTrue(validator.isValid("ftp://username:password@example.com:8042/over/there/index.dtb?type=animal&name=narwhal#nose"));
514 }
515
516 /**
517 * Non-regression test for VALIDATOR-380
518 */
519 @Test
520 public void testValidator380() {
521 UrlValidator validator = new UrlValidator();
522 assertTrue(validator.isValid("http://www.apache.org:80/path"));
523 assertTrue(validator.isValid("http://www.apache.org:8/path"));
524 assertTrue(validator.isValid("http://www.apache.org:/path"));
525 }
526
527 /**
528 * Unit test of {@link UrlValidator#getValidatorName}.
529 */
530 @Test
531 public void testValidatorName() {
532 assertEquals("URL validator", UrlValidator.getInstance().getValidatorName());
533 }
534
535 //-------------------- Test data for creating a composite URL
536 /**
537 * The data given below approximates the 4 parts of a URL
538 * {@code <scheme>://<authority><path>?<query>} except that the port number
539 * is broken out of authority to increase the number of permutations.
540 * A complete URL is composed of a scheme+authority+port+path+query,
541 * all of which must be individually valid for the entire URL to be considered
542 * valid.
543 */
544 ResultPair[] testUrlScheme = {new ResultPair("http://", true),
545 new ResultPair("ftp://", true),
546 new ResultPair("h3t://", true),
547 new ResultPair("3ht://", false),
548 new ResultPair("http:/", false),
549 new ResultPair("http:", false),
550 new ResultPair("http/", false),
551 new ResultPair("://", false),
552 new ResultPair("", true)};
553
554 ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true),
555 new ResultPair("go.com", true),
556 new ResultPair("go.au", true),
557 new ResultPair("0.0.0.0", true),
558 new ResultPair("255.255.255.255", true),
559 new ResultPair("256.256.256.256", false),
560 new ResultPair("255.com", true),
561 new ResultPair("1.2.3.4.5", false),
562 new ResultPair("1.2.3.4.", false),
563 new ResultPair("1.2.3", false),
564 new ResultPair(".1.2.3.4", false),
565 new ResultPair("go.a", false),
566 new ResultPair("go.a1a", false),
567 new ResultPair("go.cc", true),
568 new ResultPair("go.1aa", false),
569 new ResultPair("aaa.", false),
570 new ResultPair(".aaa", false),
571 new ResultPair("aaa", false),
572 new ResultPair("", false)
573 };
574 ResultPair[] testUrlPort = {new ResultPair(":80", true),
575 new ResultPair(":65535", true),
576 new ResultPair(":0", true),
577 new ResultPair("", true),
578 new ResultPair(":-1", false),
579 new ResultPair(":65636", true),
580 new ResultPair(":65a", false)
581 };
582 ResultPair[] testPath = {new ResultPair("/test1", true),
583 new ResultPair("/t123", true),
584 new ResultPair("/$23", true),
585 new ResultPair("/..", false),
586 new ResultPair("/../", false),
587 new ResultPair("/test1/", true),
588 new ResultPair("", true),
589 new ResultPair("/test1/file", true),
590 new ResultPair("/..//file", false),
591 new ResultPair("/test1//file", false)
592 };
593 //Test allow2slash, noFragment
594 ResultPair[] testUrlPathOptions = {new ResultPair("/test1", true),
595 new ResultPair("/t123", true),
596 new ResultPair("/$23", true),
597 new ResultPair("/..", false),
598 new ResultPair("/../", false),
599 new ResultPair("/test1/", true),
600 new ResultPair("/#", false),
601 new ResultPair("", true),
602 new ResultPair("/test1/file", true),
603 new ResultPair("/t123/file", true),
604 new ResultPair("/$23/file", true),
605 new ResultPair("/../file", false),
606 new ResultPair("/..//file", false),
607 new ResultPair("/test1//file", true),
608 new ResultPair("/#/file", false)
609 };
610
611 ResultPair[] testUrlQuery = {new ResultPair("?action=view", true),
612 new ResultPair("?action=edit&mode=up", true),
613 new ResultPair("", true)
614 };
615
616 Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery};
617 Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery};
618 int[] testPartsIndex = {0, 0, 0, 0, 0};
619
620 //---------------- Test data for individual url parts ----------------
621 private final String[] schemes = {"http", "gopher", "g0-To+.",
622 "not_valid" // TODO this will need to be dropped if the ctor validates schemes
623 };
624
625 ResultPair[] testScheme = {new ResultPair("http", true),
626 new ResultPair("ftp", false),
627 new ResultPair("httpd", false),
628 new ResultPair("gopher", true),
629 new ResultPair("g0-to+.", true),
630 new ResultPair("not_valid", false), // underscore not allowed
631 new ResultPair("HtTp", true),
632 new ResultPair("telnet", false)};
633}
Note: See TracBrowser for help on using the repository browser.