Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #133 from dgreisen/auth2
Browse files Browse the repository at this point in the history
authenticate() can pass custom error message to client through reject(msg)
  • Loading branch information
wmertens committed Oct 23, 2012
2 parents 7334263 + 4498873 commit 4bd2896
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/useragent.coffee
Expand Up @@ -52,10 +52,10 @@ module.exports = (model, options) ->
else throw new Error "Invalid action name #{name}"

action.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
Expand Down
7 changes: 7 additions & 0 deletions test/client.coffee
Expand Up @@ -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) ->
Expand Down

0 comments on commit 4bd2896

Please sign in to comment.