mongodb/mongo-ruby-driver — pull request #462 by estolfo (2014-08-15 15:10:22+00:00)
Title: Rake task, functional and authentication test suite fixes for narrowed localhost exception

I had to redo a lot of this when I started working on the replica set test suite fixes. I deleted a bunch of duplication and I think I'm doing it right this time.

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:

TEST_URI provides a uri for a mongo client with an admin user already set up.
TEST_USER is an admin user on the admin database.
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:

TestUnit has a #at_start and a #at_exit method that will ensure that there is an admin user in the db and clean it up after the test(s) run.

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.

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:

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