Giter Site home page Giter Site logo

ntf's Introduction

ntf Build Status

ntf is a network testing framework written in Node.js.

See the ntf homepage for more details about the ntf framework.

Getting Started

Install ntf

npm install ntf
npm install ntf -g

Create a file named ntfjs.org.js

var ntf = require('ntf')
  , test = ntf.http('http://ntfjs.org')

exports.homepage = test.get('/', function(test) {
  test.statusCode(200)
  test.body('ntf')
  test.done()
})

Run the tests

ntf ntfjs.org.js
## Documentation ## DNS

Test DNS records.

var ntf = require('ntf')
  , dns = ntf.dns()
### dns.a(name, callback)

Resolve an IPv4 address record.

Arguments

  • name {String} - name to resolve
  • callback(test) {Function} - test callback

Example

exports.a = dns.a('a.dns.ntfjs.org', function(test) {
  test.address('127.0.0.1')
  test.done()
})
### dns.aaaa(name, callback)

Resolve an IPv6 address record.

Arguments

  • name {String} - name to resolve
  • callback(test) {Function} - test callback

Example

exports.aaaa = dns.aaaa('aaaa.dns.ntfjs.org', function(test) {
  test.address('::1')
  test.done()
})
### dns.cname(name, callback)

Resolve a canonical name record.

Arguments

  • name {String} - canonical name to resolve
  • callback(test) {Function} - test callback

Example

exports.cname = dns.cname('cname.dns.ntfjs.org', function(test) {
  test.name('a.dns.ntfjs.org')
  test.done()
})
### dns.mx(name, callback)

Resolve a mail exchange record.

Arguments

  • name {String} - mail exchange to resolve
  • callback(test) {Function} - test callback

Example

exports.mx = dns.mx('mx.dns.ntfjs.org', function(test) {
  test.name('mx1.dns.ntfjs.org')
  test.done()
})
### dns.ns(name, callback)

Resolve a name server record.

Arguments

  • name {String} - name server to resolve
  • callback(test) {Function} - test callback

Example

exports.ns = dns.ns('ns.dns.ntfjs.org', function(test) {
  test.name('ns1.dns.ntfjs.org')
  test.done()
})
### dns.ptr(ip, callback)

Resolve a pointer record.

Arguments

  • name {String} - IP address to resolve
  • callback(test) {Function} - test callback

Example

exports.ptr = dns.ptr('50.116.49.237', function(test) {
  test.name('hub.sewell.org')
  test.done()
})
### dns.srv(name, callback)

Resolve a service location record.

Arguments

  • name {String} - service to resolve
  • callback(test) {Function} - test callback

Example

exports.srv = dns.srv('_ntfjs', function(test) {
  test.name('srv1.dns.ntfjs.org')
  test.done()
})
### dns.txt(name, callback)

Resolve a text record.

Arguments

  • name {String} - text to resolve
  • callback(test) {Function} - test callback

Example

exports.txt = dns.txt('_ntfjs', function(test) {
  test.done()
})
### test.address(ip)

Assert answer contains IP address.

Arguments

  • ip {String} - IP address to check

Example

exports.a = dns.a('a.dns.ntfjs.org', function(test) {
  test.address('127.0.0.1')
  test.done()
})
### test.name(name)

Assert answer contains name.

Arguments

  • name {String} - name to check

Example

exports.cname = dns.cname('cname.dns.ntfjs.org', function(test) {
  test.name('a.dns.ntfjs.org')
  test.done()
})
## HTTP

Test HTTP requests.

var ntf = require('ntf')
  , http = ntf.http('http://http.ntfjs.org')
### http.request(options, callback)

Execute an HTTP request.

__Arguments__
  • options {Object,String} - options or path/URL
    • auth {String} - username and password (ex: "user:pass")
    • body {Object,String} - request body
    • cookie {Object} - cookie names and values (ex: { "sid": "2bf74f" })
    • header {Object} - header names and values (ex: { "content-type": "application/json" })
    • jar {Boolean} - persist cookies in sub-requests
    • method {String} - HTTP method (delete, get, post, put)
    • timeout {Integer} - maximum number of milliseconds request can take before its killed
    • type {String} - encodes body and sets content-type header (form, json)
    • url {String} - path or URL
  • callback(test) {Function} - test callback

Example

exports.request = http.request('/', function(test) {
  test.statusCode(200)
  test.done()
})
### http.del(options, callback)

Execute an HTTP delete request.

Arguments

  • options {Object,String} - see request arguments
    • method {String} - always set to delete
  • callback(test) {Function} - test callback

Example

exports.del = http.del('/delete', function(test) {
  test.statusCode(200)
  test.done()
})
### http.get(options, callback)

Execute an HTTP get request.

Arguments

  • options {Object,String} - see request arguments
    • method {String} - always set to get
  • callback(test) {Function} - test callback

Example

exports.get = http.get('/get', function(test) {
  test.statusCode(200)
  test.done()
})
### http.head(options, callback)

Execute an HTTP head request.

Arguments

  • options {Object,String} - see request arguments
    • method {String} - always set to head
  • callback(test) {Function} - test callback

Example

exports.head = http.head('/head', function(test) {
  test.statusCode(200)
  test.done()
})
### http.options(options, callback)

Execute an HTTP options request.

Arguments

  • options {Object,String} - see request arguments
    • method {String} - always set to options
  • callback(test) {Function} - test callback

Example

exports.options = http.options('/options', function(test) {
  test.statusCode(200)
  test.done()
})
### http.patch(options, callback)

Execute an HTTP patch request.

Arguments

  • options {Object,String} - see request arguments
    • method {String} - always set to patch
  • callback(test) {Function} - test callback

Example

exports.patch = http.patch('/patch', function(test) {
  test.statusCode(200)
  test.done()
})
### http.post(options, callback)

Execute an HTTP post request.

Arguments

  • options {Object} - see request arguments
    • body {Object,String} - should be object by default (see type below)
    • method {String} - always set to post
    • type {String} - defaults to form
  • callback(test) {Function} - test callback

Example

exports.post = http.post({ url: '/post', body: { 'q': 'test' } }), function(test) {
  test.statusCode(201)
  test.done()
})
### http.put(options, callback)

Execute an HTTP put request.

Arguments

  • options {Object} - see request arguments
    • method {String} - always set to put
  • callback(test) {Function} - test callback

Example

exports.put = http.put({ url: '/put', body: 'put' }), function(test) {
  test.statusCode(201)
  test.done()
})
### test.body([match[, compare...]])

Tests match against body and returns result.

Arguments

  • match
    • RegExp - asserts body matches RegExp
      • compare {String} - compare against match results
      • return {Array,null} - RegExp match result
    • String - asserts body contains match
      • return {Integer} - first position of matched result
    • undefined
      • return {String,undefined} - body String

Example

exports.get = http.get('/', function(test) {
  test.body(/<title>(.*)<\/title>/, 'ntf')
  test.done()
})
### test.cookie([name[, match]])

Tests cookie existence/value and returns match.

Arguments

  • name {String} - cookie name
  • match
    • RegExp - asserts value matches RegExp
      • return {Array,null} - RegExp match result
    • String - asserts value matches String
    • undefined
      • return {Object,undefined} - cookie object

Example

exports.get = http.get('/', function(test) {
  test.cookie('sid', /^[a-f0-9]+$/)
  test.done()
})
### test.header([name[, match]])

Tests header existence/value and returns match.

Arguments

  • name {String} - header name
  • match
    • RegExp - asserts value matches RegExp
      • return {Array,null} - RegExp match result
    • String - asserts value matches String
    • undefined
      • return {Object,undefined} - header object

Example

exports.get = http.get('/', function(test) {
  test.header('Content-Type', 'text/html')
  test.done()
})
### test.json([match])

Tests body against match and returns parsed JSON.

Arguments

  • match - deep equal assert against match
  • return - parsed JSON object

Example

exports.get = http.get('/', function(test) {
  test.json({ one: 'two' })
  test.done()
})
### test.jsonPath([path[, compare...]])

Tests json path against compares and returns result.

Arguments

  • path {String} - json path (examples)
  • compare - compare against json path results
  • return {Array} - parsed JSON object

Example

exports.get = http.get('/', function(test) {
  test.jsonPath('$.book.title', 'Second Foundation', "The Wise Man's Fear")
  test.done()
})
### test.statusCode(code)

Tests response status code.

Arguments

  • code {Integer} - status code

Example

exports.get = http.get('/', function(test) {
  test.statusCode(200)
  test.done()
})
## Socket

Test socket connections.

var ntf = require('ntf')
  , socket = ntf.socket('ntfjs.org')
### socket.tcp(port, callback)

Open TCP connection to host and port.

Arguments

  • options {Integer,Object} - port or options
    • port {Integer} - port
    • timeout {Integer} - maximum number of milliseconds before connection is killed
  • callback(test) {Function} - test callback

Example

exports.tcp = socket.tcp(25, function(test) {
  test.connect()
  test.done()
})
### test.connect(code)

Tests connection was opened.

Example

exports.tcp = socket.tcp(25, function(test) {
  test.connect()
  test.done()
})

MIT © 2011-2017 Shutterstock Images, LLC

ntf's People

Contributors

arodland avatar crazed avatar danmcc avatar richardlitt avatar rubikzube avatar silas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ntf's Issues

add test to verify certificates

Can you add the ability to test certificates. I want to be able to determine if the website has a trusted certificate or not. This would include hostname mismatches as well.

add functionality to test if port is connection refused.

I want to use this testing framework to test if paticular Layer 3 ACLs have been created on the network side.

About the only way to test this is using telnet and port number.

If the response is connection refused than the ACL is open. If there is no response and it appears to hang, the ACL is not open. Currently ntf only checks if its open and fails otherwise. Can we have a condition that would pass this test if connection is refused?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.