Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
113 lines (89 sloc) 4.35 KB

Development notes

Misc resources I drew upon while learning node.js and writing this script.

Node.js (general)

Packaging

Testing

general

vows

There's a lot to learn about how node-http-proxiy tests are written:

vows alternatives

Apieasy

At some point, I actually implemented my tests using APIEasy, but then I decided to remove it as a dependency. For posterity, here's the code:

// Helper function to convert @table@, a 2d array, into an array of objects.
// Example usage:
//   convertToAssoc( [[1,2],[3,4]], ["a","b"]) 
//   => [ {a:1, b:2}, {a:3, b:4}]
var convertToAssoc = function(headers, table) {
  var assocTable = [];
  for (var i = 0; i < table.length; i++) {
    var assoc = {}
    for (var j=0; j < headers.length; j++) {
      assoc[headers[j]] = table[i][j];
    }
    assocTable.push(assoc);
  }
  return assocTable;
}

var tests = convertToAssoc(
    ["backend_code", "proxy_code", "method", "path", "description"],
    [ [200, 403, 'POST', '/solr', 'Proxy blocks all POST requests'],
      [200, 200, 'GET',  '/solr/select', 'Proxy allows /solr/select requests'],
      [200, 403, 'GET',  '/solr/admin', 'Proxy blocks /solr/admin requests (not in whitelist)'],
      [200, 403, 'GET',  '/solr/update', 'Proxy blocks /solr/update requests (not in whitelist)'],
      [200, 200, 'GET',  '/solr/select?q=balloon', 'Proxy allows random /solr/select queries'],
      [200, 403, 'GET',  '/solr/select?qt=/update', 'Proxy blocks queries with qt= param'],
      [200, 403, 'GET',  '/solr/select?stream.body=EVIL', 'Proxy blocks queries with stream.* param']
    ]);

var APIeasy = require('api-easy'),
    assert = require('assert');

var suite = APIeasy.describe('solr-security-proxy');

tests.forEach(function(test) { 
  suite.discuss(test.description)
         .discuss('(without proxy)')
           .use('localhost', 8080)
             .get(test.path)
               .expect(test.backend_code)
           .undiscuss()
         .discuss('(via proxy)')
           .use('localhost', 8008)
             .get(test.path)
               .expect(test.proxy_code)
           .undiscuss()
         .undiscuss();
})

suite.export(module);