Skip to content

Instantly share code, notes, and snippets.

@berngp
Created July 18, 2012 23:29
Show Gist options
  • Save berngp/3139679 to your computer and use it in GitHub Desktop.
Save berngp/3139679 to your computer and use it in GitHub Desktop.
First stab on Integration Test mixing green-oauth-server and Twitter Oauth flow.
should = require 'should'
restify = require 'restify'
util = require 'util'
Browser = require 'zombie'
querys = require 'querystring'
OAuthClient = require './oauth-client'
class Specification extends OAuthClient
doTests: (clientFactory) -> ( ) =>
describe "Twitter OAuth Flow", (done) ->
it "should be able to assert that there is no session.", (done) ->
clientFactory().get "/1/oauth/sessions", ( err, req, res, data ) =>
res.statusCode.should.eql 404
request =
response_type : "token"
redirect_uri : "https://my.server.domain.com"
state : "a_stateVal=1&ya_stateVal=true"
clientFactory().post "/1/oauth/authorize/twitter", request, ( err, req, res, data ) =>
should.not.exist err
res.statusCode.should.eql 303
twitterAuthLocation = res.headers.location
twitterAuthLocation.should.be.ok
browser = new Browser()
browser.visit twitterAuthLocation, () =>
browser.fill("session[username_or_email]", "YourTwitterUsername")
browser.fill("session[password]", "Password-super-secret!!")
browser.pressButton( "Authorize app", () =>
browser.success.should.be.ok
browser.location.pathname.should.eql "/oauth/authorize"
[ callbackUrl, callbackQuery ] = (browser.query "a.maintain-context")?.href?.split "?" ? [ "", "" ]
callbackUrl.should.be.ok
callbackQuery.should.be.ok
clientFactory().get "/1/oauth/callback/twitter?#{callbackQuery}", ( err, req, res, data ) =>
should.not.exist err
res.statusCode.should.eql 303
done() )
module.exports = ( clientFactory ) ->
service = new Specification
service.doTests clientFactory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment