diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index b7e4faa..c6268d4 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -18,6 +18,7 @@ def initialize(options = ENV['NEO4J_URL'] || {}) @client = HTTPClient.new @client.send_timeout = 1200 # 10 minutes @client.receive_timeout = 1200 + authenticate end def configure(protocol, server, port, directory) @@ -42,7 +43,6 @@ def merge_options(options) define_method(action) do |path, options = {}| query_path = configuration + path query_body = merge_options(options)[:body] - authenticate(query_path) log path, query_body do evaluate_response(@client.send(action.to_sym, query_path, query_body, merge_options(options)[:headers])) end @@ -61,7 +61,7 @@ def log(path, body) end end - def authenticate(path) + def authenticate(path = nil) @client.set_auth(path, @authentication[@authentication.keys.first][:username], @authentication[@authentication.keys.first][:password]) unless @authentication.empty? diff --git a/spec/integration/authorization_spec.rb b/spec/integration/authorization_spec.rb index 6129d01..edee976 100644 --- a/spec/integration/authorization_spec.rb +++ b/spec/integration/authorization_spec.rb @@ -2,43 +2,35 @@ describe Neography::Rest, :slow => true do describe "basic authentication" do - describe "get_root" do + describe "get_root", :reference => true do it "can get the root node"do - @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"}) + @neo = Neography::Rest.new({:authentication => 'digest', :username => "username", :password => "password"}) root_node = @neo.get_root root_node.should have_key("reference_node") end - end - + end + describe "create_node" do it "can create an empty node" do - @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'basic', :username => "abbe3c012", :password => "34d7b22eb"}) + @neo = Neography::Rest.new({:authentication => 'basic', :username => "username", :password => "password"}) new_node = @neo.create_node new_node.should_not be_nil end end describe "quick initializer" do - it "can get the root node" do - @neo = Neography::Rest.new("http://abbe3c012:34d7b22eb@4c36b641.neo4j.atns.de:7474/9dc1fda5be8b5cde29621e21cae5adece3de0f37") - root_node = @neo.get_root - root_node.should have_key("reference_node") + it "can create an empty node" do + @neo = Neography::Rest.new("http://username:password@localhost:7474") + new_node = @neo.create_node + new_node.should_not be_nil end end end describe "digest authentication" do - describe "get_root" do - it "can get the root node" do - @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"}) - root_node = @neo.get_root - root_node.should have_key("reference_node") - end - end - describe "create_node" do it "can create an empty node" do - @neo = Neography::Rest.new({:server => '4c36b641.neo4j.atns.de', :port => 7474, :directory => '/9dc1fda5be8b5cde29621e21cae5adece3de0f37', :authentication => 'digest', :username => "abbe3c012", :password => "34d7b22eb"}) + @neo = Neography::Rest.new({:authentication => 'digest', :username => "username", :password => "password"}) new_node = @neo.create_node new_node.should_not be_nil end