Skip to content

Basic error message tests with bug reproduction #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.zetetic.tests;

import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteStatement;
import net.sqlcipher.database.SQLiteException;

import net.zetetic.ZeteticApplication;

import android.util.Log;

public class CompileStatementSyntaxErrorMessageTest extends SQLCipherTest {

@Override
public boolean execute(SQLiteDatabase database) {
try {
SQLiteStatement ignored = database.compileStatement("INSERT INTO mytable (mydata) VALUES");
} catch (SQLiteException e) {
Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteException", e);
String message = e.getMessage();
setMessage(message);
// TBD missing error code etc.
if (!message.matches("near \"VALUES\": syntax error: .*\\, while compiling: INSERT INTO mytable \\(mydata\\) VALUES")) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message);
return false;
}
return true;
} catch (Exception e) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e);
return false;
}

return false;
}

@Override
public String getName() {
return "Compile statement syntax error message Test";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.zetetic.tests;

import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteStatement;
import net.sqlcipher.database.SQLiteConstraintException;

import net.zetetic.ZeteticApplication;

import android.util.Log;

public class ExecuteInsertConstraintErrorMessageTest extends SQLCipherTest {

@Override
public boolean execute(SQLiteDatabase database) {
database.execSQL("CREATE TABLE tt(a UNIQUE, b)");
database.execSQL("INSERT INTO tt VALUES (101, 'Alice')");
try {
SQLiteStatement insertStatement = database.compileStatement("INSERT INTO tt VALUES (101, 'Betty')");
long ignored = insertStatement.executeInsert();
} catch (SQLiteConstraintException e) {
Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteConstraintException", e);
String message = e.getMessage();
setMessage(message);
if (!message.matches("error code 19: UNIQUE constraint failed: tt\\.a")) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message);
return false;
}
return true;
} catch (Exception e) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e);
return false;
}

return false;
}

@Override
public String getName() {
return "Execute insert constraint error message Test";
}
}
20 changes: 18 additions & 2 deletions src/main/java/net/zetetic/tests/RawExecSQLExceptionTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
package net.zetetic.tests;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteException;

import net.zetetic.ZeteticApplication;

import android.util.Log;

public class RawExecSQLExceptionTest extends SQLCipherTest {

@Override
public boolean execute(SQLiteDatabase database) {

try{
try {
database.rawExecSQL("select foo from bar");
}catch (Exception e){
} catch (SQLiteException e) {
Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteException", e);
String message = e.getMessage();
setMessage(message);
if (!message.matches("no such table: bar")) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message);
return false;
}
return true;
} catch (Exception e) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e);
return false;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.zetetic.tests;

import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteException;

import net.zetetic.ZeteticApplication;

import android.util.Log;

public class RawQueryNoSuchFunctionErrorMessageTest extends SQLCipherTest {

@Override
public boolean execute(SQLiteDatabase database) {
try {
Cursor ignored = database.rawQuery("SELECT UPER('Test')", null);
} catch (SQLiteException e) {
Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteException", e);
String message = e.getMessage();
setMessage(message);
// TBD missing error code etc.
if (!message.matches("no such function: UPER: .*\\, while compiling: SELECT UPER\\('Test'\\)")) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message);
return false;
}
return true;
} catch (Exception e) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e);
return false;
}

return false;
}

@Override
public String getName() {
return "rawQuery no such function error message Test";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.zetetic.tests;

import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteException;

import net.zetetic.ZeteticApplication;

import android.util.Log;

import java.util.regex.Pattern;

public class RawQueryNonsenseStatementErrorMessageTest extends SQLCipherTest {

@Override
public boolean execute(SQLiteDatabase database) {
try {
Cursor ignored = database.rawQuery("101", null);
} catch (SQLiteException e) {
Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteException", e);
String message = e.getMessage();
setMessage(message);
// TBD missing error code etc.
if (!message.matches("near \"101\": syntax error: .*\\, while compiling: 101")) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message);
return false;
}
return true;
} catch (Exception e) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e);
return false;
}

return false;
}

@Override
public String getName() {
return "rawQuery nonsense statement error message Test";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.zetetic.tests;

import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteException;

import net.zetetic.ZeteticApplication;

import android.util.Log;

public class RawQuerySyntaxErrorMessageTest extends SQLCipherTest {

@Override
public boolean execute(SQLiteDatabase database) {
try {
Cursor ignored = database.rawQuery("SLCT 1", null);
} catch (SQLiteException e) {
Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteException", e);
String message = e.getMessage();
setMessage(message);
// TBD missing error code etc.
if (!message.matches("near \"SLCT\": syntax error: .*\\, while compiling: SLCT 1")) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message);
return false;
}
return true;
} catch (Exception e) {
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e);
return false;
}

return false;
}

@Override
public String getName() {
return "rawQuery syntax error message Test";
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/zetetic/tests/TestSuiteRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ private List<SQLCipherTest> getTestsToRun(){
tests.add(new VerifyCipherProviderTest());
tests.add(new VerifyCipherProviderVersionTest());
tests.add(new AES256GCMCipherTest());
tests.add(new RawQuerySyntaxErrorMessageTest());
tests.add(new RawQueryNonsenseStatementErrorMessageTest());
tests.add(new RawQueryNoSuchFunctionErrorMessageTest());
tests.add(new CompileStatementSyntaxErrorMessageTest());
tests.add(new ExecuteInsertConstraintErrorMessageTest());
return tests;
}
}