CartoDB-SQL-API/test/acceptance/pg-entities-access-validator.js

65 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-04-24 16:10:09 +08:00
const assert = require('../support/assert');
const TestClient = require('../support/test-client');
describe('PG entities access validator', function () {
const forbiddenQueries = [
'select * from information_schema.tables',
'select * from pg_catalog.pg_auth_members'
];
2018-04-24 19:22:15 +08:00
const testClientApiKey = new TestClient({ apiKey: 1234 });
const testClientAuthorized = new TestClient({ authorization: 'vizzuality:regular1' });
2018-04-24 16:10:09 +08:00
2018-04-24 19:22:15 +08:00
const expectedResponse = {
response: {
status: 403
2018-04-24 23:24:13 +08:00
}
2018-04-24 19:22:15 +08:00
};
function assertQuery(query, testClient, done) {
testClient.getResult(query, expectedResponse, (err, result) => {
assert.ifError(err);
assert.equal(result.error, 'system tables are forbidden');
done();
});
}
describe('validatePGEntitiesAccess enabled', function() {
before(function(){
2018-04-26 16:13:03 +08:00
global.settings.validatePGEntitiesAccess = true;
2018-04-24 19:22:15 +08:00
});
forbiddenQueries.forEach(query => {
it(`testClientApiKey: query: ${query}`, function(done) {
assertQuery(query, testClientApiKey, done);
2018-04-24 16:10:09 +08:00
});
2018-04-24 19:22:15 +08:00
it(`testClientAuthorized: query: ${query}`, function(done) {
assertQuery(query, testClientAuthorized, done);
});
});
});
describe('validatePGEntitiesAccess disabled', function() {
before(function(){
2018-04-26 16:13:03 +08:00
global.settings.validatePGEntitiesAccess = false;
2018-04-24 19:22:15 +08:00
});
forbiddenQueries.forEach(query => {
it(`testClientApiKey: query: ${query}`, function(done) {
2018-04-24 23:24:13 +08:00
testClientApiKey.getResult(query, err => {
assert.ifError(err);
done();
});
2018-04-24 19:22:15 +08:00
});
it(`testClientAuthorized: query: ${query}`, function(done) {
testClientAuthorized.getResult(query, err => {
assert.ifError(err);
done();
});
});
2018-04-24 16:10:09 +08:00
});
});
2018-04-24 21:56:35 +08:00
});