2014-08-05 22:20:06 +08:00
|
|
|
require('../helper');
|
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
var ApikeyAuth = require('../../app/auth/apikey');
|
|
|
|
var assert = require('assert');
|
2014-08-05 22:20:06 +08:00
|
|
|
|
2018-02-16 00:23:35 +08:00
|
|
|
describe.skip('has credentials', function() {
|
2014-08-05 22:20:06 +08:00
|
|
|
|
|
|
|
var noCredentialsRequests = [
|
|
|
|
{
|
|
|
|
des: 'there is not api_key/map_key in the request query',
|
|
|
|
req: {query:{}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'api_key is undefined`ish in the request query',
|
|
|
|
req: {query:{api_key:null}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'map_key is undefined`ish in the request query',
|
|
|
|
req: {query:{map_key:null}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'there is not api_key/map_key in the request body',
|
|
|
|
req: {query:{}, body:{}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'api_key is undefined`ish in the request body',
|
|
|
|
req: {query:{}, body:{api_key:null}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'map_key is undefined`ish in the request body',
|
|
|
|
req: {query:{}, body:{map_key:null}}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
noCredentialsRequests.forEach(function(request) {
|
2015-05-13 00:34:25 +08:00
|
|
|
it('has no credentials if ' + request.des, function() {
|
|
|
|
testCredentials(request.req, false);
|
2014-08-05 22:20:06 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var credentialsRequests = [
|
|
|
|
{
|
|
|
|
des: 'there is api_key in the request query',
|
|
|
|
req: {query:{api_key: 'foo'}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'there is api_key in the request query',
|
|
|
|
req: {query:{map_key: 'foo'}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'there is api_key in the request body',
|
|
|
|
req: {query:{}, body:{api_key:'foo'}}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
des: 'there is map_key in the request body',
|
|
|
|
req: {query:{}, body:{map_key:'foo'}}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
credentialsRequests.forEach(function(request) {
|
2015-05-13 00:34:25 +08:00
|
|
|
it('has credentials if ' + request.des, function() {
|
|
|
|
testCredentials(request.req, true);
|
2014-08-05 22:20:06 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function testCredentials(req, hasCredentials) {
|
|
|
|
var apiKeyAuth = new ApikeyAuth(req);
|
|
|
|
assert.equal(apiKeyAuth.hasCredentials(), hasCredentials);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-02-16 00:23:35 +08:00
|
|
|
describe.skip('verifyCredentials', function() {
|
2014-08-05 22:20:06 +08:00
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
it('callbacks with true value when request api_key is the same', function(done) {
|
2014-08-05 22:20:06 +08:00
|
|
|
testVerifyCredentials({query:{api_key: 'foo'}}, {apiKey: 'foo'}, true, done);
|
|
|
|
});
|
|
|
|
|
2015-05-13 00:34:25 +08:00
|
|
|
it('callbacks with false value when request api_key is different', function(done) {
|
2014-08-05 22:20:06 +08:00
|
|
|
testVerifyCredentials({query:{api_key: 'foo'}}, {apiKey: 'bar'}, false, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
function testVerifyCredentials(req, options, shouldBeValid, done) {
|
|
|
|
var apiKeyAuth = new ApikeyAuth(req);
|
|
|
|
apiKeyAuth.verifyCredentials(options, function(err, validCredentials) {
|
|
|
|
assert.equal(validCredentials, shouldBeValid);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|