diff --git a/lib/cartodb/central.rb b/lib/cartodb/central.rb index c1627d0f53..05c89480c4 100644 --- a/lib/cartodb/central.rb +++ b/lib/cartodb/central.rb @@ -19,11 +19,10 @@ module Cartodb def build_request(path, body, method, timeout = 200) Typhoeus::Request.new( - "#{@host}/#{path}", + "#{ @host }/#{ path }", method: method, body: body.to_json, - username: @auth['username'], - password: @auth['password'], + userpwd: "#{ @auth[:username] }:#{ @auth[:password] }", headers: { "Content-Type" => "application/json" }, ssl_verifypeer: Rails.env.production?, timeout: timeout diff --git a/spec/lib/central_spec.rb b/spec/lib/central_spec.rb index 3543999afe..23cd10490f 100644 --- a/spec/lib/central_spec.rb +++ b/spec/lib/central_spec.rb @@ -1,10 +1,19 @@ require 'spec_helper' require_relative '../../lib/cartodb/central' +def config + Cartodb.config[:cartodb_central_api].deep_symbolize_keys +end + def config_present? - Cartodb.config[:cartodb_central_api].present? && - Cartodb.config[:cartodb_central_api]['username'].present? && - Cartodb.config[:cartodb_central_api]['password'].present? + config.present? && + config[:username].present? && + config[:password].present? +end + +def assert_headers_and_auth(request) + request.options[:headers]["Content-Type"].should == "application/json" + request.options[:userpwd].should == "#{ config[:username] }:#{ config[:password] }" end describe Cartodb::Central do @@ -35,10 +44,18 @@ describe Cartodb::Central do describe "Organization users" do it "gets all users from an organization" do request = @cartodb_central_client.build_request(@users_path, nil, :get) + + request.url.should == "#{ @cartodb_central_client.host }/#{ @users_path }" + request.options[:method].should == :get + assert_headers_and_auth(request) end it "gets an organization user" do request = @cartodb_central_client.build_request(@user_path, nil, :get) + + request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }" + request.options[:method].should == :get + assert_headers_and_auth(request) end it "creates an organization user" do @@ -47,9 +64,9 @@ describe Cartodb::Central do request = @cartodb_central_client.build_request(@user_path, body, :post) request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }" - request.options[:headers]["Content-Type"].should == "application/json" request.options[:method].should == :post request.options[:body].should == { user: @user.allowed_attributes_to_central(:create) }.to_json + assert_headers_and_auth(request) end it "updates an organization user" do @@ -58,17 +75,17 @@ describe Cartodb::Central do request = @cartodb_central_client.build_request(@user_path, body, :put) request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }" - request.options[:headers]["Content-Type"].should == "application/json" request.options[:method].should == :put request.options[:body].should == { user: @user.allowed_attributes_to_central(:update) }.to_json + assert_headers_and_auth(request) end it "deletes an organization user" do request = @cartodb_central_client.build_request(@user_path, nil, :delete) request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }" - request.options[:headers]["Content-Type"].should == "application/json" request.options[:method].should == :delete + assert_headers_and_auth(request) end end