Skip to content

Commit

Permalink
Merge pull request #559 from stephencelis/cipher-read-only
Browse files Browse the repository at this point in the history
Make sure the valid key check works with read-only dbs
  • Loading branch information
jberkel authored Dec 9, 2016
2 parents eb1b131 + 7b724b0 commit bcc03e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.11.2 (unreleased), [diff][diff-0.11.2]
========================================

* Fixed SQLCipher integration with read-only databases ([#559][])

0.11.1 (06-12-2016), [diff][diff-0.11.1]
========================================
Expand All @@ -7,15 +11,17 @@
* Fix for ~= operator used with Double ranges
* Various documentation updates

0.11.0 (10-19-2016)
0.11.0 (19-10-2016)
===================

* Swift3 migration ([diff][diff-0.11.0])


[diff-0.11.1]: https://github.com/stephencelis/SQLite.swift/compare/0.11.0...0.11.1
[diff-0.11.0]: https://github.com/stephencelis/SQLite.swift/compare/0.10.1...0.11.0
[diff-0.11.1]: https://github.com/stephencelis/SQLite.swift/compare/0.11.0...0.11.1
[diff-0.11.2]: https://github.com/stephencelis/SQLite.swift/compare/0.11.1...0.11.2

[#532]: https://github.com/stephencelis/SQLite.swift/issues/532
[#546]: https://github.com/stephencelis/SQLite.swift/issues/546
[#553]: https://github.com/stephencelis/SQLite.swift/pull/553
[#559]: https://github.com/stephencelis/SQLite.swift/pull/559
5 changes: 1 addition & 4 deletions SQLite/Extensions/Cipher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ extension Connection {
// the key provided is incorrect. To test that the database can be successfully opened with the
// provided key, it is necessary to perform some operation on the database (i.e. read from it).
private func cipher_key_check() throws {
try execute(
"CREATE TABLE \"__SQLCipher.swift__\" (\"cipher key check\");\n" +
"DROP TABLE \"__SQLCipher.swift__\";"
)
try scalar("SELECT count(*) FROM sqlite_master;")
}
}
#endif
14 changes: 9 additions & 5 deletions SQLiteTests/CipherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ class CipherTests: XCTestCase {
defer { try! FileManager.default.removeItem(atPath: path) }

try! connA.key("hello")
try! connA.run("CREATE TABLE foo (bar TEXT)")

let connB = try! Connection(path)
let connB = try! Connection(path, readonly: true)

var rc: Int32?
do {
try connB.key("world")
XCTFail("expected exception")
} catch Result.error(_, let code, _) {
rc = code
XCTAssertEqual(SQLITE_NOTADB, code)
} catch {
XCTFail()
XCTFail("unexpected error: \(error)")
}
XCTAssertEqual(SQLITE_NOTADB, rc)
}

func test_open_db_encrypted_with_sqlcipher() {
Expand All @@ -78,6 +78,10 @@ class CipherTests: XCTestCase {
// sqlite> CREATE TABLE foo (bar TEXT);
// sqlite> INSERT INTO foo (bar) VALUES ('world');
let encryptedFile = fixture("encrypted", withExtension: "sqlite")

try! FileManager.default.setAttributes([FileAttributeKey.immutable : 1], ofItemAtPath: encryptedFile)
XCTAssertFalse(FileManager.default.isWritableFile(atPath: encryptedFile))

let conn = try! Connection(encryptedFile)
try! conn.key("sqlcipher-test")
XCTAssertEqual(1, try! conn.scalar("SELECT count(*) FROM foo") as? Int64)
Expand Down

0 comments on commit bcc03e9

Please sign in to comment.