提交 bbba0f51 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

Fix bug in changing encrypted DB password that kept the file handle open when…

Fix bug in changing encrypted DB password that kept the file handle open when the wrong password was supplied. (test case from Jens Hohmuth).
上级 d5b6aad1
......@@ -20,7 +20,9 @@ Change Log
<ul><li>The LIRS cache now re-sizes the internal hash map if needed.
<ul><li>Optionally persist session history in the H2 console. (patch from Martin Grajcar)
<ul><li>Add client-info property to get the number of servers currently in the cluster
and which servers that are available. (patch from Nikolaj Fogh)
and which servers that are available. (patch from Nikolaj Fogh)
<ul><li>Fix bug in changing encrypted DB password that kept the file handle
open when the wrong password was supplied. (test case from Jens Hohmuth).
</li></ul>
<h2>Version 1.4.179 Beta (2014-06-23)</h2>
......
......@@ -207,8 +207,12 @@ public class ChangeFileEncryption extends Tool {
} else {
in = FileStore.open(null, fileName, "r", cipherType, decrypt);
}
in.init();
copy(fileName, in, encrypt);
try {
in.init();
copy(fileName, in, encrypt);
} finally {
in.closeSilently();
}
}
private void copy(String fileName) throws IOException {
......
......@@ -95,6 +95,7 @@ public class TestTools extends TestBase {
if (!config.splitFileSystem) {
testChangeFileEncryption(true);
}
testChangeFileEncryptionWithWrongPassword();
testServer();
testScriptRunscript();
testBackupRestore();
......@@ -910,10 +911,9 @@ public class TestTools extends TestBase {
private void testChangeFileEncryption(boolean split) throws SQLException {
org.h2.Driver.load();
final String dir = (split ? "split:19:" : "") + getBaseDir();
String url = "jdbc:h2:" + dir;
String url = "jdbc:h2:" + dir + "/testChangeFileEncryption;CIPHER=AES";
DeleteDbFiles.execute(dir, "testChangeFileEncryption", true);
Connection conn = getConnection(url +
"/testChangeFileEncryption;CIPHER=AES", "sa", "abc 123");
Connection conn = getConnection(url, "sa", "abc 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) "
+ "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
......@@ -924,8 +924,7 @@ public class TestTools extends TestBase {
args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption",
"-cipher", "AES", "-encrypt", "def", "-quiet" };
ChangeFileEncryption.main(args);
conn = getConnection(url + "/testChangeFileEncryption;CIPHER=AES",
"sa", "def 123");
conn = getConnection(url, "sa", "def 123");
stat = conn.createStatement();
stat.execute("SELECT * FROM TEST");
new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) {
......@@ -942,6 +941,37 @@ public class TestTools extends TestBase {
DeleteDbFiles.main(args);
}
private void testChangeFileEncryptionWithWrongPassword() throws SQLException {
org.h2.Driver.load();
final String dir = getBaseDir();
// TODO: this doesn't seem to work in MVSTORE mode yet
String url = "jdbc:h2:" + dir + "/testChangeFileEncryption;CIPHER=AES;MV_STORE=false";
DeleteDbFiles.execute(dir, "testChangeFileEncryption", true);
Connection conn = getConnection(url, "sa", "abc 123");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) "
+ "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
conn.close();
// try with wrong password, this used to have a bug where it kept the
// file handle open
new AssertThrows(SQLException.class) {
@Override
public void test() throws SQLException {
ChangeFileEncryption.execute(dir, "testChangeFileEncryption", "AES", "wrong".toCharArray(),
"def".toCharArray(), true);
}
};
ChangeFileEncryption.execute(dir, "testChangeFileEncryption", "AES", "abc".toCharArray(), "def".toCharArray(),
true);
conn = getConnection(url, "sa", "def 123");
stat = conn.createStatement();
stat.execute("SELECT * FROM TEST");
conn.close();
String[] args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption", "-quiet" };
DeleteDbFiles.main(args);
}
private void testServer() throws SQLException {
Connection conn;
deleteDb("test");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论