Socket
Socket
Sign inDemoInstall

ntf

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntf - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

.gitignore

93

lib/http.js

@@ -10,3 +10,3 @@ var http = require('http')

return function(opts, callback) {
if (typeof(opts) !== 'object') opts = { url: opts }
if (typeof opts !== 'object') opts = { url: opts }
opts.url = (parentOpts.url || '') + opts.url

@@ -17,3 +17,3 @@

test._ntf.parentOpts = parentOpts
if (typeof(test._ntf.meta) !== 'object') test._ntf.meta = this.meta || {}
if (typeof test._ntf.meta !== 'object') test._ntf.meta = this.meta || {}
TEST[type].call(this, test, opts, callback)

@@ -25,3 +25,3 @@ }

var TEST = module.exports = function(opts) {
if (typeof(opts) === 'string') opts = { url: opts }
if (typeof opts === 'string') opts = { url: opts }
return {

@@ -42,3 +42,3 @@ request: testType(opts, 'request'),

var res = this.ntf.res
this.equal(typeof(res) === 'object' ? res.statusCode : undefined,
this.equal(typeof res === 'object' ? res.statusCode : undefined,
code, 'Status code is ' + code)

@@ -49,6 +49,6 @@ },

, values
, result = typeof(res) === 'object' && typeof(res.headers) === 'object'
, result = typeof res === 'object' && typeof res.headers === 'object'
if (name === undefined)
return result ? res.headers : undefined
result = result && typeof(name) === 'string'
result = result && typeof name === 'string'
if (result) {

@@ -75,15 +75,19 @@ name = name.toLowerCase()

body: function(match) {
if (match === undefined) return this.ntf.body
if (!arguments.length) return this.ntf.body
var self = this
, body = typeof(self.ntf.body) === 'string' ? self.ntf.body : ''
, check = function(result) { self.ok(result, 'Content matches "' + match + '"') }
, args = Array.prototype.slice.call(arguments, 1)
if (Buffer.isBuffer(self.ntf.body)) {
self.deepEqual(match, self.ntf.body, 'Content buffers match')
return self.ntf.body
}
var body = typeof self.ntf.body === 'string' ? self.ntf.body : ''
, check = function(result) {
self.ok(result, 'Content matches "' + match + '"') }
, result
if (typeof(match) === 'string') {
result = typeof(body) === 'string' ? body.indexOf(match) : -1
if (typeof match === 'string') {
result = typeof body === 'string' ? body.indexOf(match) : -1
check(body.indexOf(match) >= 0)
} else if (match instanceof RegExp) {
result = typeof(body) === 'string' ? body.match(match) : null
result = typeof body === 'string' ? body.match(match) : null
check(result)
args.forEach(function(value, i) {
Array.prototype.slice.call(arguments, 1).forEach(function(value, i) {
self.equal(result && result[i+1], value,

@@ -100,3 +104,4 @@ 'Body[' + i + ']' +

var header = this.header()
, setCookie = header && header.hasOwnProperty('set-cookie') ? header['set-cookie'] : []
, setCookie = header && header.hasOwnProperty('set-cookie') ?
header['set-cookie'] : []
, cookie = {}

@@ -147,4 +152,5 @@ if (!Array.isArray(setCookie)) setCookie = [setCookie]

, r = false
if (v && v.hasOwnProperty('value') && typeof(v.value) === 'string') {
r = (match instanceof RegExp) ? v.value.match(match) : v.value == match
if (v && v.hasOwnProperty('value') && typeof v.value === 'string') {
r = (match instanceof RegExp) ?
v.value.match(match) : v.value == match
}

@@ -186,3 +192,3 @@ this.ok(r, 'Cookie[' + name + '] matches "' + match + '"')

var args = Array.prototype.slice.call(arguments)
if (typeof(args[0]) !== 'object') args[0] = { url: args[0] }
if (typeof args[0] !== 'object') args[0] = { url: args[0] }
var opts = args[0]

@@ -209,10 +215,12 @@ opts.url = (test._ntf.parentOpts.url || '') + opts.url

// ensure valid timeout
if (typeof(opts.timeout) !== 'number') opts.timeout = 30 * 1000
if (typeof(opts.jar) && typeof(opts.jar)!== 'object') opts.jar = {}
if (typeof opts.timeout !== 'number') opts.timeout = 30 * 1000
if (typeof opts.jar && typeof opts.jar !== 'object') opts.jar = {}
var reqTimeout
, url = urlLib.parse(opts.url)
, reqEncoding = opts.hasOwnProperty('reqEncoding') ? opts.reqEncoding : 'utf8'
, resEncoding = opts.hasOwnProperty('resEncoding') ? opts.resEncoding : 'utf8'
if (typeof(test._ntf.meta) === 'object' && test._ntf.meta.currentTest) {
if (typeof(test._ntf.meta.test) !== 'object') { test._ntf.meta.test = {} }
if (typeof test._ntf.meta === 'object' && test._ntf.meta.currentTest) {
if (typeof test._ntf.meta.test !== 'object') { test._ntf.meta.test = {} }
test._ntf.meta.test[test._ntf.meta.currentTest] = {

@@ -240,3 +248,3 @@ type: 'http',

var header = {}
if (typeof(opts.header) === 'object') {
if (typeof opts.header === 'object') {
Object.keys(opts.header).forEach(function(key) {

@@ -267,3 +275,3 @@ header[key.toLowerCase()] = opts.header[key]

var handleCookie = function(cookies) {
if (typeof(cookies) !== 'object') return
if (typeof cookies !== 'object') return
Object.keys(cookies).forEach(function(name) {

@@ -273,3 +281,3 @@ var cookieStr = httpOpts.headers.cookie ? httpOpts.headers.cookie + '; ' : ''

httpOpts.headers.cookie = cookieStr + name + '=' +
(typeof(cookie) === 'object' ? cookie.value : cookie)
(typeof cookie === 'object' ? cookie.value : cookie)
})

@@ -292,3 +300,3 @@ }

case 'form':
opts.body = qs.stringify(opts.body).toString('utf8')
opts.body = qs.stringify(opts.body).toString(reqEncoding)
setContentType('application/x-www-form-urlencoded')

@@ -302,4 +310,6 @@ break

if (!httpOpts.headers.hasOwnProperty('content-length')) {
httpOpts.headers['content-length'] = opts.body ?
Buffer.byteLength(opts.body, opts.reqEncoding || 'utf8') : 0
httpOpts.headers['content-length'] = opts.body ? (
Buffer.isBuffer(opts.body) ?
opts.body.length :
Buffer.byteLength(opts.body, reqEncoding)) : 0
}

@@ -321,2 +331,18 @@ }

var handleBody = function() {
if (!Array.isArray(test.ntf.body))
return
if (resEncoding) {
test.ntf.body = test.ntf.body.join('')
} else {
var body = new Buffer(test.ntf.bodyLength)
, start = 0
test.ntf.body.forEach(function(buf) {
buf.copy(body, start)
start += buf.length
})
test.ntf.body = body
}
}
// fail test on http errors

@@ -326,2 +352,3 @@ req.on('error', function(err) {

test.ntf.reqDone = true
handleBody()
test.ok(false, err)

@@ -362,6 +389,9 @@ test.done()

if (!opts.handle || opts.handleData) {
test.ntf.body = ''
res.setEncoding(opts.resEncoding || 'utf8')
test.ntf.body = []
test.ntf.bodyLength = 0
if (resEncoding)
res.setEncoding(resEncoding)
res.on('data', function(chunk) {
test.ntf.body += chunk
test.ntf.body.push(chunk)
test.ntf.bodyLength += chunk.length
})

@@ -373,2 +403,3 @@ }

test.ntf.reqClosed = true
handleBody()
if (!opts.handle && !test.ntf.reqDone) {

@@ -375,0 +406,0 @@ test.ntf.reqDone = true

{
"name": "ntf",
"description": "Network Testing Framework",
"version": "0.11.0",
"version": "0.12.0",
"author": "Silas Sewell <silas@sewell.org>",

@@ -12,2 +12,3 @@ "keywords": ["dns", "http", "nodeunit", "ntf", "test"],

"devDependencies": {
"express": ">= 2.5.9",
"jshint": ">= 0.6.1",

@@ -14,0 +15,0 @@ "nock": ">= 0.12.1"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc