2018-06-20 23:50:53 +03:00
|
|
|
// Copyright (C) 2018 The Go-SQLite3 Authors.
|
2018-06-13 18:08:59 +03:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by an MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-06-20 23:50:53 +03:00
|
|
|
// +build cgo
|
2018-06-13 18:08:59 +03:00
|
|
|
// +build !sqlite_userauth
|
|
|
|
|
|
|
|
package sqlite3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This file is included for code coverage
|
|
|
|
|
|
|
|
func TestUserAuthOmit(t *testing.T) {
|
|
|
|
var conn *SQLiteConn
|
|
|
|
|
|
|
|
sql.Register("sqlite3_with_conn",
|
|
|
|
&SQLiteDriver{
|
|
|
|
ConnectHook: func(c *SQLiteConn) error {
|
|
|
|
conn = c
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
file := TempFilename(t)
|
|
|
|
defer os.Remove(file)
|
|
|
|
|
|
|
|
db, err := sql.Open("sqlite3_with_conn", "file:"+file+"?_auth&_auth_user=admin&_auth_pass=admin")
|
|
|
|
if err != nil {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
// Dummy query to force connection and database creation
|
|
|
|
// Will return ErrUnauthorized (SQLITE_AUTH) if user authentication fails
|
|
|
|
if _, err := db.Exec("SELECT 1;"); err != nil {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if conn.Authenticate("", ""); err != nil {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
if ok := conn.authenticate("", ""); ok != 0 {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if conn.AuthUserAdd("", "", true); err != nil {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
if ok := conn.authUserAdd("", "", 1); ok != 0 {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if conn.AuthUserChange("", "", true); err != nil {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
if ok := conn.authUserChange("", "", 1); ok != 0 {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if conn.AuthUserDelete(""); err != nil {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
if ok := conn.authUserDelete(""); ok != 0 {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
if enabled := conn.AuthEnabled(); enabled {
|
2018-07-22 23:32:19 +03:00
|
|
|
t.Fatal("UserAuthOmit failure")
|
2018-06-13 18:08:59 +03:00
|
|
|
}
|
|
|
|
}
|