forked from lelylan/simple-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8a5361
commit fc8e70d
Showing
7 changed files
with
130 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// A NodeJS module to handle OAuth2 server errors. | ||
// | ||
module.exports = function() { | ||
|
||
// Personalized errror | ||
function HTTPError(status) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = this.constructor.name; | ||
this.message = { status: status, message: statusCodes[status] }; | ||
} HTTPError.prototype.__proto__ = Error.prototype; | ||
|
||
|
||
// List of all 4xx and 5xx status code plus their description | ||
var statusCodes = { | ||
400: "Bad Request", | ||
401: "Unauthorized", | ||
402: "Payment Required", | ||
403: "Forbidden", | ||
404: "Not Found", | ||
405: "Method Not Allowed", | ||
406: "Not Acceptable", | ||
407: "Proxy Authentication Required", | ||
408: "Request Timeout", | ||
409: "Conflict", | ||
410: "Gone", | ||
411: "Length Required", | ||
412: "Precondition Failed", | ||
413: "Request Entity Too Large", | ||
414: "Request-URI Too Long", | ||
415: "Unsupported Media Type", | ||
416: "Requested Range Not Satisfiable", | ||
417: "Expectation Failed", | ||
420: "Enhance Your Calm", | ||
422: "Unprocessable Entity", | ||
423: "Locked", | ||
424: "Failed Dependency", | ||
425: "Unordered Collection", | ||
426: "Upgrade Required", | ||
428: "Precondition Required", | ||
429: "Too Many Requests", | ||
431: "Request Header Fields Too Large", | ||
444: "No Response", | ||
449: "Retry With", | ||
499: "Client Closed Request", | ||
500: "Internal Server Error", | ||
501: "Not Implemented", | ||
502: "Bad Gateway", | ||
503: "Service Unavailable", | ||
504: "Gateway Timeout", | ||
505: "HTTP Version Not Supported", | ||
506: "Variant Also Negotiates", | ||
507: "Insufficient Storage", | ||
508: "Loop Detected", | ||
509: "Bandwidth Limit Exceeded", | ||
510: "Not Extended", | ||
511: "Network Authentication Required" | ||
}; | ||
|
||
|
||
return { | ||
'HTTPError': HTTPError | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,58 @@ | ||
//var Lelylan = require('./../lib/lelylan-node.js')({ 'token': '5f7fb8f11b8499b' }); | ||
//var nock = require('nock'); | ||
//var request, response, error; | ||
|
||
//describe('Lelylan Error',function() { | ||
|
||
//describe('with status code 500',function() { | ||
|
||
//beforeEach(function(done) { | ||
//request = nock('http://api.lelylan.com').get('/devices/1').reply(500, 'Internal Server Error'); | ||
//done(); | ||
//}) | ||
|
||
//beforeEach(function(done) { | ||
//Lelylan.Device.find('1', function(e, r) { | ||
//error = e; response = r; done(); | ||
//}) | ||
//}) | ||
|
||
//it('makes the HTTP request', function() { | ||
//request.isDone(); | ||
//}); | ||
|
||
//it('return a json array',function() { | ||
//error.should.be.a('object'); | ||
//}); | ||
//}); | ||
|
||
//describe('with status code 401',function() { | ||
|
||
//beforeEach(function(done) { | ||
//request = nock('http://api.lelylan.com').get('/devices/1').replyWithFile(401, __dirname + '/fixtures/errors/401.json'); | ||
//done(); | ||
//}) | ||
|
||
//beforeEach(function(done) { | ||
//Lelylan.Device.find('1', function(e, r) { | ||
//error = e; response = r; done(); | ||
//}) | ||
//}) | ||
|
||
//it('makes the HTTP request', function() { | ||
//request.isDone(); | ||
//}); | ||
|
||
//it('return a json array',function() { | ||
//error.should.be.a('object'); | ||
//}); | ||
//}); | ||
|
||
//describe('with status code 404',function() { | ||
|
||
//beforeEach(function(done) { | ||
//request = nock('http://api.lelylan.com').get('/devices/1').replyWithFile(404, __dirname + '/fixtures/errors/404.json'); | ||
//done(); | ||
//}) | ||
|
||
//beforeEach(function(done) { | ||
//Lelylan.Device.find('1', function(e, r) { | ||
//error = e; response = r; done(); | ||
//}) | ||
//}) | ||
|
||
//it('makes the HTTP request', function() { | ||
//request.isDone(); | ||
//}); | ||
|
||
//it('return a json array',function() { | ||
//error.should.be.a('object'); | ||
//}); | ||
//}); | ||
|
||
//describe('with status code 422',function() { | ||
|
||
//beforeEach(function(done) { | ||
//request = nock('http://api.lelylan.com').get('/devices/1').replyWithFile(422, __dirname + '/fixtures/errors/422.json'); | ||
//done(); | ||
//}) | ||
|
||
//beforeEach(function(done) { | ||
//Lelylan.Device.find('1', function(e, r) { | ||
//error = e; response = r; done(); | ||
//}) | ||
//}) | ||
|
||
//it('makes the HTTP request', function() { | ||
//request.isDone(); | ||
//}); | ||
|
||
//it('return a json array',function() { | ||
//error.should.be.a('object'); | ||
//}); | ||
//}); | ||
//}) | ||
var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' } }, | ||
OAuth2 = require('./../lib/simple-oauth2.js')(credentials), | ||
nock = require('nock'); | ||
|
||
var request, result, error; | ||
|
||
describe('Simple OAuth2 Error',function() { | ||
|
||
describe('with status code 401',function() { | ||
|
||
beforeEach(function(done) { | ||
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code' }; | ||
request = nock('https://example.org:443').post('/oauth/token', params).reply(401, 'Unauthorized'); | ||
done(); | ||
}); | ||
|
||
beforeEach(function(done) { | ||
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com' } | ||
OAuth2.AuthCode.getToken(params, function(e, r) { | ||
error = e; result = r; done(); | ||
}); | ||
}); | ||
|
||
it('makes the HTTP request', function() { | ||
request.isDone(); | ||
}); | ||
|
||
it('returns an access token',function() { | ||
error.message.message.should.eql('Unauthorized'); | ||
}); | ||
}); | ||
|
||
describe('with status code 500',function() { | ||
|
||
beforeEach(function(done) { | ||
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code' }; | ||
request = nock('https://example.org:443').post('/oauth/token', params).reply(500, 'Server Error'); | ||
done(); | ||
}); | ||
|
||
beforeEach(function(done) { | ||
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com' } | ||
OAuth2.AuthCode.getToken(params, function(e, r) { | ||
error = e; result = r; done(); | ||
}); | ||
}); | ||
|
||
it('makes the HTTP request', function() { | ||
request.isDone(); | ||
}); | ||
|
||
it('returns an access token',function() { | ||
error.message.message.should.eql('Internal Server Error'); | ||
}); | ||
}); | ||
}) | ||
|
||
|