MCPcopy
hub / github.com/go-sql-driver/mysql / TestUnixSocketAuthFail

Function TestUnixSocketAuthFail

driver_test.go:2160–2205  ·  driver_test.go::TestUnixSocketAuthFail
(t *testing.T)

Source from the content-addressed store, hash-verified

2158}
2159
2160func TestUnixSocketAuthFail(t *testing.T) {
2161 runTests(t, dsn, func(dbt *DBTest) {
2162 // Save the current logger so we can restore it.
2163 oldLogger := defaultLogger
2164
2165 // Set a new logger so we can capture its output.
2166 buffer := bytes.NewBuffer(make([]byte, 0, 64))
2167 newLogger := log.New(buffer, "prefix: ", 0)
2168 SetLogger(newLogger)
2169
2170 // Restore the logger.
2171 defer SetLogger(oldLogger)
2172
2173 // Make a new DSN that uses the MySQL socket file and a bad password, which
2174 // we can make by simply appending any character to the real password.
2175 badPass := pass + "x"
2176 socket := ""
2177 if prot == "unix" {
2178 socket = addr
2179 } else {
2180 // Get socket file from MySQL.
2181 err := dbt.db.QueryRow("SELECT @@socket").Scan(&socket)
2182 if err != nil {
2183 t.Fatalf("error on SELECT @@socket: %s", err.Error())
2184 }
2185 }
2186 t.Logf("socket: %s", socket)
2187 badDSN := fmt.Sprintf("%s:%s@unix(%s)/%s?timeout=30s", user, badPass, socket, dbname)
2188 db, err := sql.Open(driverNameTest, badDSN)
2189 if err != nil {
2190 t.Fatalf("error connecting: %s", err.Error())
2191 }
2192 defer db.Close()
2193
2194 // Connect to MySQL for real. This will cause an auth failure.
2195 err = db.Ping()
2196 if err == nil {
2197 t.Error("expected Ping() to return an error")
2198 }
2199
2200 // The driver should not log anything.
2201 if actual := buffer.String(); actual != "" {
2202 t.Errorf("expected no output, got %q", actual)
2203 }
2204 })
2205}
2206
2207// See Issue #422
2208func TestInterruptBySignal(t *testing.T) {

Callers

nothing calls this directly

Calls 8

runTestsFunction · 0.85
SetLoggerFunction · 0.85
ScanMethod · 0.80
OpenMethod · 0.80
PingMethod · 0.80
StringMethod · 0.80
ErrorMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected