drewww/unhangout — pull request #222 by yourcelf (2013-11-09 21:07:21+00:00)
Title: Multi user mocks (as well as the 3 other pull requests)

This pul requests implements multi-user authentication mocking. It also incorporates and resolves merge conflicts for the 3 other open pull requests from me (chatscroll, event-blur-bugfix, and email-logging). If we decide to skip any of those I'll need to change this; but if we want all three this one suffices. :)

Previously, auth mocking for tests worked by passing two options to the server ("mock-auth" and "mock-auth-admin"), which influenced a number of branches to change initialization and auth handling throughout the
server routine.

Replace all of this with a single "mockAuth" middleware, which is installed prior to all other authentication middleware, and looks for either an "x-mock-auth" HTTP header or "mock_auth" cookie in incoming
requests, which specifies a key for an authenticating user. This enables us to choose which user to mock-authenticate on a per-request basis. When using ``superagent`` or other raw HTTP requests, we can set
an HTTP header. When using selenium, we can execute javascript on the browser to set a cookie.

Since we now have multiple users, we can do away with the distinction between "standardSetup" and "mockSetup" with admin status -- when you want to mock an authenticated user, specify the header or cookie. When you want to mock an admin, just make sure the mock user is an admin (mock users are defined in lib/passport-mock). When you want unauthenticated requests, omit the header and cookie.