Skip to content

Commit

Permalink
Cleaned up and prep for going live a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanndutoit committed Feb 21, 2018
1 parent 41e40e8 commit e703eed
Show file tree
Hide file tree
Showing 14 changed files with 1,938 additions and 1,969 deletions.
Empty file added Dockerfile
Empty file.
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# @passmarked/dns

![NPM](https://img.shields.io/npm/dt/@passmarked/dns.svg) [![Build Status](https://travis-ci.org/passmarked/dns.svg)](https://travis-ci.org/passmarked/dns)

[Passmarked](http://passmarked.com?source=github&repo=dns) is a suite of tests that can be run against any page/website to identify issues with parity to most online tools in one package.

The [Terminal Client](http://npmjs.org/package/passmarked) is intended for use by developers to integrate into their workflow/CI servers but also integrate into their own application that might need to test websites and provide realtime feedback.

All of the checks on [Passmarked](https://passmarked.com?source=github&repo=dns) can be voted on importance and are [open-sourced](http://github.com/passmarked/suite), to encourage community involvement in fixing and adding new rules. We are building the living Web Standard and love any [contributions](#contributing).

## Synopsis

The rules checked in this module are:

* **count** - Less than <2 ip records on your main domain name, this is bad as it does not offer failover
* **response** - The SOA of the hostname could not be requested from the specific name server that was configured

## Running

The rules are checked everytime a url is run through Passmarked or our API. To run using the hosted system head to [passmarked.com](http://passmarked.com?source=github&repo=dns) or our [Terminal Client](http://npmjs.org/package/passmarked) use:

```bash
npm install -g passmarked
passmarked --filter=dns example.com
```

The hosted version allows free runs from our homepage and the option to register a site to check in its entirety.
Using the Passmarked npm module (or directly via the API) integrations are also possible to get running reports with all the rules in a matter of seconds.

## Running Locally

All rules can be run locally using our main integration library. This requires installing the package and any dependencies that the code might have such as a specific version of OpenSSL, see [#dependencies](#dependencies)

First ensure `passmarked` is installed:

```bash
npm install passmarked
npm install @passmarked/dns
```

After which the rules will be runnable using promises:

```javascript
passmarked.createRunner(
require('@passmarked/dns'), // this package
require('@passmarked/ssl'), // to test SSL
require('@passmarked/network') // to test network performance
).run({
url: 'http://example.com',
body: 'body of page here',
har: {log: {entries: []}}
}).then(function(payload) {
if (payload.hasRule('secure')) {
console.log('better check that ...');
}
var rules = payload.getRules();
for (var rule in rules) {
console.log('*', rules[rule].getMessage());
}
}).catch(console.error.bind(console));
```

Alternatively, callbacks are also available:

```javascript
passmarked.createRunner(
require('@passmarked/dns'),
require('@passmarked/ssl'),
require('@passmarked/network')
).run({
url: 'http://example.com',
body: 'body of page here',
har: {log: {entries: []}}
}, function(err, payload) {
if (payload.hasRule('secure')) {
console.log("better check that ...");
}
var rules = payload.getRules();
for (var rule in rules) {
console.log('*', rules[rule].getMessage());
}
});
```

## Dependencies

This module does not need any specific external services or packages. This section will be updated if that ever changes with detailed setup steps/dns.

## Rules

Rules represent checks that occur in this module, all of these rules have a **UID** which can be used to check for specific rules. For the structure and more details see the [Wiki](https://github.com/passmarked/passmarked/wiki) page on [Rules](https://github.com/passmarked/passmarked/wiki/Create).

> Rules also include a `type` which could be `critical`, `error`, `warning` or `notice` giving a better view on the importance of the rule.
## Contributing

```bash
git clone [email protected]:passmarked/dns.git
npm install
npm test
```

Pull requests have a prerequisite of passing tests. If your contribution is accepted, it will be merged into `develop` (and then `master` after staging tests by the team) which will then be deployed live to [passmarked.com](http://passmarked.com?source=github&repo=dns) and on NPM for everyone to download and test.

## About

To learn more visit:

* [Passmarked](http://passmarked.com?source=github&repo=dns)
* [Terminal Client](https://www.npmjs.com/package/passmarked)
* [NPM Package](https://www.npmjs.com/package/@passmarked/dns)
* [Slack](http://passmarked.com/chat?source=github&repo=dns) - We have a Slack team with all our team and open to anyone using the site to chat and figure out problems. To join head over to [passmarked.com/chat](http://passmarked.com/chat?source=github&repo=dns) and request a invite.

## License

Copyright 2016 Passmarked Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
135 changes: 103 additions & 32 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,125 @@
const dns = require('dns');
const { URL } = require('url');
const _ = require('underscore');
const async = require('async');
const dns = require('dns');
const url = require('url');
const _ = require('underscore');
const async = require('async');

// import rules to check for each individual DNS server
const rules = require('./rules');

// expose our main function
module.exports = exports = function(payload, fn) {

// get hostname from payload data
const data = payload.getData();
const myURL = new URL(data.url);
const hostname = myURL.hostname;
// get hostname from payload data
var data = payload.getData();

// set servers to use for initial NS resolving
dns.setServers(['8.8.8.8', '8.8.4.4']);
// sanity check
if(!data.url);

dns.resolveNs(hostname, (err, nsNames) => {

if (err) return fn(err);
console.log(nsNames);
// iterate through DNS server names and get their IPs
async.map(nsNames, dns.resolve, (err, nsIPs) => {
// load the url
var uri = new url.parse(data.url);

if (err) return fn(err);
nsIPs=_.flatten(nsIPs);
// payload.nsNames = nsNames;
async.each(rules, function(checkFunc, cb) {
// get the hostname
var hostname = uri.hostname;

checkFunc(payload, {
// set servers to use for initial NS resolving
dns.setServers([

nsNames: nsNames,
nsIPs: nsIPs
'8.8.8.8',
'8.8.4.4'

}, function(err) {
]);

// bubble up any errors we might get
cb(err);

});
// resolve the domain name
dns.resolveNs(hostname, (err, nsNames) => {

// handle the error
if (err) {

}, (err) => {
// show the error
payload.error('client', 'Something went wrong while checking the name server', err);

if (err) return fn(err);
fn();
// done
return fn(err);

});
}

// get/set the records
var ipRecords = [];

// build up the options
var optionItems = [];

// loop and run each
async.eachSeries(nsNames || [], function(nsName, cb) {

// resolve the DNS
dns.resolve(nsName, function(err, nsIPs) {

// check for the error
if(err) {

// output the error
payload.error('client', 'Something went wrong while trying to resolve: ' + nsName);

// done
return cb(null);

}

// flatten list
nsIPs = _.flatten(nsIPs);

// add the items
for(var i = 0; i < (nsIPs || []).length; i++) {

// add the list
optionItems.push({

server: nsName,
address: nsIPs[i]

});

}

// done
cb(null);

});

}, function() {

// loop through all the options
async.eachSeries(data.testOptions || optionItems || [], function(options, cb) {

// run all the rules for this server
async.eachSeries(rules, function(checkFunc, cbb) {

// run it
checkFunc(payload, options, function() {

// finish
cbb();

});

}, function() {

// done
cb(null);

});

});
}, function() {

// done
fn(null);

});

})

});

};
54 changes: 0 additions & 54 deletions lib/rules/all-servers-responding.js

This file was deleted.

Loading

0 comments on commit e703eed

Please sign in to comment.