Path: blob/master/test/jdk/sun/security/krb5/Krb5NameEquals.java
41152 views
/*1* Copyright (c) 2007, 2011, 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* @bug 463439225* @summary JDK code doesn't respect contract for equals and hashCode26* @author Andrew Fan27*/2829import org.ietf.jgss.*;3031public class Krb5NameEquals {3233private static String NAME_STR1 = "service@localhost";34private static String NAME_STR2 = "service2@localhost";35private static final Oid MECH;3637static {38Oid temp = null;39try {40temp = new Oid("1.2.840.113554.1.2.2"); // KRB541} catch (Exception e) {42// should never happen43}44MECH = temp;45}4647public static void main(String[] argv) throws Exception {48GSSManager mgr = GSSManager.getInstance();4950boolean result = true;51// Create GSSName and check their equals(), hashCode() impl52GSSName name1 = mgr.createName(NAME_STR1,53GSSName.NT_HOSTBASED_SERVICE, MECH);54GSSName name2 = mgr.createName(NAME_STR2,55GSSName.NT_HOSTBASED_SERVICE, MECH);56GSSName name3 = mgr.createName(NAME_STR1,57GSSName.NT_HOSTBASED_SERVICE, MECH);5859if (!name1.equals(name1) || !name1.equals(name3) ||60!name1.equals((Object) name1) ||61!name1.equals((Object) name3)) {62System.out.println("Error: should be the same name");63result = false;64} else if (name1.hashCode() != name3.hashCode()) {65System.out.println("Error: should have same hash");66result = false;67}6869if (name1.equals(name2) || name1.equals((Object) name2)) {70System.out.println("Error: should be different names");71result = false;72}73if (result) {74System.out.println("Done");75} else System.exit(1);76}77}787980