Skip to content

Commit

Permalink
set client authentication on initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Dec 13, 2013
1 parent 8daa667 commit 4c36b68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/neography/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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?
Expand Down
28 changes: 10 additions & 18 deletions spec/integration/authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]: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
Expand Down

0 comments on commit 4c36b68

Please sign in to comment.