@@ -82,6 +82,71 @@ vows.describe('TokenStrategy').addBatch({
8282 } ,
8383 } ,
8484
85+ 'strategy handling a valid request with credentials with spaces in header' : {
86+ topic : function ( ) {
87+ var strategy = new TokenStrategy (
88+ // consumer callback
89+ function ( consumerKey , done ) {
90+ if ( consumerKey == '1234' ) {
91+ done ( null , { id : '1' } , 'keep-this-secret' ) ;
92+ } else {
93+ done ( new Error ( 'something is wrong' ) )
94+ }
95+ } ,
96+ // verify callback
97+ function ( accessToken , done ) {
98+ if ( accessToken == 'abc-123-xyz-789' ) {
99+ done ( null , { username : 'bob' } , 'lips-zipped' ) ;
100+ } else {
101+ done ( new Error ( 'something is wrong' ) )
102+ }
103+ }
104+ ) ;
105+ return strategy ;
106+ } ,
107+
108+ 'after augmenting with actions' : {
109+ topic : function ( strategy ) {
110+ var self = this ;
111+ var req = { } ;
112+ strategy . success = function ( user , info ) {
113+ self . callback ( null , user , info ) ;
114+ }
115+ strategy . fail = function ( challenge , status ) {
116+ self . callback ( new Error ( 'should not be called' ) ) ;
117+ }
118+ strategy . error = function ( err ) {
119+ self . callback ( new Error ( 'should not be called' ) ) ;
120+ }
121+
122+ req . url = '/1/users/show.json?screen_name=jaredhanson&user_id=1705' ;
123+ req . method = 'GET' ;
124+ req . headers = { } ;
125+ req . headers [ 'host' ] = '127.0.0.1:3000' ;
126+ req . headers [ 'authorization' ] = 'OAuth oauth_consumer_key="1234", oauth_nonce="A7E738D9A9684A60A40607017735ADAD", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1339004912", oauth_token="abc-123-xyz-789", oauth_version="1.0", oauth_signature="TBrJJJWS896yWrbklSbhEd9MGQc%3D"' ;
127+ req . query = url . parse ( req . url , true ) . query ;
128+ req . connection = { encrypted : false } ;
129+ process . nextTick ( function ( ) {
130+ strategy . authenticate ( req ) ;
131+ } ) ;
132+ } ,
133+
134+ 'should not generate an error' : function ( err , user , info ) {
135+ assert . isNull ( err ) ;
136+ } ,
137+ 'should authenticate' : function ( err , user , info ) {
138+ assert . equal ( user . username , 'bob' ) ;
139+ } ,
140+ 'should set scheme to OAuth' : function ( err , user , info ) {
141+ assert . equal ( info . scheme , 'OAuth' ) ;
142+ } ,
143+ 'should set consumer' : function ( err , user , info ) {
144+ assert . equal ( info . consumer . id , '1' ) ;
145+ assert . strictEqual ( info . client , info . consumer ) ;
146+ } ,
147+ } ,
148+ } ,
149+
85150 'strategy handling a valid request using host option instead of host header' : {
86151 topic : function ( ) {
87152 var strategy = new TokenStrategy (
0 commit comments