Path: blob/master/test/jdk/java/security/cert/GetInstance.java
41149 views
/*1* Copyright (c) 2001, 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* @bug 441694626* @summary Make sure {CertStore,CertPathBuilder,CertPathValidator,27* CertificateFactory}.getInstance throws InvalidAlgorithmParameterException28* if invalid params are specified and NoSuchAlgorithmException (or29* CertificateException for CertificateFactory) if bogus type is specified30*/31import java.security.*;32import java.security.cert.*;33import java.util.*;3435public class GetInstance {3637public static void main(String[] args) throws Exception {3839CollectionCertStoreParameters ccsp40= new CollectionCertStoreParameters(new ArrayList());41try {42CertStore cs = CertStore.getInstance("LDAP", ccsp);43throw new Exception("CertStore.getInstance() should have thrown " +44"InvalidAlgorithmParameterException");45} catch (InvalidAlgorithmParameterException iape) { }4647try {48CertStore cs = CertStore.getInstance("BOGUS", null);49throw new Exception("CertStore.getInstance() should have thrown " +50"NoSuchAlgorithmException");51} catch (NoSuchAlgorithmException nsae) { }5253try {54CertPathBuilder cpb = CertPathBuilder.getInstance("BOGUS");55throw new Exception("CertPathBuilder.getInstance() should have " +56"thrown NoSuchAlgorithmException");57} catch (NoSuchAlgorithmException nsae) { }5859try {60CertPathValidator cpv = CertPathValidator.getInstance("BOGUS");61throw new Exception("CertPathValidator.getInstance() should have " +62"thrown NoSuchAlgorithmException");63} catch (NoSuchAlgorithmException nsae) { }6465try {66CertificateFactory cf = CertificateFactory.getInstance("BOGUS");67throw new Exception("CertificateFactory.getInstance() should " +68"have thrown CertificateException");69} catch (CertificateException ce) { }70}71}727374