|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import org.testng.annotations.DataProvider; |
| 25 | +import org.testng.annotations.Test; |
| 26 | +import sun.security.x509.GeneralNameInterface; |
| 27 | +import sun.security.x509.IPAddressName; |
| 28 | + |
| 29 | +import java.io.IOException; |
| 30 | + |
| 31 | +import static org.testng.Assert.assertEquals; |
| 32 | + |
| 33 | +/* |
| 34 | + * @test |
| 35 | + * @summary Verify IPAddressName.constrains |
| 36 | + * @bug 8267617 |
| 37 | + * @modules java.base/sun.security.x509 |
| 38 | + * @run testng ConstrainsTest |
| 39 | + */ |
| 40 | +public class ConstrainsTest { |
| 41 | + |
| 42 | + IPAddressName ipv4Addr = new IPAddressName("127.0.0.1"); |
| 43 | + IPAddressName ipv4Mask = new IPAddressName("127.0.0.0/255.0.0.0"); |
| 44 | + IPAddressName ipv6Addr = new IPAddressName("::1"); |
| 45 | + IPAddressName ipv6Mask = new IPAddressName("::/0"); |
| 46 | + |
| 47 | + public ConstrainsTest() throws IOException { |
| 48 | + } |
| 49 | + |
| 50 | + @DataProvider(name = "names") |
| 51 | + public Object[][] names() { |
| 52 | + Object[][] data = { |
| 53 | + {ipv4Addr, ipv4Addr, GeneralNameInterface.NAME_MATCH}, |
| 54 | + {ipv4Addr, ipv4Mask, GeneralNameInterface.NAME_WIDENS}, |
| 55 | + {ipv4Addr, ipv6Addr, GeneralNameInterface.NAME_SAME_TYPE}, |
| 56 | + {ipv4Addr, ipv6Mask, GeneralNameInterface.NAME_SAME_TYPE}, |
| 57 | + {ipv4Mask, ipv4Addr, GeneralNameInterface.NAME_NARROWS}, |
| 58 | + {ipv4Mask, ipv4Mask, GeneralNameInterface.NAME_MATCH}, |
| 59 | + {ipv4Mask, ipv6Addr, GeneralNameInterface.NAME_SAME_TYPE}, |
| 60 | + {ipv4Mask, ipv6Mask, GeneralNameInterface.NAME_SAME_TYPE}, |
| 61 | + {ipv6Addr, ipv4Addr, GeneralNameInterface.NAME_SAME_TYPE}, |
| 62 | + {ipv6Addr, ipv4Mask, GeneralNameInterface.NAME_SAME_TYPE}, |
| 63 | + {ipv6Addr, ipv6Addr, GeneralNameInterface.NAME_MATCH}, |
| 64 | + {ipv6Addr, ipv6Mask, GeneralNameInterface.NAME_WIDENS}, |
| 65 | + {ipv6Mask, ipv4Addr, GeneralNameInterface.NAME_SAME_TYPE}, |
| 66 | + {ipv6Mask, ipv4Mask, GeneralNameInterface.NAME_SAME_TYPE}, |
| 67 | + {ipv6Mask, ipv6Addr, GeneralNameInterface.NAME_NARROWS}, |
| 68 | + {ipv6Mask, ipv6Mask, GeneralNameInterface.NAME_MATCH}, |
| 69 | + }; |
| 70 | + return data; |
| 71 | + } |
| 72 | + |
| 73 | + @Test(dataProvider = "names") |
| 74 | + public void testNameContains(IPAddressName addr1, IPAddressName addr2, int result) throws IOException { |
| 75 | + assertEquals(addr1.constrains(addr2), result); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments