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
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.
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.