Skip to content
Browse files

Adding a test for the refresh_token grant type support

  • Loading branch information...
1 parent 64b2487 commit c631a315037d463952573bbdf66a7d40421b104e @ciaranj committed
Showing with 30 additions and 2 deletions.
  1. +30 −2 tests/oauth2.js
View
32 tests/oauth2.js
@@ -3,8 +3,9 @@ var vows = require('vows'),
OAuth2= require('../lib/oauth2').OAuth2;
vows.describe('OAuth2').addBatch({
- 'When handling the access token response': {
- topic: new OAuth2(),
+ 'Given an OAuth2 instance, ': {
+ topic: new OAuth2(),
+ 'When handling the access token response': {
'we should correctly extract the token if received as form-data': function (oa) {
oa._request= function( method, url, fo, bar, bleh, callback) {
callback(null, "access_token=access&refresh_token=refresh");
@@ -35,5 +36,32 @@ vows.describe('OAuth2').addBatch({
assert.equal( results.extra_2, "foo");
});
}
+ },
+ 'When no grant_type parameter is specified': {
+ 'we should pass the value of the code argument as the code parameter': function(oa) {
+ oa._request= function(method, url, headers, post_body, access_token, callback) {
+ assert.isTrue( post_body.indexOf("code=xsds23") != -1 )
+ }
+ oa.getOAuthAccessToken("xsds23", {} );
+ }
+ },
+ 'When an invalid grant_type parameter is specified': {
+ 'we should pass the value of the code argument as the code parameter': function(oa) {
+ oa._request= function(method, url, headers, post_body, access_token, callback) {
+ assert.isTrue( post_body.indexOf("code=xsds23") != -1 )
+ }
+ oa.getOAuthAccessToken("xsds23", {grant_type:"refresh_toucan"} );
+ }
+ },
+ 'When a grant_type parameter of value "refresh_token" is specified': {
+ 'we should pass the value of the code argument as the refresh_token parameter, should pass a grant_type parameter, but shouldn\'t pass a code parameter' : function(oa) {
+ oa._request= function(method, url, headers, post_body, access_token, callback) {
+ assert.isTrue( post_body.indexOf("refresh_token=sdsds2") != -1 )
+ assert.isTrue( post_body.indexOf("grant_type=refresh_token") != -1 )
+ assert.isTrue( post_body.indexOf("code=") == -1 )
+ }
+ oa.getOAuthAccessToken("sdsds2", {grant_type:"refresh_token"} );
+ }
+ }
}
}).export(module);

0 comments on commit c631a31

Please sign in to comment.
Something went wrong with that request. Please try again.