pax_global_header00006660000000000000000000000064130620606020014505gustar00rootroot0000000000000052 comment=be27f68b78ae2d6ae66c419d15df99b99f0a8eaf har-validator-5.0.2/000077500000000000000000000000001306206060200142465ustar00rootroot00000000000000har-validator-5.0.2/.codeclimate.yml000066400000000000000000000003011306206060200173120ustar00rootroot00000000000000engines: fixme: enabled: true duplication: enabled: true config: languages: - javascript eslint: enabled: true ratings: paths: - lib/** - test/** har-validator-5.0.2/.editorconfig000066400000000000000000000003261306206060200167240ustar00rootroot00000000000000# http://editorconfig.org root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false har-validator-5.0.2/.gitignore000066400000000000000000000000411306206060200162310ustar00rootroot00000000000000*.log /node_modules /.nyc_output har-validator-5.0.2/.travis.yml000066400000000000000000000010341306206060200163550ustar00rootroot00000000000000language: node_js node_js: - 7 - 6 - 4 matrix: fast_finish: true cache: directories: - node_modules after_success: - npm install --only=production codeclimate-test-reporter semantic-release before_deploy: - npm run coverage -- --coverage-report=text-lcov | codeclimate-test-reporter deploy: skip_cleanup: true provider: script script: semantic-release pre && npm publish && semantic-release post || true on: branch: master node: 7 branches: except: - /^v\d+\.\d+\.\d+$/ - /^greenkeeper\/.+/ har-validator-5.0.2/LICENSE000066400000000000000000000013631306206060200152560ustar00rootroot00000000000000Copyright (c) 2015, Ahmad Nassri Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. har-validator-5.0.2/README.md000066400000000000000000000047241306206060200155340ustar00rootroot00000000000000# HAR Validator [![version][npm-version]][npm-url] [![License][license-image]][license-url] > Extremely fast HTTP Archive ([HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md)) validator using JSON Schema. [![Build Status][travis-image]][travis-url] [![Downloads][npm-downloads]][npm-url] [![Code Climate][codeclimate-quality]][codeclimate-url] [![Coverage Status][codeclimate-coverage]][codeclimate-url] [![Dependency Status][dependencyci-image]][dependencyci-url] [![Dependencies][david-image]][david-url] ## Install ```bash npm install --only=production --save har-validator ``` ## CLI Usage Please refer to [`har-cli`](https://github.com/ahmadnassri/har-cli) for more info. ## API **Note**: as of [`v2.0.0`](https://github.com/ahmadnassri/har-validator/releases/tag/v2.0.0) this module defaults to Promise based API. *For backward compatibility with `v1.x` an [async/callback API](docs/async.md) is also provided* - [async API](docs/async.md) - [callback API](docs/async.md) - [Promise API](docs/promise.md) *(default)* ---- > :copyright: [ahmadnassri.com](https://www.ahmadnassri.com/)  ·  > License: [ISC][license-url]  ·  > Github: [@ahmadnassri](https://github.com/ahmadnassri)  ·  > Twitter: [@ahmadnassri](https://twitter.com/ahmadnassri) [license-url]: http://choosealicense.com/licenses/isc/ [license-image]: https://img.shields.io/github/license/ahmadnassri/har-validator.svg?style=flat-square [travis-url]: https://travis-ci.org/ahmadnassri/har-validator [travis-image]: https://img.shields.io/travis/ahmadnassri/har-validator.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/har-validator [npm-version]: https://img.shields.io/npm/v/har-validator.svg?style=flat-square [npm-downloads]: https://img.shields.io/npm/dm/har-validator.svg?style=flat-square [codeclimate-url]: https://codeclimate.com/github/ahmadnassri/har-validator [codeclimate-quality]: https://img.shields.io/codeclimate/github/ahmadnassri/har-validator.svg?style=flat-square [codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/ahmadnassri/har-validator.svg?style=flat-square [david-url]: https://david-dm.org/ahmadnassri/har-validator [david-image]: https://img.shields.io/david/ahmadnassri/har-validator.svg?style=flat-square [dependencyci-url]: https://dependencyci.com/github/ahmadnassri/har-validator [dependencyci-image]: https://dependencyci.com/github/ahmadnassri/har-validator/badge?style=flat-square har-validator-5.0.2/docs/000077500000000000000000000000001306206060200151765ustar00rootroot00000000000000har-validator-5.0.2/docs/async.md000066400000000000000000000105301306206060200166340ustar00rootroot00000000000000## async API ```js import * as validate from 'har-validator/lib/async' import { request, response } from 'har-validator/lib/async' ``` ### validate.afterRequest(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [afterRequest"](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) objects ```js let isValid = validate.afterRequest(data) ``` ### validate.beforeRequest(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a ["afterRequest"](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) objects ```js let isValid = validate.beforeRequest(data) ``` ### validate.browser(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [browser](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#browser) object ```js let isValid = validate.browser(data) ``` ### validate.cache(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [cache](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) object ```js let isValid = validate.cache(data) ``` ### validate.content(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [content](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#content) object ```js let isValid = validate.content(data) ``` ### validate.cookie(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [cookie](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cookies) object ```js let isValid = validate.cookie(data) ``` ### validate.creator(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [creator](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#creator) object ```js let isValid = validate.creator(data) ``` ### validate.entry(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* an [entry](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#entries) object ```js let isValid = validate.entry(data) ``` ### validate.har(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a full [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) object ```js let isValid = validate.har(data) ``` ### validate.header(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [header](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#headers) object ```js let isValid = validate.header(data) ``` ### validate.log(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [log](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#log) object ```js let isValid = validate.log(data) ``` ### validate.page(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [page](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#pages) object ```js let isValid = validate.page(data) ``` ### validate.pageTimings(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [pageTimings](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#pageTimings) object ```js let isValid = validate.pageTimings(data) ``` ### validate.postData(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [postData](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#postData) object ```js let isValid = validate.postData(data) ``` ### validate.query(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [queryString](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#querystring) object ```js let isValid = validate.query(data) ``` ### validate.request(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [request](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#request) object ```js let isValid = validate.request(data) ``` ### validate.response(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [response](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#response) object ```js let isValid = validate.cacheEntry(data) ``` ### validate.timings(data) > Returns `true` or `false`. - **data**: `Object` *(Required)* a [timings](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#timings) object ```js let isValid = validate.timings(data) ``` har-validator-5.0.2/docs/callback.md000066400000000000000000000155521306206060200172640ustar00rootroot00000000000000## Callback API ```js import * as validate from 'har-validator/lib/async' import { request, response } from 'har-validator/lib/async' ``` ### validate.afterRequest(data [, callback]) - **data**: `Object` *(Required)* a [afterRequest"](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) objects - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.afterRequest(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.beforeRequest(data [, callback]) - **data**: `Object` *(Required)* a ["beforeRequest"](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) objects - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.beforeRequest(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.browser(data [, callback]) - **data**: `Object` *(Required)* a [browser](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#browser) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.browser(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.cache(data [, callback]) - **data**: `Object` *(Required)* a [cache](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.cache(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.content(data [, callback]) - **data**: `Object` *(Required)* a [content](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#content) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.content(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.cookie(data [, callback]) - **data**: `Object` *(Required)* a [cookie](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cookies) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.cookie(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.creator(data [, callback]) - **data**: `Object` *(Required)* a [creator](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#creator) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.creator(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.entry(data [, callback]) - **data**: `Object` *(Required)* an [entry](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#entries) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.entry(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.har(data [, callback]) - **data**: `Object` *(Required)* a full [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.har(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.header(data [, callback]) - **data**: `Object` *(Required)* a [header](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#headers) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.header(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.log(data [, callback]) - **data**: `Object` *(Required)* a [log](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#log) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.log(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.page(data [, callback]) - **data**: `Object` *(Required)* a [page](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#page) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.page(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.pageTimings(data [, callback]) - **data**: `Object` *(Required)* a [pageTimings](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#pageTimings) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.pageTimings(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.postData(data [, callback]) - **data**: `Object` *(Required)* a [postData](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#postdata') object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.postData(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.query(data [, callback]) - **data**: `Object` *(Required)* a [queryString](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#querystring) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.query(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.request(data [, callback]) - **data**: `Object` *(Required)* a [request](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#request) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.request(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.response(data [, callback]) - **data**: `Object` *(Required)* a [response](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#response) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.cacheEntry(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` ### validate.timings(data [, callback]) - **data**: `Object` *(Required)* a [timings](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#timings) object - **callback**: `Function` callback function with signature of `(err, valid)` ```js validate.timings(data, (err, valid) => { if (err) console.error(err.errors) if (valid) console.log('✔️') }) ``` har-validator-5.0.2/docs/promise.md000066400000000000000000000133641306206060200172050ustar00rootroot00000000000000## Promise API ```js import * as validate from 'har-validator' import * as validate from 'har-validator/lib/promise' import { request, response } from 'har-validator/lib/promise' ``` ### validate.afterRequest(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [afterRequest"](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) objects ```js validate.afterRequest(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.beforeRequest(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a ["beforeRequest"](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) objects ```js validate.beforeRequest(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.browser(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [browser](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#browser) object ```js validate.browser(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.cache(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [cache](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cache) object ```js validate.cache(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.content(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [content](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#content) object ```js validate.content(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.cookie(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [cookie](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#cookies) object ```js validate.cookie(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.creator(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [creator](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#creator) object ```js validate.creator(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.entry(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* an [entry](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#entries) object ```js validate.entry(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.har(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a full [HAR](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md) object ```js validate.har(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.header(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [header](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#headers) object ```js validate.header(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.log(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [log](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#log) object ```js validate.log(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.page(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [page](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#pages) object ```js validate.page(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.pageTimings(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [pageTimings](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#pageTimings) object ```js validate.pageTimings(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.postData(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [postData](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#postData) object ```js validate.postData(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.query(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [queryString](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#querystring) object ```js validate.query(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.request(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [request](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#request) object ```js validate.request(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.response(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [response](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#response) object ```js validate.cacheEntry(data) .then((data) => console.log('✔️')) .catch(console.error) ``` ### validate.timings(data) > Returns a promise that resolves to the valid object. - **data**: `Object` *(Required)* a [timings](https://github.com/ahmadnassri/har-spec/blob/master/versions/1.2.md#timings) object ```js validate.timings(data) .then((data) => console.log('✔️')) .catch(console.error) ``` har-validator-5.0.2/lib/000077500000000000000000000000001306206060200150145ustar00rootroot00000000000000har-validator-5.0.2/lib/async.js000066400000000000000000000037511306206060200164750ustar00rootroot00000000000000var Ajv = require('ajv') var HARError = require('./error') var schemas = require('har-schema') var ajv function validate (name, data, next) { data = data || {} // validator config ajv = ajv || new Ajv({ allErrors: true, schemas: schemas }) var validate = ajv.getSchema(name + '.json') var valid = validate(data) // callback? if (typeof next === 'function') { return next(!valid ? new HARError(validate.errors) : null, valid) } return valid } exports.afterRequest = function (data, next) { return validate('afterRequest', data, next) } exports.beforeRequest = function (data, next) { return validate('beforeRequest', data, next) } exports.browser = function (data, next) { return validate('browser', data, next) } exports.cache = function (data, next) { return validate('cache', data, next) } exports.content = function (data, next) { return validate('content', data, next) } exports.cookie = function (data, next) { return validate('cookie', data, next) } exports.creator = function (data, next) { return validate('creator', data, next) } exports.entry = function (data, next) { return validate('entry', data, next) } exports.har = function (data, next) { return validate('har', data, next) } exports.header = function (data, next) { return validate('header', data, next) } exports.log = function (data, next) { return validate('log', data, next) } exports.page = function (data, next) { return validate('page', data, next) } exports.pageTimings = function (data, next) { return validate('pageTimings', data, next) } exports.postData = function (data, next) { return validate('postData', data, next) } exports.query = function (data, next) { return validate('query', data, next) } exports.request = function (data, next) { return validate('request', data, next) } exports.response = function (data, next) { return validate('response', data, next) } exports.timings = function (data, next) { return validate('timings', data, next) } har-validator-5.0.2/lib/error.js000066400000000000000000000005651306206060200165110ustar00rootroot00000000000000function HARError (errors) { var message = 'validation failed' this.name = 'HARError' this.message = message this.errors = errors if (typeof Error.captureStackTrace === 'function') { Error.captureStackTrace(this, this.constructor) } else { this.stack = (new Error(message)).stack } } HARError.prototype = Error.prototype module.exports = HARError har-validator-5.0.2/lib/promise.js000066400000000000000000000033721306206060200170350ustar00rootroot00000000000000var Ajv = require('ajv') var HARError = require('./error') var schemas = require('har-schema') var ajv function validate (name, data) { data = data || {} // validator config ajv = ajv || new Ajv({ allErrors: true, schemas: schemas }) var validate = ajv.getSchema(name + '.json') return new Promise(function (resolve, reject) { var valid = validate(data) !valid ? reject(new HARError(validate.errors)) : resolve(data) }) } exports.afterRequest = function (data) { return validate('afterRequest', data) } exports.beforeRequest = function (data) { return validate('beforeRequest', data) } exports.browser = function (data) { return validate('browser', data) } exports.cache = function (data) { return validate('cache', data) } exports.content = function (data) { return validate('content', data) } exports.cookie = function (data) { return validate('cookie', data) } exports.creator = function (data) { return validate('creator', data) } exports.entry = function (data) { return validate('entry', data) } exports.har = function (data) { return validate('har', data) } exports.header = function (data) { return validate('header', data) } exports.log = function (data) { return validate('log', data) } exports.page = function (data) { return validate('page', data) } exports.pageTimings = function (data) { return validate('pageTimings', data) } exports.postData = function (data) { return validate('postData', data) } exports.query = function (data) { return validate('query', data) } exports.request = function (data) { return validate('request', data) } exports.response = function (data) { return validate('response', data) } exports.timings = function (data) { return validate('timings', data) } har-validator-5.0.2/package.json000066400000000000000000000020211306206060200165270ustar00rootroot00000000000000{ "version": "0.0.0-development", "name": "har-validator", "description": "Extremely fast HTTP Archive (HAR) validator using JSON Schema", "author": "Ahmad Nassri (https://www.ahmadnassri.com/)", "homepage": "https://github.com/ahmadnassri/har-validator", "repository": { "type": "git", "url": "https://github.com/ahmadnassri/har-validator.git" }, "license": "ISC", "main": "lib/promise.js", "keywords": [ "har", "cli", "ajv", "http", "archive", "validate", "validator" ], "engines": { "node": ">=4" }, "files": [ "lib" ], "bugs": { "url": "https://github.com/ahmadnassri/har-validator/issues" }, "scripts": { "lint": "standard && echint", "pretest": "npm run lint", "test": "tap test", "coverage": "tap test --reporter silent --coverage" }, "devDependencies": { "echint": "^4.0.1", "standard": "^9.0.1", "tap": "^10.3.0" }, "dependencies": { "ajv": "^4.9.1", "har-schema": "^1.0.5" } } har-validator-5.0.2/test/000077500000000000000000000000001306206060200152255ustar00rootroot00000000000000har-validator-5.0.2/test/async.js000066400000000000000000000023321306206060200167000ustar00rootroot00000000000000'use strict' const HARError = require('../lib/error') const invalid = require('./fixtures/har/invalid') const schemas = require('har-schema') const tap = require('tap') const valid = require('./fixtures/har/valid') const validate = require('../lib/async') tap.test('async', assert => { let keys = Object.keys(schemas).filter(key => key !== 'default') assert.plan(keys.length) keys.forEach(key => { assert.type(validate[key], 'function', `${key} is a function`) }) }) tap.test('failure', assert => { assert.plan(4) let error = new HARError([{ dataPath: '.log.version', message: 'should be string' }]) assert.notOk(validate.har({}), 'should fail') validate.har({}, (err, valid) => { assert.notOk(valid, 'should return false in a callback') assert.type(err, HARError, 'should return HARError object in a callback') }) validate.har(invalid.version, (err) => { assert.match(err, error, 'should fail on bad "log.version"') }) }) tap.test('success', assert => { assert.plan(3) assert.ok(validate.har(valid), 'should be successful') validate.har(valid, (err, valid) => { assert.ok(valid, 'should return true in a callback') assert.equal(err, null, 'should not have any errors') }) }) har-validator-5.0.2/test/cache-entry.js000066400000000000000000000006661306206060200177750ustar00rootroot00000000000000'use strict' const tap = require('tap') const validate = require('../lib/promise') tap.test('cache entry', assert => { assert.plan(2) return Promise.all([ validate.cache({ beforeRequest: null }).then(out => assert.match(out, { beforeRequest: null }, 'should allow null beforeRequest')), validate.cache({ afterRequest: null }).then(out => assert.match(out, { afterRequest: null }, 'should allow null afterRequest')) ]) }) har-validator-5.0.2/test/fixtures/000077500000000000000000000000001306206060200170765ustar00rootroot00000000000000har-validator-5.0.2/test/fixtures/har/000077500000000000000000000000001306206060200176505ustar00rootroot00000000000000har-validator-5.0.2/test/fixtures/har/invalid.json000066400000000000000000000014541306206060200221750ustar00rootroot00000000000000{ "creator": { "log": { "version": "1.2", "creator": { "name": "", "version": 2 }, "pages": [], "entries": [] } }, "date": { "log": { "version": "1.2", "creator": { "name": "WebInspector", "version": "537.36" }, "pages": [ { "startedDateTime": "2015-02-10T07:33:17.146", "id": "page_1", "title": "http://mockbin.com/", "pageTimings": { "onContentLoad": 627.4099349975586, "onLoad": 1266.5300369262695 } } ], "entries": [] } }, "version": { "log": { "version": 1.2, "creator": { "name": "", "version": "" }, "pages": [], "entries": [] } } } har-validator-5.0.2/test/fixtures/har/valid.json000066400000000000000000000064321306206060200216470ustar00rootroot00000000000000{ "log": { "version": "1.2", "creator": { "name": "WebInspector", "version": "537.36" }, "pages": [ { "startedDateTime": "2015-02-10T07:33:17.146Z", "id": "page_1", "title": "http://mockbin.com/", "pageTimings": { "onContentLoad": 627.4099349975586, "onLoad": 1266.5300369262695 } } ], "entries": [ { "startedDateTime": "2015-02-10T07:33:17.146Z", "time": 181.59985542297363, "serverIPAddress": "::1", "request": { "method": "GET", "url": "http://mockbin.com/", "httpVersion": "HTTP/1.1", "headers": [ { "name": "DNT", "value": "1" }, { "name": "Accept-Encoding", "value": "gzip, deflate, sdch" }, { "name": "Host", "value": "mockbin.com" }, { "name": "Connection", "value": "keep-alive" } ], "queryString": [], "cookies": [ { "name": "foo", "expires": "2015-02-10T07:33:17.146Z", "value": "bar", "httpOnly": false, "secure": false } ], "headersSize": 482, "bodySize": 0 }, "response": { "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "headers": [ { "name": "X-Response-Time", "value": "3.419ms" }, { "name": "Date", "value": "Tue, 10 Feb 2015 07:33:16 GMT" }, { "name": "Vary", "value": "Accept, Accept-Encoding" }, { "name": "X-Powered-By", "value": "mockbin.com" }, { "name": "Transfer-Encoding", "value": "chunked" }, { "name": "Content-Type", "value": "text/html; charset=utf-8" }, { "name": "Content-Encoding", "value": "gzip" }, { "name": "Connection", "value": "keep-alive" } ], "cookies": [], "content": { "size": 30, "mimeType": "text/html", "compression": 0, "text": "ALL YOUR BASE ARE BELONG TO US" }, "redirectURL": "", "headersSize": 430, "bodySize": 30 }, "cache": { "beforeRequest": null, "afterRequest": { "expires": "2009-04-16T15:50:36", "lastAccess": "2009-16-02T15:50:34", "eTag": "", "hitCount": 0, "comment": "" } }, "timings": { "blocked": 0.381000001652865, "dns": -1, "connect": -1, "send": 0.05899999996472599, "wait": 179.1829999983744, "receive": 1.9768554229816289, "ssl": -1 }, "connection": "161767", "pageref": "page_1" } ] } } har-validator-5.0.2/test/fixtures/request/000077500000000000000000000000001306206060200205665ustar00rootroot00000000000000har-validator-5.0.2/test/fixtures/request/invalid.json000066400000000000000000000012221306206060200231040ustar00rootroot00000000000000{ "headers": { "method": "GET", "url": "http://mockbin.com/", "httpVersion": "HTTP/1.1", "headers": {}, "queryString": [], "cookies": [], "headersSize": 0, "bodySize": 0 }, "malformed": { "method": "GET", "url": "http://mockbin.com/", "httpVersion": "HTTP/1.1", "headers": [ { "foo": "bar" } ], "queryString": [], "cookies": [], "headersSize": 0, "bodySize": 0 }, "url": { "method": "GET", "url": "mockbin.com", "httpVersion": "HTTP/1.1", "headers": [], "queryString": [], "cookies": [], "headersSize": 0, "bodySize": 0 } } har-validator-5.0.2/test/fixtures/request/valid.json000066400000000000000000000011261306206060200225600ustar00rootroot00000000000000{ "method": "GET", "url": "http://mockbin.com/", "httpVersion": "HTTP/1.1", "headers": [ { "name": "DNT", "value": "1" }, { "name": "Accept-Encoding", "value": "gzip, deflate, sdch" }, { "name": "Host", "value": "mockbin.com" }, { "name": "Connection", "value": "keep-alive" } ], "queryString": [], "cookies": [ { "name": "foo", "expires": "2015-02-10T07:33:17.146Z", "value": "bar", "httpOnly": false, "secure": false } ], "headersSize": 482, "bodySize": 0 } har-validator-5.0.2/test/fixtures/response/000077500000000000000000000000001306206060200207345ustar00rootroot00000000000000har-validator-5.0.2/test/fixtures/response/invalid.json000066400000000000000000000015221306206060200232550ustar00rootroot00000000000000{ "bodySize": { "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "headers": [], "cookies": [], "content": { "size": 0, "mimeType": "text/html" }, "redirectURL": "", "headersSize": 0, "bodySize": "0" }, "headers": { "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "headers": {}, "cookies": [], "content": { "size": 0, "mimeType": "text/html" }, "redirectURL": "", "headersSize": 0, "bodySize": 0 }, "malformed": { "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "headers": [ { "foo": "bar" } ], "cookies": [], "content": { "size": 0, "mimeType": "text/html" }, "redirectURL": "", "headersSize": 0, "bodySize": 0 } } har-validator-5.0.2/test/fixtures/response/valid.json000066400000000000000000000016011306206060200227240ustar00rootroot00000000000000{ "status": 200, "statusText": "OK", "httpVersion": "HTTP/1.1", "headers": [ { "name": "X-Response-Time", "value": "3.419ms" }, { "name": "Date", "value": "Tue, 10 Feb 2015 07:33:16 GMT" }, { "name": "Vary", "value": "Accept, Accept-Encoding" }, { "name": "X-Powered-By", "value": "mockbin.com" }, { "name": "Transfer-Encoding", "value": "chunked" }, { "name": "Content-Type", "value": "text/html; charset=utf-8" }, { "name": "Content-Encoding", "value": "gzip" }, { "name": "Connection", "value": "keep-alive" } ], "cookies": [], "content": { "size": 30, "mimeType": "text/html", "compression": 0, "text": "ALL YOUR BASE ARE BELONG TO US" }, "redirectURL": "", "headersSize": 430, "bodySize": 30 } har-validator-5.0.2/test/log.js000066400000000000000000000031361306206060200163470ustar00rootroot00000000000000'use strict' const HARError = require('../lib/error') const invalid = require('./fixtures/har/invalid') const tap = require('tap') const valid = require('./fixtures/har/valid') const validate = require('../lib/promise') const errors = { object: new HARError([{ dataPath: '', message: "should have required property 'log'" }]), array: new HARError([{ dataPath: '', message: 'should be object' }]), undef: new HARError([{ dataPath: '', message: "should have required property 'log'" }]), version: new HARError([{ dataPath: '.log.version', message: 'should be string' }]), creator: new HARError([{ dataPath: '.log.creator.version', message: 'should be string' }]), date: new HARError([{ dataPath: '.log.pages[0].startedDateTime', message: 'should match pattern' }]) } tap.test('log', assert => { assert.plan(7) return Promise.all([ validate.har({}).catch(err => assert.match(err, errors.object, 'should fail with empty object')), validate.har([]).catch(err => assert.match(err, errors.array, 'should fail with empty array')), validate.har(undefined).catch(err => assert.match(err, errors.undef, 'should fail with undefined')), validate.har(invalid.version).catch(err => assert.match(err, errors.version, 'should fail on bad "log.version"')), validate.har(invalid.creator).catch(err => assert.match(err, errors.creator, 'should fail on bad "log.creator"')), validate.har(invalid.date).catch(err => assert.match(err, errors.date, 'should fail on bad "log.pages.*.startedDateTime"')), validate.har(valid).then(out => assert.equal(out, valid, 'should not fail with full example')) ]) }) har-validator-5.0.2/test/promise.js000066400000000000000000000013511306206060200172410ustar00rootroot00000000000000'use strict' const fixture = require('./fixtures/har/valid') const HARError = require('../lib/error') const schemas = require('har-schema') const tap = require('tap') const validate = require('../lib/promise') tap.test('promises', assert => { let keys = Object.keys(schemas).filter((key) => key !== 'default') assert.plan((keys.length * 2) + 2) keys.forEach(key => { assert.type(validate[key], 'function', `${key} is a function`) assert.type(validate[key]().catch(() => {}), Promise, `${key}() is a promise`) }) validate.har({}).catch(err => { assert.type(err, HARError, 'thrown error is an object') }) validate.har(fixture).then(out => { assert.equal(out, fixture, 'resolves with the original data') }) }) har-validator-5.0.2/test/request.js000066400000000000000000000031471306206060200172600ustar00rootroot00000000000000'use strict' const HARError = require('../lib/error') const invalid = require('./fixtures/request/invalid') const tap = require('tap') const valid = require('./fixtures/request/valid') const validate = require('../lib/promise') const errors = { object: new HARError([{ dataPath: '', message: "should have required property 'method'" }]), array: new HARError([{ dataPath: '', message: 'should be object' }]), undef: new HARError([{ dataPath: '', message: "should have required property 'method'" }]), url: new HARError([{ dataPath: '.url', message: 'should match format "uri"' }]), headers: new HARError([{ dataPath: '.headers', message: 'should be array' }]), malformed: new HARError([{ dataPath: '.headers[0]', message: "should have required property 'name'" }]) } tap.test('request', assert => { assert.plan(7) return Promise.all([ validate.request({}).catch(err => assert.match(err, errors.object, 'should fail with empty object')), validate.request([]).catch(err => assert.match(err, errors.array, 'should fail with empty array')), validate.request(undefined).catch(err => assert.match(err, errors.undef, 'should fail with undefined')), validate.request(invalid.url).catch(err => assert.match(err, errors.url, 'should fail on bad "url"')), validate.request(invalid.headers).catch(err => assert.match(err, errors.headers, 'should fail on bad "headers"')), validate.request(invalid.malformed).catch(err => assert.match(err, errors.malformed, 'should fail on malformed "headers"')), validate.request(valid).then(out => assert.equal(out, valid, 'should not fail with full example')) ]) }) har-validator-5.0.2/test/response.js000066400000000000000000000032021306206060200174160ustar00rootroot00000000000000'use strict' const HARError = require('../lib/error') const invalid = require('./fixtures/response/invalid') const valid = require('./fixtures/response/valid') const validate = require('../lib/promise') const tap = require('tap') const errors = { object: new HARError([{ dataPath: '', message: "should have required property 'status'" }]), array: new HARError([{ dataPath: '', message: 'should be object' }]), undef: new HARError([{ dataPath: '', message: "should have required property 'status'" }]), bodySize: new HARError([{ dataPath: '.bodySize', message: 'should be integer' }]), headers: new HARError([{ dataPath: '.headers', message: 'should be array' }]), malformed: new HARError([{ dataPath: '.headers[0]', message: "should have required property 'name'" }]) } tap.test('response', assert => { assert.plan(7) return Promise.all([ validate.response({}).catch(err => assert.match(err, errors.object, 'should fail with empty object')), validate.response([]).catch(err => assert.match(err, errors.array, 'should fail with empty array')), validate.response(undefined).catch(err => assert.match(err, errors.undef, 'should fail with undefined')), validate.response(invalid.bodySize).catch(err => assert.match(err, errors.bodySize, 'should fail on bad "bodySize"')), validate.response(invalid.headers).catch(err => assert.match(err, errors.headers, 'should fail on bad "headers"')), validate.response(invalid.malformed).catch(err => assert.match(err, errors.malformed, 'should fail on malformed "headers"')), validate.response(valid).then(out => assert.equal(out, valid, 'should not fail with full example')) ]) })