mongodb/mongo-ruby-driver — pull request #461 by estolfo (2014-08-14 11:54:21+00:00)
Title: Rake task, functional and authentication test suite fixes for narrowed localhost exception

This PR has changes that make db#add_user work for 2.7 and that make all tests except for replica set and sharded cluster tests work with the new narrowed localhost exception.

The main idea is that before any tests run, an admin user is added to the admin database and then a URI constant(TEST_URI) is set up that each test will use to create a MongoClient.

The tests can then run without having to worry about authenticating themselves to the admin database.

The tests assume that:

1. TEST_URI provides a uri for a mongo client with an admin user already set up.
2. TEST_USER is an admin user on the admin database.
3. TEST_USER_PWD is the password for the admin user on the admin user database.

The test changes in this pull request can be categorized into three areas:

1. testing.rake and test_unit.rb changes: Both have a cleanup and ensure_admin_user hook. testing.rake will run these hooks when rake is used to run tests. The code had to be repeated in test_unit so that you could run tests individually. If you run tests just as 'ruby -I ./lib -I ./test test/../..' it would not run the rake test hooks and thus wouldn't set up the admin user. If anyone has a better idea of how I can avoid repeating this code, I'm open to hearing it...

2. Functional test suite changes: In order to preserve clean authentication on a client, I've changed all tests that create a global client object to use a test-specific client object from the TEST_URI. This avoids any complications between tests adding auth objects onto the client and not properly removing them. Other changes were necessary in the functional tests.

3. Authentication test changes: Because there is already an admin user set up in the database before any tests run, the authentication tests were simplified. The setup process doesn't need to add an admin user now and can get just create a client from the TEST_URI.

TODO:

1. Replica set and sharded cluster test fixes
2. Test sasl_plain and gssapi tests (the kdc is down right now)
3. Uncomment the tests in client_test that are failing due to RUBY-788
4. Figure out whey copy_db isn't working on 2.4