1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.shiro.web.filter.authz; 20 21 import org.junit.Test; 22 import static org.junit.Assert.*; 23 24 import java.util.regex.Pattern; 25 26 /** @since 1.0 */ 27 public class HostFilterTest { 28 29 @Test 30 public void testPrivateClassC() { 31 Pattern p = Pattern.compile(HostFilter.PRIVATE_CLASS_C_REGEX); 32 33 String base = "192.168."; 34 35 for (int i = 0; i < 256; i++) { 36 String ibase = base + i; 37 for (int j = 0; j < 256; j++) { 38 String ip = ibase + "." + j; 39 assertTrue(p.matcher(ip).matches()); 40 } 41 } 42 } 43 44 @Test 45 public void testPrivateClassB() { 46 Pattern p = Pattern.compile(HostFilter.PRIVATE_CLASS_B_REGEX); 47 48 String base = "172."; 49 50 for (int i = 16; i < 32; i++) { 51 String ibase = base + i; 52 for (int j = 0; j < 256; j++) { 53 String jBase = ibase + "." + j; 54 for (int k = 0; k < 256; k++) { 55 String ip = jBase + "." + k; 56 assertTrue(p.matcher(ip).matches()); 57 } 58 } 59 } 60 } 61 62 /* Takes a long time (20+ seconds?) - only enable when testing explicitly: 63 @Test 64 public void testPrivateClassA() { 65 Pattern p = Pattern.compile(HostFilter.PRIVATE_CLASS_A_REGEX); 66 67 String base = "10."; 68 69 for (int i = 0; i < 256; i++) { 70 String ibase = base + i; 71 for (int j = 0; j < 256; j++) { 72 String jBase = ibase + "." + j; 73 for (int k = 0; k < 256; k++) { 74 String ip = jBase + "." + k; 75 assertTrue(p.matcher(ip).matches()); 76 } 77 } 78 } 79 } */ 80 81 }