CartoDB-SQL-API/test/unit/apikeyauth-test.js

91 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
require('../helper');
var ApikeyAuth = require('../../lib/auth/apikey');
var assert = require('assert');
2019-12-24 01:19:08 +08:00
describe.skip('has credentials', function () {
var noCredentialsRequests = [
{
des: 'there is not api_key/map_key in the request query',
2019-12-24 01:19:08 +08:00
req: { query: {} }
},
{
des: 'api_key is undefined`ish in the request query',
2019-12-24 01:19:08 +08:00
req: { query: { api_key: null } }
},
{
des: 'map_key is undefined`ish in the request query',
2019-12-24 01:19:08 +08:00
req: { query: { map_key: null } }
},
{
des: 'there is not api_key/map_key in the request body',
2019-12-24 01:19:08 +08:00
req: { query: {}, body: {} }
},
{
des: 'api_key is undefined`ish in the request body',
2019-12-24 01:19:08 +08:00
req: { query: {}, body: { api_key: null } }
},
{
des: 'map_key is undefined`ish in the request body',
2019-12-24 01:19:08 +08:00
req: { query: {}, body: { map_key: null } }
}
];
2019-12-24 01:19:08 +08:00
noCredentialsRequests.forEach(function (request) {
it('has no credentials if ' + request.des, function () {
testCredentials(request.req, false);
});
});
var credentialsRequests = [
{
des: 'there is api_key in the request query',
2019-12-24 01:19:08 +08:00
req: { query: { api_key: 'foo' } }
},
{
des: 'there is api_key in the request query',
2019-12-24 01:19:08 +08:00
req: { query: { map_key: 'foo' } }
},
{
des: 'there is api_key in the request body',
2019-12-24 01:19:08 +08:00
req: { query: {}, body: { api_key: 'foo' } }
},
{
des: 'there is map_key in the request body',
2019-12-24 01:19:08 +08:00
req: { query: {}, body: { map_key: 'foo' } }
}
];
2019-12-24 01:19:08 +08:00
credentialsRequests.forEach(function (request) {
it('has credentials if ' + request.des, function () {
testCredentials(request.req, true);
});
});
2019-12-24 01:19:08 +08:00
function testCredentials (req, hasCredentials) {
var apiKeyAuth = new ApikeyAuth(req);
2019-12-26 21:01:18 +08:00
assert.strictEqual(apiKeyAuth.hasCredentials(), hasCredentials);
}
});
2019-12-24 01:19:08 +08:00
describe.skip('verifyCredentials', function () {
it('callbacks with true value when request api_key is the same', function (done) {
testVerifyCredentials({ query: { api_key: 'foo' } }, { apiKey: 'foo' }, true, done);
});
2019-12-24 01:19:08 +08:00
it('callbacks with false value when request api_key is different', function (done) {
testVerifyCredentials({ query: { api_key: 'foo' } }, { apiKey: 'bar' }, false, done);
});
2019-12-24 01:19:08 +08:00
function testVerifyCredentials (req, options, shouldBeValid, done) {
var apiKeyAuth = new ApikeyAuth(req);
2019-12-24 01:19:08 +08:00
apiKeyAuth.verifyCredentials(options, function (err, validCredentials) {
2019-12-26 21:51:09 +08:00
assert.ifError(err);
2019-12-26 21:01:18 +08:00
assert.strictEqual(validCredentials, shouldBeValid);
done();
});
}
});