package db import ( "context" "strings" "testing" ) func TestMySQLRejectsUnsafeConfiguration(t *testing.T) { for _, dsn := range []string{"", "private-secret@bad", "u:private-secret@tcp(localhost:3306)/pages", "u:p@tcp(localhost:3306)/pages?tls=skip-verify", "u:p@tcp(localhost:3306)/pages?tls=preferred", "u:p@tcp(localhost:3306)/pages?tls=true&multiStatements=true", "u:p@tcp(localhost:3306)/pages?tls=true&allowAllFiles=true", "u:p@tcp(localhost:3306)/pages?tls=true&sql_mode=bad"} { connection, err := OpenMySQL(context.Background(), MySQLOptions{DSN: dsn}) if connection != nil { connection.Close() t.Fatal("unexpected connection") } if err == nil || strings.Contains(err.Error(), "private-secret") { t.Fatalf("configuration not safely rejected: %v", err) } } }