Disable query tracing inside EncryptionTests.testExportPlainTextDatabaseToEncryptedDatabase (workaround https://github.com/sqlcipher/sqlcipher/issues/216)

This commit is contained in:
Gwendal Roué authored and Gwendal Roué committed 2017-05-28 11:40:26 +02:00
1 parent 7eecb059e6
commit 1fb7f9ff5b
2 files changed
+44 -41

No files matched your search

-2
View File
@@ -1,5 +1,3 @@
- [ ] Fix flaky ConcurrencyTests.testReaderInDeferredTransactionDuringDefaultTransaction
- [ ] Upgrade SQLCipher to v3.4.1
- [ ] We share the database cache between database pool writers and readers. But what if a writer modifies the database schema within a transaction, and a concurrent reader reads the cache? Bad things, isn't it? Write failing tests first, and fix the bug.
- [ ] Attach databases. Interesting question: what happens when one attaches a non-WAL db to a databasePool?
- [ ] SQLCipher: sqlite3_rekey is discouraged (https://github.com/ccgus/fmdb/issues/547#issuecomment-259219320)
+44 -39
View File
@@ -332,44 +332,49 @@ class EncryptionTests: GRDBTestCase {
}
}
}
// TODO: restore this test once https://github.com/sqlcipher/sqlcipher/issues/216 is fixed
// func testExportPlainTextDatabaseToEncryptedDatabase() throws {
// // See https://discuss.zetetic.net/t/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher-and-avoid-file-is-encrypted-or-is-not-a-database-errors/868?source_topic_id=939
// do {
// dbConfiguration.passphrase = nil
// let plainTextDBQueue = try makeDatabaseQueue(filename: "plaintext.sqlite")
// try plainTextDBQueue.inDatabase { db in
// try db.execute("CREATE TABLE data (value INTEGER)")
// try db.execute("INSERT INTO data (value) VALUES (1)")
// }
//
// dbConfiguration.passphrase = "secret"
// do {
// _ = try makeDatabaseQueue(filename: "plaintext.sqlite")
// } catch let error as DatabaseError {
// XCTAssertEqual(error.resultCode, .SQLITE_NOTADB)
// XCTAssertEqual(error.message!, "file is encrypted or is not a database")
// XCTAssertTrue(error.sql == nil)
// XCTAssertEqual(error.description, "SQLite error 26: file is encrypted or is not a database")
// }
//
// let encryptedDBQueue = try makeDatabaseQueue(filename: "encrypted.sqlite")
//
// try plainTextDBQueue.inDatabase { db in
// try db.execute("ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
// try db.execute("SELECT sqlcipher_export('encrypted')")
// try db.execute("DETACH DATABASE encrypted")
// }
// }
//
// do {
// dbConfiguration.passphrase = "secret"
// let dbQueue = try makeDatabaseQueue(filename: "encrypted.sqlite")
// try dbQueue.inDatabase { db in
// XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
// }
// }
// }
func testExportPlainTextDatabaseToEncryptedDatabase() throws {
// See https://discuss.zetetic.net/t/how-to-encrypt-a-plaintext-sqlite-database-to-use-sqlcipher-and-avoid-file-is-encrypted-or-is-not-a-database-errors/868?source_topic_id=939
do {
// https://github.com/sqlcipher/sqlcipher/issues/216
// SQLCipher 3.4.1 crashes when sqlcipher_export() is called and a
// trace hook has been installed. So we disable query tracing for
// this test.
dbConfiguration.trace = nil
dbConfiguration.passphrase = nil
let plainTextDBQueue = try makeDatabaseQueue(filename: "plaintext.sqlite")
try plainTextDBQueue.inDatabase { db in
try db.execute("CREATE TABLE data (value INTEGER)")
try db.execute("INSERT INTO data (value) VALUES (1)")
}
dbConfiguration.passphrase = "secret"
do {
_ = try makeDatabaseQueue(filename: "plaintext.sqlite")
} catch let error as DatabaseError {
XCTAssertEqual(error.resultCode, .SQLITE_NOTADB)
XCTAssertEqual(error.message!, "file is encrypted or is not a database")
XCTAssertTrue(error.sql == nil)
XCTAssertEqual(error.description, "SQLite error 26: file is encrypted or is not a database")
}
let encryptedDBQueue = try makeDatabaseQueue(filename: "encrypted.sqlite")
try plainTextDBQueue.inDatabase { db in
try db.execute("ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
try db.execute("SELECT sqlcipher_export('encrypted')")
try db.execute("DETACH DATABASE encrypted")
}
}
do {
dbConfiguration.passphrase = "secret"
let dbQueue = try makeDatabaseQueue(filename: "encrypted.sqlite")
try dbQueue.inDatabase { db in
XCTAssertEqual(try Int.fetchOne(db, "SELECT COUNT(*) FROM data")!, 1)
}
}
}
}
#endif