 				cb()
 	], callback
 
-expect_read_access = (requester, project_id, callback) ->
-	try_read_access(requester, project_id, (response, body) ->
-		if response.statusCode not in [200,204]
-			console.log response.statusCode, response.headers
+try_content_access = (user, project_id, test, callback) ->
+	# The real-time service calls this end point to determine the user's 
+	# permissions.
+	request.post {
+		url: "/project/#{project_id}/join"
+		qs: {user_id: user.id}
+		auth:
+			user: settings.apis.web.user
+			pass: settings.apis.web.pass
+			sendImmediately: true
+		json: true
+		jar: false
+	}, (error, response, body) ->
+		return callback(error) if error?
+		test(response, body)
+		callback()
+
+expect_read_access = (user, project_id, callback) ->
+	async.series [
+		(cb) ->
+			try_read_access(user, project_id, (response, body) ->
+				expect(response.statusCode).to.be.oneOf [200, 204]
+			, cb)
+		(cb) ->
+			try_content_access(user, project_id, (response, body) ->
+				expect(body.privilegeLevel).to.be.oneOf ["owner", "readAndWrite", "readOnly"]
+			, cb)
+	], callback
+
+expect_content_write_access = (user, project_id, callback) ->
+	try_content_access(user, project_id, (response, body) ->
+		expect(body.privilegeLevel).to.be.oneOf ["owner", "readAndWrite"]
+	, callback)
+
+expect_settings_write_access = (user, project_id, callback) ->
+	try_settings_write_access(user, project_id, (response, body) ->
 		expect(response.statusCode).to.be.oneOf [200, 204]
 	, callback)
 
-expect_settings_write_access = (requester, project_id, callback) ->
-	try_settings_write_access(requester, project_id, (response, body) ->
+expect_admin_access = (user, project_id, callback) ->
+	try_admin_access(user, project_id, (response, body) ->
 		expect(response.statusCode).to.be.oneOf [200, 204]
 	, callback)
 
-expect_admin_access = (requester, project_id, callback) ->
-	try_admin_access(requester, project_id, (response, body) ->
-		expect(response.statusCode).to.be.oneOf [200, 204]
-	, callback)
-
-expect_no_read_access = (requester, project_id, options, callback) ->
-	try_read_access(requester, project_id, (response, body) ->
+expect_no_read_access = (user, project_id, options, callback) ->
+	async.series [
+		(cb) ->
+			try_read_access(user, project_id, (response, body) ->
+				expect(response.statusCode).to.equal 302
+				expect(response.headers.location).to.match new RegExp(options.redirect_to)
+			, cb)
+		(cb) ->
+			try_content_access(user, project_id, (response, body) ->
+				expect(body.privilegeLevel).to.be.equal false
+			, cb)
+	], callback
+
+expect_no_content_write_access = (user, project_id, callback) ->
+	try_content_access(user, project_id, (response, body) ->
+		expect(body.privilegeLevel).to.be.oneOf [false, "readOnly"]
+	, callback)
+
+expect_no_settings_write_access = (user, project_id, options, callback) ->
+	try_settings_write_access(user, project_id, (response, body) ->
 		expect(response.statusCode).to.equal 302
-		expect(response.headers.location).to.equal options.redirect_to
-	, callback)
-
-expect_no_settings_write_access = (requester, project_id, options, callback) ->
-	try_settings_write_access(requester, project_id, (response, body) ->
+		expect(response.headers.location).to.match new RegExp(options.redirect_to)
+	, callback)
+
+expect_no_admin_access = (user, project_id, options, callback) ->
+	try_admin_access(user, project_id, (response, body) ->
 		expect(response.statusCode).to.equal 302
-		expect(response.headers.location).to.equal options.redirect_to
-	, callback)
-
-expect_no_admin_access = (requester, project_id, options, callback) ->
-	try_admin_access(requester, project_id, (response, body) ->
-		expect(response.statusCode).to.equal 302
-		expect(response.headers.location).to.equal options.redirect_to
+		expect(response.headers.location).to.match new RegExp(options.redirect_to)
 	, callback)
 
 describe "Authorization", ->

request = require("request")
expect = require("chai").expect
async = require "async"

count = 0
BASE_URL = "http://localhost:3000"

			})
			callback()

try_read_access = (user, project_id, test, callback) ->
	async.parallel [
		(cb) ->
			user.request.get "/project/#{project_id}", (error, response, body) ->
				return cb(error) if error?
				test(response, body)
				cb()
		(cb) ->
			user.request.get "/project/#{project_id}/download/zip", (error, response, body) ->
				return cb(error) if error?
				test(response, body)
				cb()
	], callback

try_settings_write_access = (user, project_id, test, callback) ->
	async.parallel [
		(cb) ->
			user.request.post {
				uri: "/project/#{project_id}/settings"
				json:
					compiler: "latex"
