Skip to content
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

Make sure the valid key check works with read-only dbs #559

Merged
merged 3 commits into from
Dec 9, 2016
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
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