mof-uarotate
Advanced tools
Comparing version 1.0.0 to 1.0.1
32
index.js
'use strict' | ||
module.exports = function(userAgents) { | ||
const fs = require('fs') | ||
const path = require('path') | ||
let UA = { | ||
values:userAgents, | ||
curIndex:0, | ||
next:function() { | ||
this.curIndex = this.curIndex % this.values.length | ||
return this.values[this.curIndex++] | ||
} | ||
module.exports = function() { | ||
const useragent = fs.readFileSync(path.resolve(__dirname,'ua') ).toString().split('\n'); | ||
let UA = { | ||
values:useragent, | ||
curIndex:0, | ||
next:function() { | ||
this.curIndex = this.curIndex % this.values.length; | ||
return this.values[this.curIndex++]; | ||
} | ||
} | ||
return function(ctx, next) { | ||
if(ctx.opt.rotateUA) { | ||
ctx.opt['User-Agent'] = UA.next() | ||
} | ||
return next() | ||
} | ||
} | ||
return function(ctx, next) { | ||
ctx.opt.headers = ctx.opt.headers || {}; | ||
ctx.opt.headers['User-Agent'] = UA.next(); | ||
return next(); | ||
} | ||
} |
{ | ||
"name": "mof-uarotate", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "middleware of floodesh, which rotates User-Agent automatically", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
'use strict' | ||
const should = require('should'), | ||
Mof = require('mof'), | ||
uarotate = require('..') | ||
Mof = require('mof'), | ||
uarotate = require('..') | ||
@@ -10,41 +10,38 @@ let mof, ctx | ||
describe('mof-uarotate()', function(){ | ||
before(function(){ | ||
mof = new Mof() | ||
mof.use(uarotate()) | ||
ctx = { | ||
opt:{ | ||
} | ||
} | ||
}) | ||
before(function(){ | ||
mof = new Mof() | ||
mof.use(uarotate(['ua1','ua2','ua3'])) | ||
console.log(' Init with [\'ua1\',\'ua2\',\'ua3\']') | ||
ctx = { | ||
opt:{ | ||
rotateUA:true | ||
} | ||
} | ||
}) | ||
it('should be Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt.headers['User-Agent'].should.be.eql('Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)') | ||
done() | ||
})(ctx) | ||
}) | ||
it('should be ua1', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt['User-Agent'].should.be.eql('ua1') | ||
done() | ||
})(ctx) | ||
}) | ||
it('should be Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt.headers['User-Agent'].should.be.eql('Mozilla/5.0 (compatible; U; ABrowse 0.6; Syllable) AppleWebKit/420+ (KHTML, like Gecko)') | ||
done() | ||
})(ctx) | ||
}) | ||
it('should be ua2', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt['User-Agent'].should.be.eql('ua2') | ||
done() | ||
})(ctx) | ||
}) | ||
it('should be Mozilla/5.0 (compatible; ABrowse 0.4; Syllable)', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt.headers['User-Agent'].should.be.eql('Mozilla/5.0 (compatible; ABrowse 0.4; Syllable)') | ||
done() | ||
})(ctx) | ||
}) | ||
it('should be ua3', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt['User-Agent'].should.be.eql('ua3') | ||
done() | ||
})(ctx) | ||
}) | ||
it('should be ua1', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt['User-Agent'].should.be.eql('ua1') | ||
done() | ||
})(ctx) | ||
}) | ||
}) | ||
it.skip('should be ua1', function(done){ | ||
mof.callback( ctx => { | ||
ctx.opt.headers['User-Agent'].should.be.eql('ua1') | ||
done() | ||
})(ctx) | ||
}) | ||
}) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
973482
5
58
1
1