Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 17 additions & 45 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,40 @@
* Licensed under the MIT license.
*/

'use strict';
'use strict'

module.exports = function(grunt) {
module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>'
],
options: {
jshintrc: '.jshintrc'
}
},

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp']
},

// Configuration to be run (and then tested).
rantomizer: {
default_options: {
options: {
},
files: {
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123']
}
production: {
urls: ['http://localhost/wsj?env=prod', 'http://localhost/wsj?env=prod2']
},
staging: {
urls: ['http://localhost/wsj?env=stage']
},
custom_options: {
options: {
separator: ': ',
punctuation: ' !!!'
},
files: {
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123']
}
development: {
urls: ['http://localhost/wsj?env=dev']
}
},

// Unit tests.
nodeunit: {
tests: ['test/*_test.js']
}

});
})

// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
grunt.loadTasks('tasks')

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-nodeunit')

// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'rantomizer', 'nodeunit']);
grunt.registerTask('test', ['clean', 'rantomizer', 'nodeunit'])

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);

};
grunt.registerTask('default', ['jshint', 'test'])
}
58 changes: 40 additions & 18 deletions tasks/rantomizer.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
'use strict'
var request = require('request')
const url = require('url')
const TunnelClient = require('../../sel/tunnelclient')

module.exports = function (grunt) {

// Please see the Grunt documentation for more information regarding task
// creation: http://gruntjs.com/creating-tasks
grunt.registerTask('rantomizer', 'description', function () {
grunt.registerMultiTask('rantomizer', 'description', function () {
// Merge task-specific and/or target-specific options with these defaults.
var options = this.options({
punctuation: '.',
separator: ', '
let done = this.async()
let clients = {}
let requestCount = 0
let expected = this.data.urls.length
grunt.log.writeln(`Scanning ${this.data.urls}`)
this.data.urls.forEach(function (urlString) {
let parsedUrl = url.parse(urlString)
let key = parsedUrl.hostname + parsedUrl.port
if (!(key in clients)) {
clients[key] = []
}
clients[key].push(parsedUrl)
})
var done = this.async()
const client = new TunnelClient('ws://scan.rantomizer.com', '80', () => {
client.scan('wsj', (blocks) => {
if (blocks.length == 0) {
grunt.log.writeln('wsj PASSED')
} else {
grunt.log.error(`wsj FAILED (${blocks.length})`)
blocks.forEach(function (block) {
grunt.log.error(`Type: ${block.type} Filter: ${block.filter} Domain: ${block.docDomain} Request: ${block.url}`)
// var done = this.async()
for (var k in clients) {
if (!clients.hasOwnProperty(k)) {
// The current property is not a direct property of p
continue
}
let urlArray = clients[k]
let client = new TunnelClient('ws://scan.rantomizer.com', urlArray[0].hostname, urlArray[0].port == null ? 80 : urlArray[0].port, () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to constantize this at the top?

urlArray.forEach(function (urlObject) {
client.scan(urlObject.path, (blocks) => {
requestCount++
if (blocks.length == 0) {
grunt.log.writeln(`${urlObject.href} PASSED`)
} else {
grunt.log.error(`${urlObject.href} FAILED (${blocks.length})`)
blocks.forEach(function (block) {
grunt.log.error(`Type: ${block.type} Filter: ${block.filter} Domain: ${block.docDomain} Request: ${block.url}`)
})
grunt.warn(`${urlObject.href} FAILED (${blocks.length})`)
}
if(requestCount == expected) {
console.log(`Finished ${requestCount}/${expected}`)
done();
}
})
grunt.warn(`wsj FAILED (${blocks.length})`)
}
done()
})
})
})
}
})
}