Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mysql/gcpmysql/gcpmysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (o *lazyCredsOpener) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB
o.opener = &URLOpener{CertSource: certSource}
})
if o.err != nil {
return nil, fmt.Errorf("gcpmysql open %v: %v", u, o.err)
return nil, fmt.Errorf("gcpmysql open %v: %v", u.Redacted(), o.err)
}
return o.opener.OpenMySQLURL(ctx, u)
}
Expand Down
17 changes: 17 additions & 0 deletions mysql/gcpmysql/gcpmysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,30 @@ import (
"fmt"
"net/url"
"reflect"
"strings"
"testing"

drvr "github.com/go-sql-driver/mysql"
"gocloud.dev/internal/testing/terraform"
"gocloud.dev/mysql"
)

func TestOpenMySQLURLDoesNotLeakPasswordOnCredentialsFailure(t *testing.T) {
const password = "S3cr3tDBPassw0rd"
u, err := url.Parse(fmt.Sprintf("gcpmysql://dbuser:%s@myproject/us-central1/myinstance/mydb", password))
if err != nil {
t.Fatalf("failed to parse URL: %v", err)
}
o := new(lazyCredsOpener)
_, err = o.OpenMySQLURL(context.Background(), u)
if err == nil {
t.Skip("Application Default Credentials are available in this environment; skipping negative-path test")
}
if strings.Contains(err.Error(), password) {
t.Errorf("OpenMySQLURL error contains the raw password: %q", err.Error())
}
}

func TestOpen(t *testing.T) {
// This test will be skipped unless the project is set up with Terraform.
// Before running go test, run in this directory:
Expand Down
Loading