Database connection success even with wrong credential

I tried both v4 and v5 version of the driver but the connection succeeded even while I provided wrong credential:

driver, err := neo4j.NewDriverWithContext(uri, neo4j.BasicAuth("wrongusername", "wrongpassword", ""))
if err != nil {
  fmt.Println("Error")
}
fmt.Println("connection success") // This is being logged.

Note: connection success is being logged when I run the application even without running database graph and even when fully quitted.

I only get connection error when I define wrong uri.

Debug:

uri = "random" // Error; OK
uri = "neo4j://100.0.0.0" // Success; Wrong; 100.0.0.0 is random number not host address
uri = "neo4j://random.com" // Success; Wrong; Not a neo4j host

You can check it here.

Hello,

side note first: your program does not terminate after fmt.Println("Error") and will therefore print "connection success" as well. You are missing a return or panic in your if err != nil condition.

Moreover, no connectivity occurs when you call NewDriverWithContext.
If you want to check for connectivity early, you need to call driver.VerifyConnectivity.
Then and only then, the URI and credentials will be exercised.

See the updated example: Go Playground - The Go Programming Language

EDIT: clarified the docs, hopefully, that will help future users as well: Mention NewDriverWithContext does not exercise URI/credentials by fbiville · Pull Request #483 · neo4j/neo4j-go-driver · GitHub

2 Likes

Ah, thank you for VerifyConnectivity that I need :)

But still error never appears on this line:

driver, err := neo4j.NewDriverWithContext(uri, neo4j.BasicAuth("wrongusername", "wrongpassword", ""))
if err != nil {
  // no error occurs
}

Yep, as I said earlier, no connectivity happens there.
The only kind of errors to show up with NewDriverWithContext is when the passed in URL is invalid.

1 Like