-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
225 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
#!/usr/bin/env node | ||
#!/usr/bin/env node --harmony | ||
|
||
require('update-notifier')({ | ||
pkg: require('../package.json') | ||
}).notify(); | ||
}).notify() | ||
|
||
const log = require('debug')('ban'); | ||
const log = require('debug')('ban') | ||
|
||
function getProperty(prop) { | ||
function getProperty (prop) { | ||
return function (obj) { | ||
return obj[prop]; | ||
}; | ||
return obj[prop] | ||
} | ||
} | ||
|
||
const isBanned = require('..'); | ||
const ggit = require('ggit'); | ||
const getName = getProperty('name'); | ||
const isBanned = require('..') | ||
const ggit = require('ggit') | ||
const getName = getProperty('name') | ||
|
||
function collectFilenames(info) { | ||
var filenames = []; | ||
function collectFilenames (info) { | ||
var filenames = [] | ||
if (info.A) { | ||
filenames = filenames.concat(info.A.map(getName)); | ||
filenames = filenames.concat(info.A.map(getName)) | ||
} | ||
if (info.M) { | ||
filenames = filenames.concat(info.M.map(getName)); | ||
filenames = filenames.concat(info.M.map(getName)) | ||
} | ||
if (info.C) { | ||
filenames = filenames.concat(info.C.map(getName)); | ||
filenames = filenames.concat(info.C.map(getName)) | ||
} | ||
return filenames; | ||
return filenames | ||
} | ||
|
||
function printFilenames(names) { | ||
log('%d changed filenames', names.length); | ||
log(names); | ||
return names; | ||
function printFilenames (names) { | ||
log('%d changed filenames', names.length) | ||
log(names) | ||
return names | ||
} | ||
|
||
ggit.changedFiles() | ||
.then(collectFilenames) | ||
.then(printFilenames) | ||
.then(isBanned) | ||
.then(function (foundBannedFilenames) { | ||
log('found banned filenames?', foundBannedFilenames); | ||
log('found banned filenames?', foundBannedFilenames) | ||
if (foundBannedFilenames) { | ||
process.exit(-1); | ||
process.exit(-1) | ||
} | ||
}) | ||
.catch(function (err) { | ||
console.error(err.message); | ||
process.exit(-1); | ||
console.error(err.message) | ||
process.exit(-1) | ||
}) | ||
.done(); | ||
.done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,77 @@ | ||
const la = require('lazy-ass'); | ||
const check = require('check-more-types'); | ||
const la = require('lazy-ass') | ||
const check = require('check-more-types') | ||
|
||
/* global describe, it */ | ||
describe('ban', function () { | ||
const isBanned = require('./ban'); | ||
const isBanned = require('./ban') | ||
|
||
it('is a function', function () { | ||
la(check.fn(isBanned)) | ||
}) | ||
|
||
it('catches a few cases', function () { | ||
const invalid = ['id_rsa', '.bash_history']; | ||
const invalid = ['id_rsa', '.bash_history'] | ||
invalid.forEach(function (name) { | ||
la(isBanned(name), name); | ||
}); | ||
}); | ||
la(isBanned(name), name) | ||
}) | ||
}) | ||
|
||
it('allows other filenames', function () { | ||
const invalid = ['something', 'foo.js']; | ||
const invalid = ['something', 'foo.js'] | ||
invalid.forEach(function (name) { | ||
la(!isBanned(name), name); | ||
}); | ||
}); | ||
la(!isBanned(name), name) | ||
}) | ||
}) | ||
|
||
it('catches long paths', function () { | ||
la(isBanned('foo/bar/id_rsa')); | ||
}); | ||
la(isBanned('foo/bar/id_rsa')) | ||
}) | ||
|
||
it('allows other long paths', function () { | ||
la(!isBanned('foo/bar/Gruntfile.js')); | ||
}); | ||
la(!isBanned('foo/bar/Gruntfile.js')) | ||
}) | ||
|
||
it('catches pem extension', function () { | ||
const name = 'something.pem'; | ||
la(isBanned(name), 'pem extension should be banned', name); | ||
}); | ||
const name = 'something.pem' | ||
la(isBanned(name), 'pem extension should be banned', name) | ||
}) | ||
|
||
it('allows pem substring', function () { | ||
const name = 'something-pem.txt'; | ||
la(!isBanned(name), 'should be allowed', name); | ||
}); | ||
const name = 'something-pem.txt' | ||
la(!isBanned(name), 'should be allowed', name) | ||
}) | ||
|
||
it('catches tblk extension', function () { | ||
la(isBanned('foo.tblk')); | ||
la(!isBanned('foo.atblk')); | ||
}); | ||
la(isBanned('foo.tblk')) | ||
la(!isBanned('foo.atblk')) | ||
}) | ||
|
||
it('calls provided logger', function () { | ||
var called = 0; | ||
function logger() { | ||
called += 1; | ||
var called = 0 | ||
function logger () { | ||
called += 1 | ||
} | ||
la(isBanned('foo.tblk', logger)); | ||
la(called === 1, 'logger has been called once'); | ||
}); | ||
la(isBanned('foo.tblk', logger)) | ||
la(called === 1, 'logger has been called once') | ||
}) | ||
|
||
it('supports multiple filename', function () { | ||
var called = 0; | ||
function logger() { | ||
called += 1; | ||
var called = 0 | ||
function logger () { | ||
called += 1 | ||
} | ||
const filenames = ['foo.tblk', 'id_rsa']; | ||
la(isBanned(filenames, logger)); | ||
la(called === 1, 'logger has been called once'); | ||
}); | ||
const filenames = ['foo.tblk', 'id_rsa'] | ||
la(isBanned(filenames, logger)) | ||
la(called === 1, 'logger has been called once') | ||
}) | ||
|
||
it('passes multiple filename', function () { | ||
var called = 0; | ||
function logger() { | ||
called += 1; | ||
var called = 0 | ||
function logger () { | ||
called += 1 | ||
} | ||
const filenames = ['foo.js', 'bar/baz.js']; | ||
la(!isBanned(filenames, logger)); | ||
la(called === 0, 'no problems'); | ||
}); | ||
|
||
}); | ||
const filenames = ['foo.js', 'bar/baz.js'] | ||
la(!isBanned(filenames, logger)) | ||
la(called === 0, 'no problems') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,50 @@ | ||
const la = require('lazy-ass'); | ||
const check = require('check-more-types'); | ||
const rules = require('../git-deny-patterns.json'); | ||
la(check.array(rules), 'missing list of rules', rules); | ||
const ruleToTester = require('./rule-to-tester'); | ||
la(check.fn(ruleToTester), 'could not get rule to tester'); | ||
const la = require('lazy-ass') | ||
const check = require('check-more-types') | ||
const rules = require('../git-deny-patterns.json') | ||
la(check.array(rules), 'missing list of rules', rules) | ||
const ruleToTester = require('./rule-to-tester') | ||
la(check.fn(ruleToTester), 'could not get rule to tester') | ||
|
||
const log = require('debug')('ban'); | ||
const log = require('debug')('ban') | ||
|
||
log('loaded', rules.length, 'rules'); | ||
log('loaded', rules.length, 'rules') | ||
|
||
// TODO lift? | ||
function formTesters(rules) { | ||
function formTesters (rules) { | ||
return rules.map(function (rule) { | ||
return ruleToTester(rule); | ||
}); | ||
return ruleToTester(rule) | ||
}) | ||
} | ||
|
||
const testers = formTesters(rules); | ||
const testers = formTesters(rules) | ||
|
||
const reToRegExp = require('./re-to-regexp'); | ||
|
||
function singleTester(filenames, logger, tester, k) { | ||
function singleTester (filenames, logger, tester, k) { | ||
return filenames.some(function (filename) { | ||
if (tester(filename)) { | ||
const brokenRule = rules[k]; | ||
const brokenRule = rules[k] | ||
|
||
var message = 'invalid filename ' + filename; | ||
var message = 'invalid filename ' + filename | ||
if (check.unemptyString(brokenRule.caption)) { | ||
message += '\n - ' + brokenRule.caption; | ||
message += '\n - ' + brokenRule.caption | ||
} | ||
if (brokenRule.description) { | ||
message += '\n - ' + brokenRule.description; | ||
message += '\n - ' + brokenRule.description | ||
} | ||
logger(message); | ||
logger(message) | ||
|
||
return true; | ||
return true | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
function isBannedFilename(filename, logger) { | ||
function isBannedFilename (filename, logger) { | ||
la(check.maybe.unemptyString(filename) || | ||
check.array(filename), 'expected single or list of filenames', filename); | ||
logger = logger || console.error.bind(console); | ||
check.array(filename), 'expected single or list of filenames', filename) | ||
logger = logger || console.error.bind(console) | ||
|
||
const filenames = check.array(filename) ? filename : [filename]; | ||
const filenames = check.array(filename) ? filename : [filename] | ||
|
||
return testers.some(singleTester.bind(null, filenames, logger)); | ||
return testers.some(singleTester.bind(null, filenames, logger)) | ||
} | ||
|
||
module.exports = isBannedFilename; | ||
module.exports = isBannedFilename |
Oops, something went wrong.