parent
2ea5857c0e
commit
b22da71572
|
@ -1522,10 +1522,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
// Before going any further, we need to check that the user
|
||||
// has provided an username and password within the DSN.
|
||||
// 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'")
|
||||
}
|
||||
if len(authPass) < 0 {
|
||||
if len(authPass) <= 0 {
|
||||
return nil, fmt.Errorf("Missing '_auth_pass' while user authentication was requested with '_auth'")
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,14 @@ func init() {
|
|||
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 {
|
||||
defer os.Remove(file)
|
||||
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) {
|
||||
f1, err := create(t, "admin", "admin")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue