Path: blob/master/test/jdk/javax/security/auth/kerberos/KerberosNullsAndDestroyTest.java
41152 views
/*1* Copyright (c) 2014, 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 804307126* @summary Expose session key and KRB_CRED through extended GSS-API27*/2829import javax.security.auth.kerberos.*;30import java.util.function.Supplier;3132public class KerberosNullsAndDestroyTest {3334public static void main(String[] args) throws Exception {3536KerberosPrincipal c = new KerberosPrincipal("me@HERE");37KerberosPrincipal s = new KerberosPrincipal("you@THERE");3839// These object constructions should throw NullPointerException40checkNPE(() -> new KerberosKey(c, null, 17, 1));41checkNPE(() -> new EncryptionKey(null, 17));42checkNPE(() -> new KerberosCredMessage(null, s, new byte[1]));43checkNPE(() -> new KerberosCredMessage(c, null, new byte[1]));44checkNPE(() -> new KerberosCredMessage(c, s, null));4546KerberosKey k1 = new KerberosKey(c, new byte[16], 17, 1);47EncryptionKey k2 = new EncryptionKey(new byte[16], 17);48KerberosCredMessage m = new KerberosCredMessage(c, s, new byte[1]);4950// These get calls should throw IllegalStateException51k1.destroy();52checkISE(() -> k1.getAlgorithm());53checkISE(() -> k1.getEncoded());54checkISE(() -> k1.getFormat());55checkISE(() -> k1.getKeyType());56checkISE(() -> k1.getPrincipal());57checkISE(() -> k1.getVersionNumber());5859k2.destroy();60checkISE(() -> k2.getAlgorithm());61checkISE(() -> k2.getEncoded());62checkISE(() -> k2.getFormat());63checkISE(() -> k2.getKeyType());6465m.destroy();66checkISE(() -> m.getSender());67checkISE(() -> m.getRecipient());68checkISE(() -> m.getEncoded());69}7071static void checkNPE(Supplier<?> f) throws Exception {72check(f, NullPointerException.class);73}7475static void checkISE(Supplier<?> f) throws Exception {76check(f, IllegalStateException.class);77}7879static void check(Supplier<?> f, Class<? extends Exception> type) throws Exception {80try {81f.get();82} catch (Exception e) {83if (e.getClass() != type) {84throw e;85} else {86return;87}88}89throw new Exception("Should fail");90}91}929394