neo4jrb / neo4j-core

A simple unified API that can access both the server and embedded Neo4j database. Used by the neo4j gem
MIT License
99 stars 80 forks source link

`Invalid URL:` error on SSL urls when not using bundler #305

Closed simpsonjulian closed 6 years ago

simpsonjulian commented 6 years ago

I wrote an app. Running migrations locally worked very well (rake neo4j:migrate) etc (nice to have migrations in a driver, BTW). Nothing blew up so I carried on coding.

Went to deploy on a production system with an SSL cert, and I started getting Invalid URL messages.

Can't get to the bottom of it, but I noticed that it's only when I'm running without bundler (which I got sloppy about because it worked on the local Neo4j server).

require 'neo4j/session_manager'
require 'uri/http' # it also blew up complaining about this
task :default do
  puts "neo4j-core version: #{Neo4j::Core::VERSION}"
  puts "neo4j version: #{Neo4j::VERSION}"

  neo4j_url = "https://neo4j:sekretpassword@db.myawesomeapp.com/"

  Neo4j::ActiveBase.on_establish_session do
    Neo4j::SessionManager.open_neo4j_session(:http, neo4j_url)
  end

  Neo4j::ActiveBase.current_session.query("match (n) return n")
end

Running without bundler:

neo4j-core version: 8.0.1
neo4j version: 9.0.5
rake aborted!
ArgumentError: Invalid URL: "https://neo4j:sekretpassword@db.myawesomeapp.com/"
/Users/jsimpson/Documents/workspace/org/project/neo4j_urls.rake:11:in `block (2 levels) in <top (required)>'
/Users/jsimpson/Documents/workspace/org/project/neo4j_urls.rake:14:in `block in <top (required)>'
Tasks: TOP => default
(See full trace by running task with --trace)

Running with bundler:

computer:project jsimpson$ bundle exec rake -f neo4j_urls.rake
neo4j-core version: 8.0.1
neo4j version: 9.0.5
rake aborted!
Neo4j::Core::CypherSession::ConnectionFailedError: Faraday::ConnectionFailed: Couldn't resolve host name
/Users/jsimpson/Documents/workspace/neo-technology/intranet/neo4j_urls.rake:14:in `block in <top (required)>'
/Users/jsimpson/.rbenv/versions/2.2.4/bin/bundle:23:in `load'
/Users/jsimpson/.rbenv/versions/2.2.4/bin/bundle:23:in `<main>'

At first I assumed that I had different gem versions in system.

It would be better for first time users who make the same mistake to get an error like "Use bundler to make sure your dependencies work" rather than the first error (which I went down the rabbit hole on).

cheerfulstoic commented 6 years ago

Hey @simpsonjulian

Thanks for the report. I think this could actually be fixed if we put a require 'uri' at the top of this file:

https://github.com/neo4jrb/neo4j-core/blob/master/lib/neo4j/core/cypher_session/adaptors/http.rb

(mainly putting that info there to remind myself when I come back to this issue ;) )

Does it work without bundler if you put require 'uri' at the top of your code?

Explination: On this line we check to see if the URI (gotten by calling URI(url) with the given URL) is URI::HTTP. If you only require uri/http it doesn't work because it's an https schema (you need to require 'uri/https`` specifically orrequire 'uri'` to get everything).

simpsonjulian commented 6 years ago

Hi Brian, you're correct: that did make the issue disappear. I made a PR for you. Cheers!