Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/x509/GeneralName/DNSNameTest.java
38853 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @summary DNSName parsing tests26* @bug 821395227* @modules java.base/sun.security.x50928* @run testng DNSNameTest29*/3031import java.io.IOException;32import sun.security.x509.DNSName;3334import org.testng.annotations.DataProvider;35import org.testng.annotations.Test;3637import static org.testng.Assert.*;3839public class DNSNameTest {40@DataProvider(name = "goodNames")41public Object[][] goodNames() {42Object[][] data = {43{"abc.com"},44{"ABC.COM"},45{"a12.com"},46{"a1b2c3.com"},47{"1abc.com"},48{"123.com"},49{"abc.com-"}, // end with hyphen50{"a-b-c.com"}, // hyphens51};52return data;53}5455@DataProvider(name = "badNames")56public Object[][] badNames() {57Object[][] data = {58{" 1abc.com"}, // begin with space59{"1abc.com "}, // end with space60{"1a bc.com "}, // no space allowed61{"-abc.com"}, // begin with hyphen62{"a..b"}, // ..63{".a"}, // begin with .64{"a."}, // end with .65{""}, // empty66{" "}, // space only67};68return data;69}7071@Test(dataProvider = "goodNames")72public void testGoodDNSName(String dnsNameString) {73try {74DNSName dn = new DNSName(dnsNameString);75} catch (IOException e) {76fail("Unexpected IOException");77}78}7980@Test(dataProvider = "badNames")81public void testBadDNSName(String dnsNameString) {82try {83DNSName dn = new DNSName(dnsNameString);84fail("IOException expected");85} catch (IOException e) {86if (!e.getMessage().contains("DNSName"))87fail("Unexpeceted message: " + e);88}89}90}919293