Skip to content

Commit

Permalink
100% coverage, circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
sagi committed Nov 20, 2018
0 parents commit 3740ad6
Show file tree
Hide file tree
Showing 11 changed files with 4,618 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:8.11

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# eslint
- run:
name: "elsint"
command: yarn eslint


# prettier
- run:
name: "prettier"
command: yarn prettier:check

# test
- run:
name: "test"
command: yarn test

# coverage
- run:
name: "coverage"
command: yarn coverage --ci --testResultsProcessor="jest-junit"
environment:
JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml"

- store_test_results:
path: reports/junit
- store_artifacts:
path: reports/junit

# coveralls
- run:
name: "coveralls"
command: yarn coverage --coverageReporters=text-lcov | yarn coveralls
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 2018,
},
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
indent: ['error', 2, { SwitchCase: 1 }],
'no-console': 'off',
},
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
coverage
*.swp
yarn-error.log
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!index.js
!utils.js
!package.json
!README.md
!LICENSE
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"parser": "babylon",
"overrides": [
{
"files": "*.json",
"options": { "parser": "json", "printWidth": 200 }
}
]
}
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# DoH (DNS over HTTPS) Command Line Client, RFC-8484 Compatible

[`@sagi.io/doh`](https://www.npmjs.com/package/@sagi.io/doh) is an RFC-8484 compliant Node.js [DNS over HTTPS](https://en.wikipedia.org/wiki/DNS_over_HTTPS) command line tool.

[![CircleCI](https://circleci.com/gh/sagi/doh-node.svg?style=svg)](https://circleci.com/gh/sagi/doh-node)
[![Coverage Status](https://coveralls.io/repos/github/sagi/doh-node/badge.svg?branch=master)](https://coveralls.io/github/sagi/doh-node?branch=master)
[![MIT License](https://img.shields.io/npm/l/@sagi.io/doh.svg?style=flat-square)](http://opensource.org/licenses/MIT)
[![version](https://img.shields.io/npm/v/@sagi.io/doh.svg?style=flat-square)](http://npm.im/@sagi.io/doh)

## Installation:
~~~
$ npm i -g @sagi.io/doh
~~~

Usage:
~~~
Usage: doh name [type] [class] [@dohUrl] [-p<port>] [-u<userAgent>] [-v] [-g];
~~~

If only `name` (domain name) is provided, it defaults to using Cloudflare's DNS-over-HTTPS server
(`@cloudflare-dns.com/dns-query`).

## Examples

~~~
$ doh sagi.io
~~~

Output:
~~~json
{
"id": 9013,
"type": "response",
"flags": 384,
"flag_qr": true,
"opcode": "QUERY",
"flag_aa": false,
"flag_tc": false,
"flag_rd": true,
"flag_ra": true,
"flag_z": false,
"flag_ad": false,
"flag_cd": false,
"rcode": "NOERROR",
"questions": [
{
"name": "sagi.io",
"type": "A",
"class": "IN"
}
],
"answers": [
{
"name": "sagi.io",
"type": "A",
"ttl": 300,
"class": "IN",
"flush": false,
"data": "151.101.1.195"
},
{
"name": "sagi.io",
"type": "A",
"ttl": 300,
"class": "IN",
"flush": false,
"data": "151.101.65.195"
}
],
"authorities": [],
"additionals": []
}
~~~

~~~
$ doh mx sagi.io @https://dns.google.com/experimental
~~~

Output:
~~~json
{
"id": 0,
"type": "response",
"flags": 384,
"flag_qr": true,
"opcode": "QUERY",
"flag_aa": false,
"flag_tc": false,
"flag_rd": true,
"flag_ra": true,
"flag_z": false,
"flag_ad": false,
"flag_cd": false,
"rcode": "NOERROR",
"questions": [
{
"name": "sagi.io",
"type": "MX",
"class": "IN"
}
],
"answers": [
{
"name": "sagi.io",
"type": "MX",
"ttl": 299,
"class": "IN",
"flush": false,
"data": {
"preference": 10,
"exchange": "mxa.mailgun.org"
}
},
{
"name": "sagi.io",
"type": "MX",
"ttl": 299,
"class": "IN",
"flush": false,
"data": {
"preference": 10,
"exchange": "mxb.mailgun.org"
}
}
],
"authorities": [],
"additionals": []
}
~~~

Probably some time the future we'll add a `DiG`-like output.

## License
MIT
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node
const doh = require('@sagi.io/dns-over-https');
const { parseArgv, parseDohUrl } = require('./utils');

(async () => {
const cliOptions = parseArgv(process.argv);
const {
dohUrl,
userAgent,
name,
method,
type,
klass,
port: userPort,
verbose,
} = cliOptions;

const { protocol, hostname, path } = parseDohUrl(dohUrl);

const useHttps = protocol === 'https:';
const port = userPort ? userPort : useHttps ? 443 : 80;

if (verbose) {
console.log(JSON.stringify(cliOptions, null, 2));
}

const r = await doh.query({
method,
hostname,
path,
port,
userAgent,
name,
type,
klass,
useHttps,
});
console.log(JSON.stringify(r, null, 2));
})();
45 changes: 45 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@sagi.io/doh",
"version": "0.0.1",
"description": "RFC-8484 Compliant DNS-over-HTTPS Command Line Tool",
"main": "index.js",
"author": "Sagi Kedmi <git@sagi.io> (https://sagi.io)",
"license": "MIT",
"bin": {
"doh": "./index.js"
},
"scripts": {
"start": "node index.js",
"prettier:check": "prettier --list-different index.js",
"eslint": "eslint index.js",
"test": "jest",
"coverage": "jest --coverage"
},
"dependencies": {
"@sagi.io/dns-over-https": "^0.0.2"
},
"devDependencies": {
"coveralls": "^3.0.2",
"eslint": "^5.9.0",
"eslint-plugin-jest": "^22.0.0",
"jest": "^23.6.0",
"jest-junit": "^5.2.0",
"prettier": "^1.14.3"
},
"repository": {
"type": "git",
"url": "https://github.com/sagi/doh-node.git"
},
"keywords": [
"dns-over-https",
"doh",
"cli",
"command line",
"dns over https",
"dns",
"https",
"dnshttps",
"security",
"privacy"
]
}

0 comments on commit 3740ad6

Please sign in to comment.