提交 d3f3c958 编写于 作者: W weijun

7040916: DynamicKeyTab test fails on Windows

Reviewed-by: xuelei
上级 7244d5ec
...@@ -92,10 +92,10 @@ public class KeyTab implements KeyTabConstants { ...@@ -92,10 +92,10 @@ public class KeyTab implements KeyTabConstants {
tabName = filename; tabName = filename;
try { try {
lastModified = new File(tabName).lastModified(); lastModified = new File(tabName).lastModified();
KeyTabInputStream kis = try (KeyTabInputStream kis =
new KeyTabInputStream(new FileInputStream(filename)); new KeyTabInputStream(new FileInputStream(filename))) {
load(kis); load(kis);
kis.close(); }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
entries.clear(); entries.clear();
isMissing = true; isMissing = true;
...@@ -439,10 +439,10 @@ public class KeyTab implements KeyTabConstants { ...@@ -439,10 +439,10 @@ public class KeyTab implements KeyTabConstants {
public synchronized static KeyTab create(String name) public synchronized static KeyTab create(String name)
throws IOException, RealmException { throws IOException, RealmException {
KeyTabOutputStream kos = try (KeyTabOutputStream kos =
new KeyTabOutputStream(new FileOutputStream(name)); new KeyTabOutputStream(new FileOutputStream(name))) {
kos.writeVersion(KRB5_KT_VNO); kos.writeVersion(KRB5_KT_VNO);
kos.close(); }
return new KeyTab(name); return new KeyTab(name);
} }
...@@ -450,13 +450,13 @@ public class KeyTab implements KeyTabConstants { ...@@ -450,13 +450,13 @@ public class KeyTab implements KeyTabConstants {
* Saves the file at the directory. * Saves the file at the directory.
*/ */
public synchronized void save() throws IOException { public synchronized void save() throws IOException {
KeyTabOutputStream kos = try (KeyTabOutputStream kos =
new KeyTabOutputStream(new FileOutputStream(tabName)); new KeyTabOutputStream(new FileOutputStream(tabName))) {
kos.writeVersion(kt_vno); kos.writeVersion(kt_vno);
for (int i = 0; i < entries.size(); i++) { for (int i = 0; i < entries.size(); i++) {
kos.writeEntry(entries.elementAt(i)); kos.writeEntry(entries.elementAt(i));
}
} }
kos.close();
} }
/** /**
...@@ -519,9 +519,9 @@ public class KeyTab implements KeyTabConstants { ...@@ -519,9 +519,9 @@ public class KeyTab implements KeyTabConstants {
* @exception IOException. * @exception IOException.
*/ */
public synchronized void createVersion(File file) throws IOException { public synchronized void createVersion(File file) throws IOException {
KeyTabOutputStream kos = try (KeyTabOutputStream kos =
new KeyTabOutputStream(new FileOutputStream(file)); new KeyTabOutputStream(new FileOutputStream(file))) {
kos.write16(KRB5_KT_VNO); kos.write16(KRB5_KT_VNO);
kos.close(); }
} }
} }
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.ietf.jgss.GSSException; import org.ietf.jgss.GSSException;
import sun.security.jgss.GSSUtil; import sun.security.jgss.GSSUtil;
import sun.security.krb5.KrbException; import sun.security.krb5.KrbException;
...@@ -47,8 +49,7 @@ public class DynamicKeytab { ...@@ -47,8 +49,7 @@ public class DynamicKeytab {
OneKDC k = new OneKDC(null); OneKDC k = new OneKDC(null);
k.writeJAASConf(); k.writeJAASConf();
new File(OneKDC.KTAB).delete(); Files.delete(Paths.get(OneKDC.KTAB));
// Starts with no keytab // Starts with no keytab
c = Context.fromJAAS("client"); c = Context.fromJAAS("client");
...@@ -79,11 +80,13 @@ public class DynamicKeytab { ...@@ -79,11 +80,13 @@ public class DynamicKeytab {
connect(); connect();
// Test 5: invalid keytab file, should ignore // Test 5: invalid keytab file, should ignore
new FileOutputStream(OneKDC.KTAB).write("BADBADBAD".getBytes()); try (FileOutputStream fos = new FileOutputStream(OneKDC.KTAB)) {
fos.write("BADBADBAD".getBytes());
}
connect(); connect();
// Test 6: delete keytab file, identical to revoke all // Test 6: delete keytab file, identical to revoke all
new File(OneKDC.KTAB).delete(); Files.delete(Paths.get(OneKDC.KTAB));
try { try {
connect(); connect();
throw new Exception("Should not success"); throw new Exception("Should not success");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册