Skip to content

Commit 0e223f1

Browse files
myankelevwangweij
authored andcommitted
8349534: Refactor jdk/sun/security/krb5/runNameEquals.sh to java test
Co-authored-by: Weijun Wang <weijun@openjdk.org> Reviewed-by: mullan
1 parent 2ba80d2 commit 0e223f1

File tree

2 files changed

+36
-155
lines changed

2 files changed

+36
-155
lines changed
Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,57 +22,65 @@
2222
*/
2323

2424
/*
25+
* @test
2526
* @bug 4634392
26-
* @summary JDK code doesn't respect contract for equals and hashCode
27+
* @summary Ensure the GSSName has the correct impl which respects
28+
* the contract for equals and hashCode across different configurations.
29+
* @library /test/lib
2730
* @author Andrew Fan
31+
*
32+
* @run main/othervm -Djava.security.krb5.realm=R -Djava.security.krb5.kdc=127.0.0.1 Krb5NameEquals
33+
* @run main/othervm -Dsun.security.jgss.native=true Krb5NameEquals
2834
*/
2935

30-
import org.ietf.jgss.*;
36+
import jtreg.SkippedException;
37+
import org.ietf.jgss.GSSManager;
38+
import org.ietf.jgss.GSSName;
39+
import org.ietf.jgss.Oid;
3140

3241
public class Krb5NameEquals {
3342

34-
private static String NAME_STR1 = "service@localhost";
35-
private static String NAME_STR2 = "service2@localhost";
43+
private static final String NAME_STR1 = "service@localhost";
44+
private static final String NAME_STR2 = "service2@localhost";
3645
private static final Oid MECH;
3746

3847
static {
39-
Oid temp = null;
4048
try {
41-
temp = new Oid("1.2.840.113554.1.2.2"); // KRB5
49+
MECH = new Oid("1.2.840.113554.1.2.2"); // KRB5
4250
} catch (Exception e) {
4351
// should never happen
52+
throw new RuntimeException("Exception initialising Oid", e);
4453
}
45-
MECH = temp;
4654
}
4755

4856
public static void main(String[] argv) throws Exception {
49-
GSSManager mgr = GSSManager.getInstance();
57+
final GSSManager mgr = GSSManager.getInstance();
58+
59+
// Checking if native GSS is installed, throwing skip exception if it's not.
60+
if (Boolean.getBoolean("sun.security.jgss.native")) {
61+
final var mechs = mgr.getMechs();
62+
if (mechs == null || mechs.length == 0) {
63+
throw new SkippedException("NativeGSS not supported");
64+
}
65+
}
5066

51-
boolean result = true;
5267
// Create GSSName and check their equals(), hashCode() impl
53-
GSSName name1 = mgr.createName(NAME_STR1,
54-
GSSName.NT_HOSTBASED_SERVICE, MECH);
55-
GSSName name2 = mgr.createName(NAME_STR2,
56-
GSSName.NT_HOSTBASED_SERVICE, MECH);
57-
GSSName name3 = mgr.createName(NAME_STR1,
58-
GSSName.NT_HOSTBASED_SERVICE, MECH);
68+
final GSSName name1 = mgr.createName(NAME_STR1,
69+
GSSName.NT_HOSTBASED_SERVICE, MECH);
70+
final GSSName name2 = mgr.createName(NAME_STR2,
71+
GSSName.NT_HOSTBASED_SERVICE, MECH);
72+
final GSSName name3 = mgr.createName(NAME_STR1,
73+
GSSName.NT_HOSTBASED_SERVICE, MECH);
5974

60-
if (!name1.equals(name1) || !name1.equals(name3) ||
61-
!name1.equals((Object) name1) ||
62-
!name1.equals((Object) name3)) {
63-
System.out.println("Error: should be the same name");
64-
result = false;
75+
if (!name1.equals(name3) || !name1.equals((Object) name3)) {
76+
throw new RuntimeException("Error: should be the same name");
6577
} else if (name1.hashCode() != name3.hashCode()) {
66-
System.out.println("Error: should have same hash");
67-
result = false;
78+
throw new RuntimeException("Error: should have same hash");
6879
}
6980

7081
if (name1.equals(name2) || name1.equals((Object) name2)) {
71-
System.out.println("Error: should be different names");
72-
result = false;
82+
throw new RuntimeException("Error: should be different names");
7383
}
74-
if (result) {
75-
System.out.println("Done");
76-
} else System.exit(1);
84+
System.out.println("Done");
7785
}
7886
}

test/jdk/sun/security/krb5/runNameEquals.sh

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)