Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

expose action.responded to authorize() function #132

Merged
merged 1 commit into from

2 participants

@dgreisen

responded was a private variable used for determining if the authorize()
function had called action.accept() or action.reject().

responded has been made a public attribute of the action object so the
authorize function can check to see whether it has called accept() or
reject(). This is useful for complex control flows.

tests included

@dgreisen dgreisen exposed action.responded to authorize() function
responded was a private variable used for determining if the authorize()
function had called action.accept() or action.reject().

responded has been made a public attribute of the action object so the
authorize function can check to see whether it has called accept() or
reject(). This is useful for complex control flows.
a97be9d
@josephg
Owner

Nice change.

@josephg josephg merged commit 7334263 into share:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 20, 2012
  1. @dgreisen

    exposed action.responded to authorize() function

    dgreisen authored
    responded was a private variable used for determining if the authorize()
    function had called action.accept() or action.reject().
    
    responded has been made a public attribute of the action object so the
    authorize function can check to see whether it has called accept() or
    reject(). This is useful for complex control flows.
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 5 deletions.
  1. +5 −5 src/server/useragent.coffee
  2. +18 −0 test/client.coffee
View
10 src/server/useragent.coffee
@@ -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
View
18 test/client.coffee
@@ -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
Something went wrong with that request. Please try again.