Add SQLCipher _key DSN support
Some checks failed
Go / Test (1.24, macos-latest) (push) Has been cancelled
Go / Test (1.24, ubuntu-latest) (push) Has been cancelled
Go / Test (1.25, macos-latest) (push) Has been cancelled
Go / Test (1.25, ubuntu-latest) (push) Has been cancelled
Go / Test (1.26, macos-latest) (push) Has been cancelled
Go / Test (1.26, ubuntu-latest) (push) Has been cancelled
Go / Test for Windows (1.24) (push) Has been cancelled
Go / Test for Windows (1.25) (push) Has been cancelled
Go / Test for Windows (1.26) (push) Has been cancelled
dockerfile / Run Dockerfiles in examples (push) Has been cancelled

This commit is contained in:
2026-08-06 14:00:09 +02:00
parent cc41b8c876
commit 9fdc81b5a8
5 changed files with 168 additions and 1 deletions

View File

@@ -103,6 +103,29 @@ func TestOpen(t *testing.T) {
}
}
func TestSQLCipherKeyPragma(t *testing.T) {
rawKey := "x'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'"
tests := []struct {
key string
want string
}{
{rawKey, "PRAGMA key = \"" + rawKey + "\";"},
{"pass'word; PRAGMA foreign_keys = OFF", "PRAGMA key = 'pass''word; PRAGMA foreign_keys = OFF';"},
}
for _, test := range tests {
got, err := sqlCipherKeyPragma(test.key)
if err != nil {
t.Fatalf("sqlCipherKeyPragma(%q): %v", test.key, err)
}
if got != test.want {
t.Errorf("sqlCipherKeyPragma(%q) = %q; want %q", test.key, got, test.want)
}
}
if _, err := sqlCipherKeyPragma("pass\x00word"); err == nil {
t.Error("sqlCipherKeyPragma accepted a key containing NUL")
}
}
func TestOpenWithVFS(t *testing.T) {
filename := t.Name() + ".sqlite"