summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/run_tests17
-rw-r--r--tests/white-box/couchdb.rb42
2 files changed, 32 insertions, 27 deletions
diff --git a/bin/run_tests b/bin/run_tests
index d7fc1e4c..2ee027f4 100755
--- a/bin/run_tests
+++ b/bin/run_tests
@@ -122,7 +122,7 @@ class LeapTest < MiniTest::Unit::TestCase
#
# attempts a http GET on the url, yields |body, response, error|
#
- def get(url, params=nil, options=nil)
+ def get(url, params=nil)
uri = URI(url)
if params
uri.query = URI.encode_www_form(params)
@@ -134,8 +134,8 @@ class LeapTest < MiniTest::Unit::TestCase
end
http.start do |agent|
request = Net::HTTP::Get.new uri.request_uri
- if options && options[:username]
- request.basic_auth options[:username], options[:password]
+ if uri.user
+ request.basic_auth uri.user, uri.password
end
response = agent.request(request)
if response.is_a?(Net::HTTPSuccess)
@@ -150,7 +150,7 @@ class LeapTest < MiniTest::Unit::TestCase
def assert_get(url, params=nil, options=nil)
options ||= {}
- get(url, params, options) do |body, response, error|
+ get(url, params) do |body, response, error|
if body
yield body if block_given?
elsif response
@@ -164,10 +164,11 @@ class LeapTest < MiniTest::Unit::TestCase
#
# only a warning for now, should be a failure in the future
#
- def assert_auth_fail(url, params, auth_options)
- get(url, params, auth_options) do |body, response, error|
- unless response.code == 401
- warn "Expected a '401 Unauthorized' response, but got #{response.code} instead (GET #{url} with username '#{auth_options[:username]}')."
+ def assert_auth_fail(url, params)
+ uri = URI(url)
+ get(url, params) do |body, response, error|
+ unless response.code.to_s == "401"
+ warn "Expected a '401 Unauthorized' response, but got #{response.code} instead (GET #{uri.request_uri} with username '#{uri.user}')."
return false
end
end
diff --git a/tests/white-box/couchdb.rb b/tests/white-box/couchdb.rb
index 8b9789bd..a6ad0f6a 100644
--- a/tests/white-box/couchdb.rb
+++ b/tests/white-box/couchdb.rb
@@ -33,7 +33,7 @@ class CouchDB < LeapTest
neighbors = assert_property('couch.bigcouch.neighbors')
neighbors << assert_property('domain.full')
neighbors.sort!
- assert_get(url, nil, http_basic_auth) do |body|
+ assert_get(url) do |body|
response = JSON.parse(body)
nodes_in_db = response['rows'].collect{|row| row['id'].sub(/^bigcouch@/, '')}.sort
assert_equal neighbors, nodes_in_db, "The couchdb replication node list is wrong (/nodes/_all_docs)"
@@ -48,8 +48,8 @@ class CouchDB < LeapTest
# this seems backward to me, so it might be the other way around.
#
def test_03_Are_configured_nodes_online?
- url = couchdb_url("/_membership")
- assert_get(url, nil, http_basic_auth) do |body|
+ url = couchdb_url("/_membership", :user => 'admin')
+ assert_get(url) do |body|
response = JSON.parse(body)
nodes_configured_but_not_available = response['cluster_nodes'] - response['all_nodes']
nodes_available_but_not_configured = response['all_nodes'] - response['cluster_nodes']
@@ -68,7 +68,7 @@ class CouchDB < LeapTest
def test_04_Do_ACL_users_exist?
acl_users = ['_design/_auth', 'leap_mx', 'nickserver', 'soledad', 'tapicero', 'webapp']
url = couchdb_backend_url("/_users/_all_docs")
- assert_get(url, nil, http_basic_auth) do |body|
+ assert_get(url) do |body|
response = JSON.parse(body)
assert_equal 6, response['total_rows']
actual_users = response['rows'].map{|row| row['id'].sub(/^org.couchdb.user:/, '') }
@@ -93,36 +93,40 @@ class CouchDB < LeapTest
#
def test_06_Is_ACL_enforced?
ok = assert_auth_fail(
- couchdb_url('/users/_all_docs'),
- {:limit => 1},
- http_basic_auth('leap_mx')
+ couchdb_url('/users/_all_docs', :user => 'leap_mx'),
+ {:limit => 1}
)
ok = assert_auth_fail(
- couchdb_url('/users/_all_docs'),
- {:limit => 1},
- {}
+ couchdb_url('/users/_all_docs', :user => 'leap_mx'),
+ {:limit => 1}
) && ok
pass if ok
end
+ def test_07_What?
+ pass
+ end
+
private
- def couchdb_url(path="", port=nil)
+ def couchdb_url(path="", options=nil)
+ options||={}
@port ||= begin
assert_property 'couch.port'
$node['couch']['port']
end
- "http://localhost:#{port || @port}#{path}"
+ url = 'http://'
+ if options[:user]
+ assert_property 'couch.users.' + options[:user]
+ password = $node['couch']['users'][options[:user]]['password']
+ url += "%s:%s@" % [options[:user], password]
+ end
+ url += "localhost:#{options[:port] || @port}#{path}"
+ url
end
def couchdb_backend_url(path="")
- couchdb_url(path, "5986") # TODO: admin port is hardcoded for now but should be configurable.
- end
-
- def http_basic_auth(username='admin')
- assert_property 'couch.users.' + username
- password = $node['couch']['users'][username]['password']
- {:username => username, :password => password}
+ couchdb_url(path, :port => "5986") # TODO: admin port is hardcoded for now but should be configurable.
end
end