Skip to content

Commit 0e6673d

Browse files
Tests that verify over reads do not occur
1 parent f0922c7 commit 0e6673d

File tree

11 files changed

+240
-158
lines changed

11 files changed

+240
-158
lines changed

.idea/workspace.xml

Lines changed: 191 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/armeabi-v7a/libsqlcipher.so

0 Bytes
Binary file not shown.

libs/armeabi/libsqlcipher.so

0 Bytes
Binary file not shown.

libs/sqlcipher.jar

1 Byte
Binary file not shown.

libs/x86/libsqlcipher.so

0 Bytes
Binary file not shown.

src/main/java/net/zetetic/ZeteticApplication.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ public void prepareDatabaseEnvironment(){
5151
}
5252

5353
public SQLiteDatabase createDatabase(File databaseFile){
54+
return createDatabase(databaseFile, null);
55+
}
56+
57+
public SQLiteDatabase createDatabase(File databaseFile, SQLiteDatabaseHook hook){
5458
Log.i(TAG, "Entered ZeteticApplication::createDatabase");
5559
Log.i(TAG, "Before SQLiteDatabase.openOrCreateDatabase");
56-
return SQLiteDatabase.openOrCreateDatabase(databaseFile.getPath(), DATABASE_PASSWORD, null);
60+
return SQLiteDatabase.openOrCreateDatabase(databaseFile.getPath(), DATABASE_PASSWORD, null, hook);
5761
}
5862

5963
public void extractAssetToDatabaseDirectory(String fileName) throws IOException {

src/main/java/net/zetetic/ZeteticContentProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel
3030

3131
SQLiteDatabase.loadLibs(ZeteticApplication.getInstance());
3232
File databasePath = ZeteticApplication.getInstance().getDatabasePath(ZeteticApplication.DATABASE_NAME);
33-
database = ZeteticApplication.getInstance().createDatabase(databasePath);
33+
database = ZeteticApplication.getInstance().createDatabase(databasePath, null);
3434

3535
createDatabaseWithData(database);
3636
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.util.Log;
44
import net.sqlcipher.database.SQLiteDatabase;
5+
import net.sqlcipher.database.SQLiteDatabaseHook;
56
import net.zetetic.ZeteticApplication;
67

78
import java.io.File;
@@ -51,11 +52,23 @@ private void internalTearDown(){
5152

5253
protected SQLiteDatabase createDatabase(File databasePath){
5354
Log.i(TAG, "Before ZeteticApplication.getInstance().createDatabase");
54-
return ZeteticApplication.getInstance().createDatabase(databasePath);
55+
return ZeteticApplication.getInstance().createDatabase(databasePath, new SQLiteDatabaseHook() {
56+
@Override
57+
public void preKey(SQLiteDatabase database) {
58+
createDatabasePreKey(database);
59+
}
60+
61+
@Override
62+
public void postKey(SQLiteDatabase database) {
63+
createDatabasePostKey(database);
64+
}
65+
});
5566
}
5667

5768
protected void setUp(){};
5869
protected void tearDown(SQLiteDatabase database){};
70+
protected void createDatabasePreKey(SQLiteDatabase database){};
71+
protected void createDatabasePostKey(SQLiteDatabase database){};
5972

6073
protected void log(String message){
6174
Log.i(TAG, message);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private List<SQLCipherTest> getTestsToRun(){
9696
tests.add(new VerifyUTF8EncodingForKeyTest());
9797
tests.add(new TextAsIntegerTest());
9898
tests.add(new TextAsDoubleTest());
99+
tests.add(new TextAsLongTest());
99100
tests.add(new CreateNonEncryptedDatabaseTest());
100101
tests.add(new ChangePasswordTest());
101102
tests.add(new ReadableWritableInvalidPasswordTest());

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import net.sqlcipher.database.SQLiteDatabase;
55

66
public class TextAsIntegerTest extends SQLCipherTest {
7+
78
@Override
89
public boolean execute(SQLiteDatabase database) {
910
database.execSQL("create table t1(a TEXT);");
10-
database.execSQL("insert into t1(a) values(500);");
11+
database.execSQL("insert into t1(a) values(15);");
1112
Cursor cursor = database.rawQuery("select * from t1;", new String[]{});
1213
if(cursor != null){
1314
cursor.moveToFirst();
1415
int value = cursor.getInt(0);
15-
return value == 500;
16+
return value == 15;
1617
}
1718
return false;
1819
}

0 commit comments

Comments
 (0)