Skip to content

Commit

Permalink
Merge dd0135f into 2ea5857
Browse files Browse the repository at this point in the history
  • Loading branch information
gjrtimmer committed Aug 22, 2019
2 parents 2ea5857 + dd0135f commit a235219
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sqlite3.go
Expand Up @@ -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'")
}

Expand Down
26 changes: 25 additions & 1 deletion sqlite3_opt_userauth_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a235219

Please sign in to comment.