Skip to content

Commit

Permalink
Merge pull request #132 from dgreisen/auth
Browse files Browse the repository at this point in the history
expose action.responded to authorize() function
  • Loading branch information
josephg committed Oct 21, 2012
2 parents 7b835a1 + a97be9d commit 7334263
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/server/useragent.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ module.exports = (model, options) ->
when 'delete' then 'delete'
else throw new Error "Invalid action name #{name}"

responded = false
action.responded = false
action.reject = ->
throw new Error 'Multiple accept/reject calls made' if responded
responded = true
throw new Error 'Multiple accept/reject calls made' if @responded
@responded = true
userCallback 'forbidden', null
action.accept = ->
throw new Error 'Multiple accept/reject calls made' if responded
responded = true
throw new Error 'Multiple accept/reject calls made' if @responded
@responded = true
acceptCallback()

auth this, action
Expand Down
18 changes: 18 additions & 0 deletions test/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,24 @@ genTests = (client) -> testCase
@model.applyOp @name, {op:[{i:'dD', p:3}], v:1, meta:{}}, =>
@model.getSnapshot @name, e

'If operation is rejected, action.responded == true': (test) ->
@auth = (client, action) ->
test.strictEqual action.responded, false
action.reject()
test.strictEqual action.responded, true
test.done()

client.open @name, 'text', "http://localhost:#{@port}/sjs", (error, doc) =>

'If operation is accepted, action.responded == true': (test) ->
@auth = (client, action) ->
test.strictEqual action.responded, false
action.accept()
test.strictEqual action.responded, true
test.done()

client.open @name, 'text', "http://localhost:#{@port}/sjs", (error, doc) =>

'Text API is advertised': (test) ->
@c.open @name, 'text', (error, doc) ->
test.strictEqual doc.provides?.text, true
Expand Down

0 comments on commit 7334263

Please sign in to comment.