@@ -77,6 +77,67 @@ vows.describe('ConsumerStrategy').addBatch({
7777 } ,
7878 } ,
7979
80+ 'strategy handling a valid request without a request token using host option instead of host header' : {
81+ topic : function ( ) {
82+ var strategy = new ConsumerStrategy (
83+ { host : '127.0.0.1:3000' } ,
84+ // consumer callback
85+ function ( consumerKey , done ) {
86+ if ( consumerKey == 'abc123' ) {
87+ done ( null , { id : '1' } , 'ssh-secret' ) ;
88+ } else {
89+ done ( new Error ( 'something is wrong' ) )
90+ }
91+ } ,
92+ // token callback
93+ function ( requestToken , done ) {
94+ done ( new Error ( 'token callback should not be called' ) ) ;
95+ }
96+ ) ;
97+ return strategy ;
98+ } ,
99+
100+ 'after augmenting with actions' : {
101+ topic : function ( strategy ) {
102+ var self = this ;
103+ var req = { } ;
104+ strategy . success = function ( user , info ) {
105+ self . callback ( null , user , info ) ;
106+ }
107+ strategy . fail = function ( challenge , status ) {
108+ self . callback ( new Error ( 'should not be called' ) ) ;
109+ }
110+ strategy . error = function ( err ) {
111+ self . callback ( new Error ( 'should not be called' ) ) ;
112+ }
113+
114+ req . url = '/oauth/request_token' ;
115+ req . method = 'POST' ;
116+ req . headers = { } ;
117+ //req.headers['host'] = '127.0.0.1:3000';
118+ req . headers [ 'authorization' ] = 'OAuth oauth_callback="http%3A%2F%2Fmacbook-air.local.jaredhanson.net%3A3001%2Foauth%2Fcallback",oauth_consumer_key="abc123",oauth_nonce="fNyKdt8ZTgTVdEABtUMFzcXRxF4a230q",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1341176111",oauth_version="1.0",oauth_signature="tgsFsPL%2BDDQmfEz6hbCywhO%2BrE4%3D"' ;
119+ req . query = url . parse ( req . url , true ) . query ;
120+ req . connection = { encrypted : false } ;
121+ process . nextTick ( function ( ) {
122+ strategy . authenticate ( req ) ;
123+ } ) ;
124+ } ,
125+
126+ 'should not generate an error' : function ( err , user , info ) {
127+ assert . isNull ( err ) ;
128+ } ,
129+ 'should authenticate' : function ( err , user , info ) {
130+ assert . equal ( user . id , '1' ) ;
131+ } ,
132+ 'should set scheme to OAuth' : function ( err , user , info ) {
133+ assert . equal ( info . scheme , 'OAuth' ) ;
134+ } ,
135+ 'should set callbackURL' : function ( err , user , info ) {
136+ assert . equal ( info . oauth . callbackURL , 'http://macbook-air.local.jaredhanson.net:3001/oauth/callback' ) ;
137+ } ,
138+ } ,
139+ } ,
140+
80141 'strategy handling a valid request without a request token using PLAINTEXT signature' : {
81142 topic : function ( ) {
82143 var strategy = new ConsumerStrategy (
@@ -699,6 +760,72 @@ vows.describe('ConsumerStrategy').addBatch({
699760 } ,
700761 } ,
701762
763+ 'strategy handling a valid request with a request token using host option instead of host header' : {
764+ topic : function ( ) {
765+ var strategy = new ConsumerStrategy (
766+ { host : '127.0.0.1:3000' } ,
767+ // consumer callback
768+ function ( consumerKey , done ) {
769+ if ( consumerKey == 'abc123' ) {
770+ done ( null , { id : '1' } , 'ssh-secret' ) ;
771+ } else {
772+ done ( new Error ( 'something is wrong' ) )
773+ }
774+ } ,
775+ // token callback
776+ function ( requestToken , done ) {
777+ if ( requestToken == 'wM9YRRm5' ) {
778+ done ( null , 'rxt0E5hKbslOEtzxD43hclL28XBZLJsF' ) ;
779+ } else {
780+ done ( new Error ( 'something is wrong' ) )
781+ }
782+ }
783+ ) ;
784+ return strategy ;
785+ } ,
786+
787+ 'after augmenting with actions' : {
788+ topic : function ( strategy ) {
789+ var self = this ;
790+ var req = { } ;
791+ strategy . success = function ( user , info ) {
792+ self . callback ( null , user , info ) ;
793+ }
794+ strategy . fail = function ( challenge , status ) {
795+ self . callback ( new Error ( 'should not be called' ) ) ;
796+ }
797+ strategy . error = function ( err ) {
798+ self . callback ( new Error ( 'should not be called' ) ) ;
799+ }
800+
801+ req . url = '/oauth/access_token' ;
802+ req . method = 'POST' ;
803+ req . headers = { } ;
804+ //req.headers['host'] = '127.0.0.1:3000';
805+ req . headers [ 'authorization' ] = 'OAuth oauth_consumer_key="abc123",oauth_nonce="KyEf2M5ptWGDcz04jMScA2iJHkXHzkUW",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1341178687",oauth_token="wM9YRRm5",oauth_verifier="qriPjOnc",oauth_version="1.0",oauth_signature="ZP5%2FtXZcUiiD2HXKrevCL5FjY%2FM%3D"' ;
806+ req . query = url . parse ( req . url , true ) . query ;
807+ req . connection = { encrypted : false } ;
808+ process . nextTick ( function ( ) {
809+ strategy . authenticate ( req ) ;
810+ } ) ;
811+ } ,
812+
813+ 'should not generate an error' : function ( err , user , info ) {
814+ assert . isNull ( err ) ;
815+ } ,
816+ 'should authenticate' : function ( err , user , info ) {
817+ assert . equal ( user . id , '1' ) ;
818+ } ,
819+ 'should set scheme to OAuth' : function ( err , user , info ) {
820+ assert . equal ( info . scheme , 'OAuth' ) ;
821+ } ,
822+ 'should include token and verifier' : function ( err , user , info ) {
823+ assert . equal ( info . oauth . token , 'wM9YRRm5' ) ;
824+ assert . equal ( info . oauth . verifier , 'qriPjOnc' ) ;
825+ } ,
826+ } ,
827+ } ,
828+
702829 'strategy handling a valid request with a request token using PLAINTEXT signature' : {
703830 topic : function ( ) {
704831 var strategy = new ConsumerStrategy (
0 commit comments