Fix _auth_* parameter check

Fixes: #724
feature-pointer-callback
G.J.R. Timmer 2019-08-22 12:11:43 +02:00 committed by Gert-Jan Timmer
parent 2ea5857c0e
commit b22da71572
2 changed files with 27 additions and 3 deletions

View File

@ -1522,10 +1522,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
// Before going any further, we need to check that the user // Before going any further, we need to check that the user
// has provided an username and password within the DSN. // has provided an username and password within the DSN.
// We are not allowed to continue. // We are not allowed to continue.
if len(authUser) < 0 { if len(authUser) <= 0 {
return nil, fmt.Errorf("Missing '_auth_user' while user authentication was requested with '_auth'") return nil, fmt.Errorf("Missing '_auth_user' while user authentication was requested with '_auth'")
} }
if len(authPass) < 0 { if len(authPass) <= 0 {
return nil, fmt.Errorf("Missing '_auth_pass' while user authentication was requested with '_auth'") return nil, fmt.Errorf("Missing '_auth_pass' while user authentication was requested with '_auth'")
} }

View File

@ -60,7 +60,14 @@ func init() {
file = TempFilename(t) file = TempFilename(t)
} }
db, err = sql.Open("sqlite3_with_conn", "file:"+file+fmt.Sprintf("?_auth&_auth_user=%s&_auth_pass=%s", username, password)) params := "?_auth"
if len(username) > 0 {
params = fmt.Sprintf("%s&_auth_user=%s", params, username)
}
if len(password) > 0 {
params = fmt.Sprintf("%s&_auth_pass=%s", params, password)
}
db, err = sql.Open("sqlite3_with_conn", "file:"+file+params)
if err != nil { if err != nil {
defer os.Remove(file) defer os.Remove(file)
return file, nil, nil, err return file, nil, nil, err
@ -164,6 +171,23 @@ func TestUserAuthCreateDatabase(t *testing.T) {
} }
} }
func TestUserAuthCreateDatabaseWithoutArgs(t *testing.T) {
_, db, c, err := connect(t, "", "", "")
if err == nil && c == nil && db == nil {
t.Fatal("Should have failed due to missing _auth_* parameters")
}
_, db, c, err = connect(t, "", "", "admin")
if err == nil && c == nil && db == nil {
t.Fatal("Should have failed due to missing _auth_user parameter")
}
_, db, c, err = connect(t, "", "admin", "")
if err == nil && c == nil && db == nil {
t.Fatal("Should have failed due to missing _auth_pass parameter")
}
}
func TestUserAuthLogin(t *testing.T) { func TestUserAuthLogin(t *testing.T) {
f1, err := create(t, "admin", "admin") f1, err := create(t, "admin", "admin")
if err != nil { if err != nil {