Skip to content

Commit 623447b

Browse files
Adding test to allow testing of ATTACH and DETACH commands in SQLCipher for Android
1 parent e684de7 commit 623447b

File tree

9 files changed

+196
-58
lines changed

9 files changed

+196
-58
lines changed

assets/icudt44l.zip

5.35 KB
Binary file not shown.
11.5 KB
Binary file not shown.
17.5 KB
Binary file not shown.

libs/armeabi/libstlport_shared.so

-2.11 MB
Binary file not shown.

libs/sqlcipher.jar

-11 KB
Binary file not shown.

net.zetetic.sqlcipher.test.iws

Lines changed: 147 additions & 54 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.zetetic.tests;
2+
3+
import info.guardianproject.database.sqlcipher.SQLiteDatabase;
4+
import net.zetetic.ZeteticApplication;
5+
6+
import java.io.File;
7+
8+
public class AttachDatabaseTest extends SQLCipherTest {
9+
@Override
10+
public boolean execute(SQLiteDatabase encryptedDatabase) {
11+
12+
encryptedDatabase.execSQL("create table t1(a,b)");
13+
encryptedDatabase.execSQL("insert into t1(a,b) values(?, ?)", new Object[]{"one", "two"});
14+
15+
String newKey = "foo";
16+
File newDatabasePath = ZeteticApplication.getInstance().getDatabasePath("normal.db");
17+
String attachCommand = "ATTACH DATABASE ? as encrypted KEY ?";
18+
String createCommand = "create table encrypted.t1(a,b)";
19+
String insertCommand = "insert into encrypted.t1 SELECT * from t1";
20+
String detachCommand = "DETACH DATABASE encrypted";
21+
encryptedDatabase.execSQL(attachCommand, new Object[]{newDatabasePath.getAbsolutePath(), newKey});
22+
encryptedDatabase.execSQL(createCommand);
23+
encryptedDatabase.execSQL(insertCommand);
24+
encryptedDatabase.execSQL(detachCommand);
25+
26+
return true;
27+
}
28+
29+
@Override
30+
protected void tearDown() {
31+
File newDatabasePath = ZeteticApplication.getInstance().getDatabasePath("normal.db");
32+
newDatabasePath.delete();
33+
}
34+
35+
@Override
36+
public String getName() {
37+
return "Attach Database Test";
38+
}
39+
}

src/main/java/net/zetetic/tests/SQLCipherTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,30 @@ public abstract class SQLCipherTest {
1111

1212
private SQLiteDatabase database;
1313

14-
protected void setUp() {
14+
protected void internalSetUp() {
1515
database = ZeteticApplication.getInstance().createDatabase();
16+
setUp();
1617
}
1718

1819
public TestResult run() {
1920

2021
TestResult result = new TestResult(getName(), false);
2122
try {
22-
setUp();
23+
internalSetUp();
2324
result.setResult(execute(database));
24-
tearDown();
25+
internalTearDown();
2526
} catch (Exception e) {
2627
Log.v(ZeteticApplication.TAG, e.toString());
2728
}
2829
return result;
2930
}
3031

31-
private void tearDown(){
32+
private void internalTearDown(){
3233
database.close();
3334
SQLiteDatabase.releaseMemory();
35+
tearDown();
3436
}
37+
38+
protected void setUp(){};
39+
protected void tearDown(){};
3540
}

src/main/java/net/zetetic/tests/TestSuiteRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private List<SQLCipherTest> getTestsToRun(){
4444
tests.add(new CrossProcessCursorQueryTest());
4545
tests.add(new LoopingQueryTest());
4646
tests.add(new LoopingCountQueryTest());
47+
tests.add(new AttachDatabaseTest());
4748
return tests;
4849
}
4950
}

0 commit comments

Comments
 (0)