2018-05-30 23:36:49 +03:00
|
|
|
// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by an MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build sqlite_userauth
|
|
|
|
|
|
|
|
package sqlite3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2018-05-31 15:57:32 +03:00
|
|
|
"os"
|
2018-05-30 23:36:49 +03:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2018-05-31 15:57:32 +03:00
|
|
|
func TestAuthCreateDatabase(t *testing.T) {
|
2018-05-30 23:36:49 +03:00
|
|
|
tempFilename := TempFilename(t)
|
2018-05-31 15:57:32 +03:00
|
|
|
defer os.Remove(tempFilename)
|
2018-05-30 23:36:49 +03:00
|
|
|
|
|
|
|
db, err := sql.Open("sqlite3", "file:"+tempFilename+"?_auth&_auth_user=admin&_auth_pass=admin")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to open database:", err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
2018-05-31 15:57:32 +03:00
|
|
|
// Ping database
|
|
|
|
if err := db.Ping(); err != nil {
|
2018-05-30 23:36:49 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:57:32 +03:00
|
|
|
var exists bool
|
|
|
|
err = db.QueryRow("select count(type) from sqlite_master WHERE type='table' and name='sqlite_user';").Scan(&exists)
|
2018-05-30 23:36:49 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:57:32 +03:00
|
|
|
if !exists {
|
|
|
|
t.Fatal("failed to enable User Authentication")
|
|
|
|
}
|
2018-05-30 23:36:49 +03:00
|
|
|
}
|