Skip to content

Commit

Permalink
Add test that specifically addresses #1517
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Mar 29, 2024
1 parent 77b85be commit 000aaa8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Tests/GRDBTests/EncryptionTests.swift
Expand Up @@ -637,6 +637,26 @@ class EncryptionTests: GRDBTestCase {
}
}

// Test for the use case described in <https://github.com/groue/GRDB.swift/discussions/1517>
func testEncryptedDatabaseCanBeAttached() throws {
// Create encrypted db
var config = Configuration()
config.prepareDatabase { db in
try db.usePassphrase("secret")
}
let encryptedDBQueue = try makeDatabaseQueue(filename: "encrypted.sqlite", configuration: config)
try encryptedDBQueue.write { db in
try db.execute(sql: "CREATE TABLE t(a)")
}

let attachingDBQueue = try makeDatabaseQueue()
try attachingDBQueue.inDatabase { db in
try db.execute(sql: "ATTACH DATABASE ? AS encrypted KEY ?", arguments: [encryptedDBQueue.path, "secret"])
let count = try Table("t").fetchCount(db)
XCTAssertEqual(count, 0)
}
}

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 {
Expand Down

0 comments on commit 000aaa8

Please sign in to comment.