提交 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
...@@ -21,6 +21,8 @@ Change Log ...@@ -21,6 +21,8 @@ Change Log
<ul><li>Optionally persist session history in the H2 console. (patch from Martin Grajcar) <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 <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> </li></ul>
<h2>Version 1.4.179 Beta (2014-06-23)</h2> <h2>Version 1.4.179 Beta (2014-06-23)</h2>
......
...@@ -207,8 +207,12 @@ public class ChangeFileEncryption extends Tool { ...@@ -207,8 +207,12 @@ public class ChangeFileEncryption extends Tool {
} else { } else {
in = FileStore.open(null, fileName, "r", cipherType, decrypt); in = FileStore.open(null, fileName, "r", cipherType, decrypt);
} }
try {
in.init(); in.init();
copy(fileName, in, encrypt); copy(fileName, in, encrypt);
} finally {
in.closeSilently();
}
} }
private void copy(String fileName) throws IOException { private void copy(String fileName) throws IOException {
......
...@@ -95,6 +95,7 @@ public class TestTools extends TestBase { ...@@ -95,6 +95,7 @@ public class TestTools extends TestBase {
if (!config.splitFileSystem) { if (!config.splitFileSystem) {
testChangeFileEncryption(true); testChangeFileEncryption(true);
} }
testChangeFileEncryptionWithWrongPassword();
testServer(); testServer();
testScriptRunscript(); testScriptRunscript();
testBackupRestore(); testBackupRestore();
...@@ -910,10 +911,9 @@ public class TestTools extends TestBase { ...@@ -910,10 +911,9 @@ public class TestTools extends TestBase {
private void testChangeFileEncryption(boolean split) throws SQLException { private void testChangeFileEncryption(boolean split) throws SQLException {
org.h2.Driver.load(); org.h2.Driver.load();
final String dir = (split ? "split:19:" : "") + getBaseDir(); 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); DeleteDbFiles.execute(dir, "testChangeFileEncryption", true);
Connection conn = getConnection(url + Connection conn = getConnection(url, "sa", "abc 123");
"/testChangeFileEncryption;CIPHER=AES", "sa", "abc 123");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) " stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB) "
+ "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)"); + "AS SELECT X, SPACE(3000) FROM SYSTEM_RANGE(1, 300)");
...@@ -924,8 +924,7 @@ public class TestTools extends TestBase { ...@@ -924,8 +924,7 @@ public class TestTools extends TestBase {
args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption", args = new String[] { "-dir", dir, "-db", "testChangeFileEncryption",
"-cipher", "AES", "-encrypt", "def", "-quiet" }; "-cipher", "AES", "-encrypt", "def", "-quiet" };
ChangeFileEncryption.main(args); ChangeFileEncryption.main(args);
conn = getConnection(url + "/testChangeFileEncryption;CIPHER=AES", conn = getConnection(url, "sa", "def 123");
"sa", "def 123");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("SELECT * FROM TEST"); stat.execute("SELECT * FROM TEST");
new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) { new AssertThrows(ErrorCode.CANNOT_CHANGE_SETTING_WHEN_OPEN_1) {
...@@ -942,6 +941,37 @@ public class TestTools extends TestBase { ...@@ -942,6 +941,37 @@ public class TestTools extends TestBase {
DeleteDbFiles.main(args); 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 { private void testServer() throws SQLException {
Connection conn; Connection conn;
deleteDb("test"); deleteDb("test");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论