From b2a3f15355a23f242d2ee5247c0787c9b3acaf2c Mon Sep 17 00:00:00 2001 From: David Greisen Date: Sat, 20 Oct 2012 20:49:05 -0400 Subject: [PATCH] authenticate() can pass error message to client through reject(msg) Now the authenticate() function can pass a custom error message to the client by providing the message in action.reject(msg). originally, rejection resulted in an unchangeable and not particularly useful "forbidden" error. includes tests --- src/server/useragent.coffee | 4 ++-- test/client.coffee | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server/useragent.coffee b/src/server/useragent.coffee index 8f53fd8b..f740f982 100644 --- a/src/server/useragent.coffee +++ b/src/server/useragent.coffee @@ -52,10 +52,10 @@ module.exports = (model, options) -> else throw new Error "Invalid action name #{name}" responded = false - action.reject = -> + action.reject = (message='forbidden') -> throw new Error 'Multiple accept/reject calls made' if responded responded = true - userCallback 'forbidden', null + userCallback message, null action.accept = -> throw new Error 'Multiple accept/reject calls made' if responded responded = true diff --git a/test/client.coffee b/test/client.coffee index 4987158b..4e824742 100644 --- a/test/client.coffee +++ b/test/client.coffee @@ -378,6 +378,13 @@ genTests = (client) -> testCase doc.insert 0, 'hi' + 'error message passed to reject is the error passed to client': (test) -> + @auth = (client, action) -> action.reject('not allowed') + + client.open @name, 'text', "http://localhost:#{@port}/sjs", (error, doc) => + test.strictEqual error, 'not allowed' + test.done() + 'If auth rejects your op, other transforms work correctly': (test) -> # This should probably have a randomized tester as well. @auth = (client, action) ->