├── .gitignore ├── .jshintrc ├── test ├── fixtures │ ├── index.js │ ├── har │ │ ├── index.js │ │ ├── invalid │ │ │ ├── index.js │ │ │ ├── creator.json │ │ │ ├── version.json │ │ │ └── date.json │ │ └── valid.json │ ├── request │ │ ├── index.js │ │ ├── invalid │ │ │ ├── index.js │ │ │ ├── url.json │ │ │ ├── headers.json │ │ │ └── malformed.json │ │ └── valid.json │ └── response │ │ ├── index.js │ │ ├── invalid │ │ ├── index.js │ │ ├── bodySize.json │ │ ├── headers.json │ │ └── malformed.json │ │ └── valid.json ├── index.js ├── request.js ├── log.js └── response.js ├── src ├── schemas │ ├── har.json │ ├── cache.json │ ├── pageTimings.json │ ├── record.json │ ├── creator.json │ ├── cacheEntry.json │ ├── content.json │ ├── log.json │ ├── cookie.json │ ├── page.json │ ├── timings.json │ ├── postData.json │ ├── response.json │ ├── request.json │ ├── entry.json │ └── index.js ├── error.js └── index.js ├── .travis.yml ├── .editorconfig ├── LICENSE ├── bin └── har-validator ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | node_modules 3 | coverage* 4 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": true, 3 | "node": true 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/fixtures/har/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/fixtures/request/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/fixtures/response/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/fixtures/har/invalid/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/fixtures/request/invalid/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /test/fixtures/response/invalid/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = require('require-directory')(module) 4 | -------------------------------------------------------------------------------- /src/schemas/har.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "log" 5 | ], 6 | "properties": { 7 | "log": { 8 | "$ref": "#log" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/har/invalid/creator.json: -------------------------------------------------------------------------------- 1 | { 2 | "log": { 3 | "version": "1.2", 4 | "creator": { 5 | "name": "" 6 | }, 7 | "pages": [], 8 | "entries": [] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - iojs 5 | - 0.10 6 | - 0.11 7 | - 0.12 8 | 9 | script: npm test 10 | 11 | after_script: 12 | - npm run coverage 13 | - npm run codeclimate 14 | -------------------------------------------------------------------------------- /test/fixtures/har/invalid/version.json: -------------------------------------------------------------------------------- 1 | { 2 | "log": { 3 | "version": 1.2, 4 | "creator": { 5 | "name": "", 6 | "version": "" 7 | }, 8 | "pages": [], 9 | "entries": {} 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/error.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | function ValidationError (errors) { 4 | this.name = 'ValidationError' 5 | this.errors = errors 6 | } 7 | 8 | ValidationError.prototype = Error.prototype 9 | 10 | module.exports = ValidationError 11 | -------------------------------------------------------------------------------- /test/fixtures/request/invalid/url.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "mockbin.com", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": [], 6 | "queryString": [], 7 | "cookies": [], 8 | "headersSize": 0, 9 | "bodySize": 0 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/request/invalid/headers.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": {}, 6 | "queryString": [], 7 | "cookies": [], 8 | "headersSize": 0, 9 | "bodySize": 0 10 | } 11 | -------------------------------------------------------------------------------- /src/schemas/cache.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": { 3 | "beforeRequest": { 4 | "$ref": "#cacheEntry" 5 | }, 6 | "afterRequest": { 7 | "$ref": "#cacheEntry" 8 | }, 9 | "comment": { 10 | "type": "string" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /test/fixtures/request/invalid/malformed.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": [ 6 | { 7 | "foo": "bar" 8 | } 9 | ], 10 | "queryString": [], 11 | "cookies": [], 12 | "headersSize": 0, 13 | "bodySize": 0 14 | } 15 | -------------------------------------------------------------------------------- /src/schemas/pageTimings.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "properties": { 4 | "onContentLoad": { 5 | "type": "number", 6 | "min": -1 7 | }, 8 | "onLoad": { 9 | "type": "number", 10 | "min": -1 11 | }, 12 | "comment": { 13 | "type": "string" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/schemas/record.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "name", 5 | "value" 6 | ], 7 | "properties": { 8 | "name": { 9 | "type": "string" 10 | }, 11 | "value": { 12 | "type": "string" 13 | }, 14 | "comment": { 15 | "type": "string" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/response/invalid/bodySize.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 200, 3 | "statusText": "OK", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": [], 6 | "cookies": [], 7 | "content": { 8 | "size": 0, 9 | "mimeType": "text/html" 10 | }, 11 | "redirectURL": "", 12 | "headersSize": 0, 13 | "bodySize": "0" 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/response/invalid/headers.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 200, 3 | "statusText": "OK", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": {}, 6 | "cookies": [], 7 | "content": { 8 | "size": 0, 9 | "mimeType": "text/html" 10 | }, 11 | "redirectURL": "", 12 | "headersSize": 0, 13 | "bodySize": 0 14 | } 15 | -------------------------------------------------------------------------------- /src/schemas/creator.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "name", 5 | "version" 6 | ], 7 | "properties": { 8 | "name": { 9 | "type": "string" 10 | }, 11 | "version": { 12 | "type": "string" 13 | }, 14 | "comment": { 15 | "type": "string" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/response/invalid/malformed.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 200, 3 | "statusText": "OK", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": [ 6 | { 7 | "foo": "bar" 8 | } 9 | ], 10 | "cookies": [], 11 | "content": { 12 | "size": 0, 13 | "mimeType": "text/html" 14 | }, 15 | "redirectURL": "", 16 | "headersSize": 0, 17 | "bodySize": 0 18 | } 19 | -------------------------------------------------------------------------------- /src/schemas/cacheEntry.json: -------------------------------------------------------------------------------- 1 | { 2 | "optional": true, 3 | "required": [ 4 | "lastAccess", 5 | "eTag", 6 | "hitCount" 7 | ], 8 | "properties": { 9 | "expires": { 10 | "type": "string" 11 | }, 12 | "lastAccess": { 13 | "type": "string" 14 | }, 15 | "eTag": { 16 | "type": "string" 17 | }, 18 | "hitCount": { 19 | "type": "integer" 20 | }, 21 | "comment": { 22 | "type": "string" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/schemas/content.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "size", 5 | "mimeType" 6 | ], 7 | "properties": { 8 | "size": { 9 | "type": "integer" 10 | }, 11 | "compression": { 12 | "type": "integer" 13 | }, 14 | "mimeType": { 15 | "type": "string" 16 | }, 17 | "text": { 18 | "type": "string" 19 | }, 20 | "encoding": { 21 | "type": "string" 22 | }, 23 | "comment": { 24 | "type": "string" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/fixtures/har/invalid/date.json: -------------------------------------------------------------------------------- 1 | { 2 | "log": { 3 | "version": "1.2", 4 | "creator": { 5 | "name": "WebInspector", 6 | "version": "537.36" 7 | }, 8 | "pages": [ 9 | { 10 | "startedDateTime": "2015-02-10T07:33:17.146", 11 | "id": "page_1", 12 | "title": "http://mockbin.com/", 13 | "pageTimings": { 14 | "onContentLoad": 627.4099349975586, 15 | "onLoad": 1266.5300369262695 16 | } 17 | } 18 | ], 19 | "entries": [] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/schemas/log.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "version", 5 | "creator", 6 | "entries" 7 | ], 8 | "properties": { 9 | "version": { 10 | "type": "string" 11 | }, 12 | "creator": { 13 | "$ref": "#creator" 14 | }, 15 | "browser": { 16 | "$ref": "#creator" 17 | }, 18 | "pages": { 19 | "type": "array", 20 | "items": { 21 | "$ref": "#page" 22 | } 23 | }, 24 | "entries": { 25 | "type": "array", 26 | "items": { 27 | "$ref": "#entry" 28 | } 29 | }, 30 | "comment": { 31 | "type": "string" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/schemas/cookie.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "name", 5 | "value" 6 | ], 7 | "properties": { 8 | "name": { 9 | "type": "string" 10 | }, 11 | "value": { 12 | "type": "string" 13 | }, 14 | "path": { 15 | "type": "string" 16 | }, 17 | "domain": { 18 | "type": "string" 19 | }, 20 | "expires": { 21 | "type": ["string", "null"], 22 | "format": "date-time" 23 | }, 24 | "httpOnly": { 25 | "type": "boolean" 26 | }, 27 | "secure": { 28 | "type": "boolean" 29 | }, 30 | "comment": { 31 | "type": "string" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/schemas/page.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "optional": true, 4 | "required": [ 5 | "startedDateTime", 6 | "id", 7 | "title", 8 | "pageTimings" 9 | ], 10 | "properties": { 11 | "startedDateTime": { 12 | "type": "string", 13 | "format": "date-time", 14 | "pattern": "^(\\d{4})(-)?(\\d\\d)(-)?(\\d\\d)(T)?(\\d\\d)(:)?(\\d\\d)(:)?(\\d\\d)(\\.\\d+)?(Z|([+-])(\\d\\d)(:)?(\\d\\d))" 15 | }, 16 | "id": { 17 | "type": "string", 18 | "unique": true 19 | }, 20 | "title": { 21 | "type": "string" 22 | }, 23 | "pageTimings": { 24 | "$ref": "#pageTimings" 25 | }, 26 | "comment": { 27 | "type": "string" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/schemas/timings.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": [ 3 | "send", 4 | "wait", 5 | "receive" 6 | ], 7 | "properties": { 8 | "dns": { 9 | "type": "number", 10 | "min": -1 11 | }, 12 | "connect": { 13 | "type": "number", 14 | "min": -1 15 | }, 16 | "blocked": { 17 | "type": "number", 18 | "min": -1 19 | }, 20 | "send": { 21 | "type": "number", 22 | "min": -1 23 | }, 24 | "wait": { 25 | "type": "number", 26 | "min": -1 27 | }, 28 | "receive": { 29 | "type": "number", 30 | "min": -1 31 | }, 32 | "ssl": { 33 | "type": "number", 34 | "min": -1 35 | }, 36 | "comment": { 37 | "type": "string" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 3 | 'use strict' 4 | 5 | var fixtures = require('./fixtures') 6 | var validate = require('..') 7 | 8 | var should = require('should') 9 | 10 | describe('Validator', function () { 11 | it('should throw error', function (done) { 12 | validate({}).should.be.false 13 | 14 | validate({}, function (err, valid) { 15 | valid.should.be.false 16 | err.should.be.Error 17 | 18 | done() 19 | }) 20 | }) 21 | 22 | it('should not throw error', function (done) { 23 | validate(fixtures.har.valid).should.be.true 24 | 25 | validate(fixtures.har.valid, function (err, valid) { 26 | valid.should.be.true 27 | should.not.exist(err) 28 | 29 | done() 30 | }) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /test/fixtures/request/valid.json: -------------------------------------------------------------------------------- 1 | { 2 | "method": "GET", 3 | "url": "http://mockbin.com/", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": [ 6 | { 7 | "name": "DNT", 8 | "value": "1" 9 | }, 10 | { 11 | "name": "Accept-Encoding", 12 | "value": "gzip, deflate, sdch" 13 | }, 14 | { 15 | "name": "Host", 16 | "value": "mockbin.com" 17 | }, 18 | { 19 | "name": "Connection", 20 | "value": "keep-alive" 21 | } 22 | ], 23 | "queryString": [], 24 | "cookies": [ 25 | { 26 | "name": "foo", 27 | "expires": "2015-02-10T07:33:17.146Z", 28 | "value": "bar", 29 | "httpOnly": false, 30 | "secure": false 31 | } 32 | ], 33 | "headersSize": 482, 34 | "bodySize": 0 35 | } 36 | -------------------------------------------------------------------------------- /src/schemas/postData.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "optional": true, 4 | "required": [ 5 | "mimeType" 6 | ], 7 | "properties": { 8 | "mimeType": { 9 | "type": "string" 10 | }, 11 | "text": { 12 | "type": "string" 13 | }, 14 | "params": { 15 | "type": "array", 16 | "required": [ 17 | "name" 18 | ], 19 | "properties": { 20 | "name": { 21 | "type": "string" 22 | }, 23 | "value": { 24 | "type": "string" 25 | }, 26 | "fileName": { 27 | "type": "string" 28 | }, 29 | "contentType": { 30 | "type": "string" 31 | }, 32 | "comment": { 33 | "type": "string" 34 | } 35 | } 36 | }, 37 | "comment": { 38 | "type": "string" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var schemas = require('./schemas') 4 | var ValidationError = require('./error') 5 | var validator = require('@postman/is-my-json-valid') 6 | 7 | var runner = function (schema, data, cb) { 8 | var validate = validator(schema, { 9 | greedy: true, 10 | verbose: true, 11 | schemas: schemas 12 | }) 13 | 14 | var valid = false 15 | 16 | if (data !== undefined) { 17 | // execute is-my-json-valid 18 | valid = validate(data) 19 | } 20 | 21 | // callback? 22 | if (!cb) { 23 | return validate.errors ? false : true 24 | } else { 25 | return cb(validate.errors ? new ValidationError(validate.errors) : null, valid) 26 | } 27 | 28 | return valid 29 | } 30 | 31 | module.exports = function (data, cb) { 32 | return runner(schemas.har, data, cb) 33 | } 34 | 35 | Object.keys(schemas).map(function (name) { 36 | module.exports[name] = function (data, cb) { 37 | return runner(schemas[name], data, cb) 38 | } 39 | }) 40 | -------------------------------------------------------------------------------- /src/schemas/response.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "status", 5 | "statusText", 6 | "httpVersion", 7 | "cookies", 8 | "headers", 9 | "content", 10 | "redirectURL", 11 | "headersSize", 12 | "bodySize" 13 | ], 14 | "properties": { 15 | "status": { 16 | "type": "integer" 17 | }, 18 | "statusText": { 19 | "type": "string" 20 | }, 21 | "httpVersion": { 22 | "type": "string" 23 | }, 24 | "cookies": { 25 | "type": "array", 26 | "items": { 27 | "$ref": "#cookie" 28 | } 29 | }, 30 | "headers": { 31 | "type": "array", 32 | "items": { 33 | "$ref": "#record" 34 | } 35 | }, 36 | "content": { 37 | "$ref": "#content" 38 | }, 39 | "redirectURL": { 40 | "type": "string" 41 | }, 42 | "headersSize": { 43 | "type": "integer" 44 | }, 45 | "bodySize": { 46 | "type": "integer" 47 | }, 48 | "comment": { 49 | "type": "string" 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/schemas/request.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "method", 5 | "url", 6 | "httpVersion", 7 | "cookies", 8 | "headers", 9 | "queryString", 10 | "headersSize", 11 | "bodySize" 12 | ], 13 | "properties": { 14 | "method": { 15 | "type": "string" 16 | }, 17 | "url": { 18 | "type": "string", 19 | "format": "uri-template" 20 | }, 21 | "httpVersion": { 22 | "type": "string" 23 | }, 24 | "cookies": { 25 | "type": "array", 26 | "items": { 27 | "$ref": "#cookie" 28 | } 29 | }, 30 | "headers": { 31 | "type": "array", 32 | "items": { 33 | "$ref": "#record" 34 | } 35 | }, 36 | "queryString": { 37 | "type": "array" 38 | }, 39 | "postData": { 40 | "$ref": "#postData" 41 | }, 42 | "headersSize": { 43 | "type": "integer" 44 | }, 45 | "bodySize": { 46 | "type": "integer" 47 | }, 48 | "comment": { 49 | "type": "string" 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/schemas/entry.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "optional": true, 4 | "required": [ 5 | "startedDateTime", 6 | "time", 7 | "request", 8 | "response", 9 | "cache", 10 | "timings" 11 | ], 12 | "properties": { 13 | "pageref": { 14 | "type": "string" 15 | }, 16 | "startedDateTime": { 17 | "type": "string", 18 | "format": "date-time", 19 | "pattern": "^(\\d{4})(-)?(\\d\\d)(-)?(\\d\\d)(T)?(\\d\\d)(:)?(\\d\\d)(:)?(\\d\\d)(\\.\\d+)?(Z|([+-])(\\d\\d)(:)?(\\d\\d))" 20 | }, 21 | "time": { 22 | "type": "number", 23 | "min": 0 24 | }, 25 | "request": { 26 | "$ref": "#request" 27 | }, 28 | "response": { 29 | "$ref": "#response" 30 | }, 31 | "cache": { 32 | "$ref": "#cache" 33 | }, 34 | "timings": { 35 | "$ref": "#timings" 36 | }, 37 | "serverIPAddress": { 38 | "type": "string", 39 | "format": "ipv4" 40 | }, 41 | "connection": { 42 | "type": "string" 43 | }, 44 | "comment": { 45 | "type": "string" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/fixtures/response/valid.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": 200, 3 | "statusText": "OK", 4 | "httpVersion": "HTTP/1.1", 5 | "headers": [ 6 | { 7 | "name": "X-Response-Time", 8 | "value": "3.419ms" 9 | }, 10 | { 11 | "name": "Date", 12 | "value": "Tue, 10 Feb 2015 07:33:16 GMT" 13 | }, 14 | { 15 | "name": "Vary", 16 | "value": "Accept, Accept-Encoding" 17 | }, 18 | { 19 | "name": "X-Powered-By", 20 | "value": "mockbin.com" 21 | }, 22 | { 23 | "name": "Transfer-Encoding", 24 | "value": "chunked" 25 | }, 26 | { 27 | "name": "Content-Type", 28 | "value": "text/html; charset=utf-8" 29 | }, 30 | { 31 | "name": "Content-Encoding", 32 | "value": "gzip" 33 | }, 34 | { 35 | "name": "Connection", 36 | "value": "keep-alive" 37 | } 38 | ], 39 | "cookies": [], 40 | "content": { 41 | "size": 30, 42 | "mimeType": "text/html", 43 | "compression": 0, 44 | "text": "ALL YOUR BASE ARE BELONG TO US" 45 | }, 46 | "redirectURL": "", 47 | "headersSize": 430, 48 | "bodySize": 30 49 | } 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ahmad Nassri (https://www.ahmadnassri.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/har-validator: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict' 4 | 5 | var Promise = require('bluebird') 6 | 7 | var chalk = require('chalk') 8 | var cmd = require('commander') 9 | var fs = Promise.promisifyAll(require('fs')) 10 | var path = require('path') 11 | var pkg = require('../package.json') 12 | var validate = Promise.promisifyAll(require('..')) 13 | 14 | cmd 15 | .version(pkg.version) 16 | .usage('[options] ') 17 | .option('-s, --schema [name]', 'validate schema name (log, request, response, etc ...)') 18 | .parse(process.argv) 19 | 20 | if (!cmd.args.length) { 21 | cmd.help() 22 | } 23 | 24 | if (!cmd.schema) { 25 | cmd.schema = 'har' 26 | } 27 | 28 | cmd.args.map(function (fileName) { 29 | var file = chalk.yellow.italic(path.basename(fileName)) 30 | 31 | fs.readFileAsync(fileName) 32 | .then(JSON.parse) 33 | .then(validate[cmd.schema + 'Async']) 34 | .then(function () { 35 | console.log('%s [%s] is valid', chalk.green('✓'), file) 36 | }) 37 | .catch(SyntaxError, function (e) { 38 | console.error('%s [%s] failed to read JSON: %s', chalk.red('✖'), file, chalk.red(e.message)) 39 | }) 40 | .catch(function (e) { 41 | e.errors.map(function (err) { 42 | console.error('%s [%s] failed validation: (%s: %s) %s', chalk.red('✖'), file, chalk.cyan.italic(err.field), chalk.magenta.italic(err.value), chalk.red(err.message)) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.6.5", 3 | "name": "har-validator-fsless", 4 | "description": "Extremely fast HTTP Archive (HAR) validator using JSON Schema", 5 | "author": { 6 | "name": "Abhijit Kane", 7 | "email": "abhijit@getpostman.com" 8 | }, 9 | "homepage": "https://github.com/postmanlabs/har-validator", 10 | "license": "MIT", 11 | "main": "./src/index.js", 12 | "bin": { 13 | "har-validator-fsless": "./bin/har-validator" 14 | }, 15 | "keywords": [ 16 | "har", 17 | "http", 18 | "archive", 19 | "validate", 20 | "validator" 21 | ], 22 | "engines": { 23 | "node": ">=0.10" 24 | }, 25 | "files": [ 26 | "bin", 27 | "src" 28 | ], 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/postmanlabs/har-validator.git" 32 | }, 33 | "bugs": { 34 | "url": "https://github.com/postmanlabs/har-validator/issues" 35 | }, 36 | "scripts": { 37 | "test": "mocha --reporter spec", 38 | "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha", 39 | "codeclimate": "codeclimate < coverage/lcov.info" 40 | }, 41 | "devDependencies": { 42 | "codeclimate-test-reporter": "0.0.4", 43 | "istanbul": "^0.3.11", 44 | "mocha": "^2.2.1", 45 | "should": "^5.2.0", 46 | "standard": "^3.3.0" 47 | }, 48 | "dependencies": { 49 | "bluebird": "^2.9.21", 50 | "chalk": "^1.0.0", 51 | "commander": "^2.7.1", 52 | "@postman/is-my-json-valid": "2.18.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/schemas/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var schemas = { 4 | cache: require('./cache.json'), 5 | cacheEntry: require('./cacheEntry.json'), 6 | content: require('./content.json'), 7 | cookie: require('./cookie.json'), 8 | creator: require('./creator.json'), 9 | entry: require('./entry.json'), 10 | har: require('./har.json'), 11 | log: require('./log.json'), 12 | page: require('./page.json'), 13 | pageTimings: require('./pageTimings.json'), 14 | postData: require('./postData.json'), 15 | record: require('./record.json'), 16 | request: require('./request.json'), 17 | response: require('./response.json'), 18 | timings: require('./timings.json') 19 | } 20 | 21 | // is-my-json-valid does not provide meaningful error messages for external schemas 22 | // this is a workaround 23 | schemas.cache.properties.beforeRequest = schemas.cacheEntry 24 | schemas.cache.properties.afterRequest = schemas.cacheEntry 25 | 26 | schemas.page.properties.pageTimings = schemas.pageTimings 27 | 28 | schemas.request.properties.cookies.items = schemas.cookie 29 | schemas.request.properties.headers.items = schemas.record 30 | 31 | // Fix so that HAR Validator does not blow up with repeated values in the queryString. 32 | // schemas.request.properties.queryString.items = schemas.record 33 | 34 | schemas.request.properties.postData = schemas.postData 35 | 36 | schemas.response.properties.cookies.items = schemas.cookie 37 | schemas.response.properties.headers.items = schemas.record 38 | schemas.response.properties.content = schemas.content 39 | 40 | schemas.entry.properties.request = schemas.request 41 | schemas.entry.properties.response = schemas.response 42 | schemas.entry.properties.cache = schemas.cache 43 | schemas.entry.properties.timings = schemas.timings 44 | 45 | schemas.log.properties.creator = schemas.creator 46 | schemas.log.properties.browser = schemas.creator 47 | schemas.log.properties.pages.items = schemas.page 48 | schemas.log.properties.entries.items = schemas.entry 49 | 50 | schemas.har.properties.log = schemas.log 51 | 52 | module.exports = schemas 53 | -------------------------------------------------------------------------------- /test/request.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 3 | 'use strict' 4 | 5 | var fixtures = require('./fixtures') 6 | var should = require('should') 7 | var validate = require('..') 8 | 9 | describe('Request Only', function () { 10 | it('should fail with empty object', function (done) { 11 | validate.request({}, function (e, valid) { 12 | valid.should.be.false 13 | 14 | e.errors[0].should.have.property('field').and.equal('data.method') 15 | e.errors[0].should.have.property('message').and.equal('is required') 16 | 17 | done() 18 | }) 19 | 20 | }) 21 | 22 | it('should fail with empty array', function (done) { 23 | validate.request([], function (e, valid) { 24 | valid.should.be.false 25 | 26 | e.errors[0].should.have.property('field').and.equal('data') 27 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 28 | 29 | done() 30 | }) 31 | }) 32 | 33 | it('should fail with undefined', function (done) { 34 | validate.request(undefined, function (e, valid) { 35 | valid.should.be.false 36 | 37 | should.not.exist(e) 38 | 39 | done() 40 | }) 41 | }) 42 | 43 | it('should fail on bad "url"', function (done) { 44 | validate.request(fixtures.request.invalid.url, function (e, valid) { 45 | valid.should.be.false 46 | 47 | e.errors[0].should.have.property('field').and.equal('data.url') 48 | e.errors[0].should.have.property('message').and.equal('must be uri format') 49 | 50 | done() 51 | }) 52 | }) 53 | 54 | it('should fail on bad "headers"', function (done) { 55 | validate.request(fixtures.request.invalid.headers, function (e, valid) { 56 | valid.should.be.false 57 | 58 | e.errors[0].should.have.property('field').and.equal('data.headers') 59 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 60 | 61 | done() 62 | }) 63 | }) 64 | 65 | it('should fail on malformed "headers"', function (done) { 66 | validate.request(fixtures.request.invalid.malformed, function (e, valid) { 67 | valid.should.be.false 68 | 69 | e.errors[0].should.have.property('field').and.equal('data.headers.*.name') 70 | e.errors[0].should.have.property('message').and.equal('is required') 71 | 72 | done() 73 | }) 74 | }) 75 | 76 | it('should not fail with full example', function (done) { 77 | validate.request(fixtures.request.valid, function (e, valid) { 78 | valid.should.be.true 79 | 80 | should.not.exist(e) 81 | 82 | done() 83 | }) 84 | }) 85 | }) 86 | -------------------------------------------------------------------------------- /test/log.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 3 | 'use strict' 4 | 5 | var fixtures = require('./fixtures') 6 | var should = require('should') 7 | var validate = require('..') 8 | 9 | describe('Full HAR', function () { 10 | it('should fail with empty object', function (done) { 11 | validate({}, function (e, valid) { 12 | valid.should.be.false 13 | 14 | e.errors[0].should.have.property('field').and.equal('data.log') 15 | e.errors[0].should.have.property('message').and.equal('is required') 16 | 17 | done() 18 | }) 19 | 20 | }) 21 | 22 | it('should fail with empty array', function (done) { 23 | validate.har([], function (e, valid) { 24 | valid.should.be.false 25 | 26 | e.errors[0].should.have.property('field').and.equal('data') 27 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 28 | 29 | done() 30 | }) 31 | }) 32 | 33 | it('should fail with undefined', function (done) { 34 | validate.har(undefined, function (e, valid) { 35 | valid.should.be.false 36 | 37 | should.not.exist(e) 38 | 39 | done() 40 | }) 41 | }) 42 | 43 | it('should fail on bad "log.version"', function (done) { 44 | validate.har(fixtures.har.invalid.version, function (e, valid) { 45 | valid.should.be.false 46 | 47 | e.errors[0].should.have.property('field').and.equal('data.log.version') 48 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 49 | 50 | done() 51 | }) 52 | }) 53 | 54 | it('should fail on bad "log.creator"', function (done) { 55 | validate.har(fixtures.har.invalid.creator, function (e, valid) { 56 | valid.should.be.false 57 | 58 | e.errors[0].should.have.property('field').and.equal('data.log.creator.version') 59 | e.errors[0].should.have.property('message').and.equal('is required') 60 | 61 | done() 62 | }) 63 | }) 64 | 65 | it('should fail on bad "log.pages.*.startedDateTime"', function (done) { 66 | validate.har(fixtures.har.invalid.date, function (e, valid) { 67 | valid.should.be.false 68 | 69 | e.errors[0].should.have.property('field').and.equal('data.log.pages.*.startedDateTime') 70 | e.errors[0].should.have.property('message').and.equal('must be date-time format') 71 | 72 | done() 73 | }) 74 | }) 75 | 76 | it('should not fail with full example', function (done) { 77 | validate.har(fixtures.har.valid, function (e, valid) { 78 | valid.should.be.true 79 | 80 | should.not.exist(e) 81 | 82 | done() 83 | }) 84 | }) 85 | }) 86 | -------------------------------------------------------------------------------- /test/response.js: -------------------------------------------------------------------------------- 1 | /* global describe, it */ 2 | 3 | 'use strict' 4 | 5 | var fixtures = require('./fixtures') 6 | var should = require('should') 7 | var validate = require('..') 8 | 9 | describe('Response Only', function () { 10 | it('should fail with empty object', function (done) { 11 | validate.response({}, function (e, valid) { 12 | valid.should.be.false 13 | 14 | e.errors[0].should.have.property('field').and.equal('data.status') 15 | e.errors[0].should.have.property('message').and.equal('is required') 16 | 17 | done() 18 | }) 19 | 20 | }) 21 | 22 | it('should fail with empty array', function (done) { 23 | validate.response([], function (e, valid) { 24 | valid.should.be.false 25 | 26 | e.errors[0].should.have.property('field').and.equal('data') 27 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 28 | 29 | done() 30 | }) 31 | }) 32 | 33 | it('should fail with undefined', function (done) { 34 | validate.response(undefined, function (e, valid) { 35 | valid.should.be.false 36 | 37 | should.not.exist(e) 38 | 39 | done() 40 | }) 41 | }) 42 | 43 | it('should fail on bad "bodySize"', function (done) { 44 | validate.response(fixtures.response.invalid.bodySize, function (e, valid) { 45 | valid.should.be.false 46 | 47 | e.errors[0].should.have.property('field').and.equal('data.bodySize') 48 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 49 | 50 | done() 51 | }) 52 | }) 53 | 54 | it('should fail on bad "headers"', function (done) { 55 | validate.response(fixtures.response.invalid.headers, function (e, valid) { 56 | valid.should.be.false 57 | 58 | e.errors[0].should.have.property('field').and.equal('data.headers') 59 | e.errors[0].should.have.property('message').and.equal('is the wrong type') 60 | 61 | done() 62 | }) 63 | }) 64 | 65 | it('should fail on malformed "headers"', function (done) { 66 | validate.response(fixtures.response.invalid.malformed, function (e, valid) { 67 | valid.should.be.false 68 | 69 | e.errors[0].should.have.property('field').and.equal('data.headers.*.name') 70 | e.errors[0].should.have.property('message').and.equal('is required') 71 | 72 | done() 73 | }) 74 | }) 75 | 76 | it('should not fail with full example', function (done) { 77 | validate.response(fixtures.response.valid, function (e, valid) { 78 | valid.should.be.true 79 | 80 | should.not.exist(e) 81 | 82 | done() 83 | }) 84 | }) 85 | }) 86 | -------------------------------------------------------------------------------- /test/fixtures/har/valid.json: -------------------------------------------------------------------------------- 1 | { 2 | "log": { 3 | "version": "1.2", 4 | "creator": { 5 | "name": "WebInspector", 6 | "version": "537.36" 7 | }, 8 | "pages": [ 9 | { 10 | "startedDateTime": "2015-02-10T07:33:17.146Z", 11 | "id": "page_1", 12 | "title": "http://mockbin.com/", 13 | "pageTimings": { 14 | "onContentLoad": 627.4099349975586, 15 | "onLoad": 1266.5300369262695 16 | } 17 | } 18 | ], 19 | "entries": [ 20 | { 21 | "startedDateTime": "2015-02-10T07:33:17.146Z", 22 | "time": 181.59985542297363, 23 | "request": { 24 | "method": "GET", 25 | "url": "http://mockbin.com/", 26 | "httpVersion": "HTTP/1.1", 27 | "headers": [ 28 | { 29 | "name": "DNT", 30 | "value": "1" 31 | }, 32 | { 33 | "name": "Accept-Encoding", 34 | "value": "gzip, deflate, sdch" 35 | }, 36 | { 37 | "name": "Host", 38 | "value": "mockbin.com" 39 | }, 40 | { 41 | "name": "Connection", 42 | "value": "keep-alive" 43 | } 44 | ], 45 | "queryString": [], 46 | "cookies": [ 47 | { 48 | "name": "foo", 49 | "expires": "2015-02-10T07:33:17.146Z", 50 | "value": "bar", 51 | "httpOnly": false, 52 | "secure": false 53 | } 54 | ], 55 | "headersSize": 482, 56 | "bodySize": 0 57 | }, 58 | "response": { 59 | "status": 200, 60 | "statusText": "OK", 61 | "httpVersion": "HTTP/1.1", 62 | "headers": [ 63 | { 64 | "name": "X-Response-Time", 65 | "value": "3.419ms" 66 | }, 67 | { 68 | "name": "Date", 69 | "value": "Tue, 10 Feb 2015 07:33:16 GMT" 70 | }, 71 | { 72 | "name": "Vary", 73 | "value": "Accept, Accept-Encoding" 74 | }, 75 | { 76 | "name": "X-Powered-By", 77 | "value": "mockbin.com" 78 | }, 79 | { 80 | "name": "Transfer-Encoding", 81 | "value": "chunked" 82 | }, 83 | { 84 | "name": "Content-Type", 85 | "value": "text/html; charset=utf-8" 86 | }, 87 | { 88 | "name": "Content-Encoding", 89 | "value": "gzip" 90 | }, 91 | { 92 | "name": "Connection", 93 | "value": "keep-alive" 94 | } 95 | ], 96 | "cookies": [], 97 | "content": { 98 | "size": 30, 99 | "mimeType": "text/html", 100 | "compression": 0, 101 | "text": "ALL YOUR BASE ARE BELONG TO US" 102 | }, 103 | "redirectURL": "", 104 | "headersSize": 430, 105 | "bodySize": 30 106 | }, 107 | "cache": {}, 108 | "timings": { 109 | "blocked": 0.381000001652865, 110 | "dns": -1, 111 | "connect": -1, 112 | "send": 0.05899999996472599, 113 | "wait": 179.1829999983744, 114 | "receive": 1.9768554229816289, 115 | "ssl": -1 116 | }, 117 | "connection": "161767", 118 | "pageref": "page_1" 119 | } 120 | ] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HAR Validator [![version][npm-version]][npm-url] [![License][npm-license]][license-url] 2 | 3 | Extremely fast HTTP Archive ([HAR](http://www.softwareishard.com/blog/har-12-spec/)) validator using JSON Schema. 4 | 5 | [![Build Status][travis-image]][travis-url] 6 | [![Downloads][npm-downloads]][npm-url] 7 | [![Code Climate][codeclimate-quality]][codeclimate-url] 8 | [![Coverage Status][codeclimate-coverage]][codeclimate-url] 9 | [![Dependencies][david-image]][david-url] 10 | 11 | ## Install 12 | 13 | ```shell 14 | # to use in cli 15 | npm install --global har-validator 16 | 17 | # to use as a module 18 | npm install --save har-validator 19 | ``` 20 | 21 | ## Usage 22 | 23 | ``` 24 | 25 | Usage: har-validator [options] 26 | 27 | Options: 28 | 29 | -h, --help output usage information 30 | -V, --version output the version number 31 | -s, --schema [name] validate schema name (log, request, response, etc ...) 32 | 33 | ``` 34 | 35 | ###### Example 36 | 37 | ```shell 38 | har-validator har.json 39 | 40 | har-validator --schema request request.json 41 | ``` 42 | 43 | ## API 44 | 45 | ### Validate(data [, callback]) 46 | 47 | Returns `true` or `false`. 48 | 49 | - **data**: `Object` *(Required)* 50 | a full [HAR](http://www.softwareishard.com/blog/har-12-spec/) object 51 | 52 | - **callback**: `Function` 53 | gets two arguments (err, valid) 54 | 55 | ```js 56 | var HAR = require('./har.json'); 57 | var validate = require('har-validator'); 58 | 59 | validate(HAR, function (e, valid) { 60 | if (e) console.log(e.errors) 61 | 62 | if (valid) console.log('horray!'); 63 | }); 64 | ``` 65 | 66 | ### Validate.log(data [, callback]) 67 | 68 | Returns `true` or `false`. 69 | 70 | - **data**: `Object` *(Required)* 71 | a [log](http://www.softwareishard.com/blog/har-12-spec/#log) object 72 | 73 | - **callback**: `Function` 74 | gets two arguments (err, valid) 75 | 76 | ```js 77 | var validate = require('har-validator'); 78 | 79 | validate.log(data, function (e, valid) { 80 | if (e) console.log(e.errors) 81 | }); 82 | ``` 83 | 84 | ### Validate.cache(data [, callback]) 85 | 86 | Returns `true` or `false`. 87 | 88 | - **data**: `Object` *(Required)* 89 | a [cache](http://www.softwareishard.com/blog/har-12-spec/#cache) object 90 | 91 | - **callback**: `Function` 92 | gets two arguments (err, valid) 93 | 94 | ```js 95 | var validate = require('har-validator'); 96 | 97 | validate.cache(data, function (e, valid) { 98 | if (e) console.log(e.errors) 99 | }); 100 | ``` 101 | 102 | ### Validate.cacheEntry(data [, callback]) 103 | 104 | Returns `true` or `false`. 105 | 106 | - **data**: `Object` *(Required)* 107 | a ["beforeRequest" or "afterRequest"](http://www.softwareishard.com/blog/har-12-spec/#cache) objects 108 | 109 | - **callback**: `Function` 110 | gets two arguments (err, valid) 111 | 112 | ```js 113 | var validate = require('har-validator'); 114 | 115 | validate.cacheEntry(data, function (e, valid) { 116 | if (e) console.log(e.errors) 117 | }); 118 | ``` 119 | 120 | ### Validate.content(data [, callback]) 121 | 122 | Returns `true` or `false`. 123 | 124 | - **data**: `Object` *(Required)* 125 | a [content](http://www.softwareishard.com/blog/har-12-spec/#content) object 126 | 127 | - **callback**: `Function` 128 | gets two arguments (err, valid) 129 | 130 | ```js 131 | var validate = require('har-validator'); 132 | 133 | validate.content(data, function (e, valid) { 134 | if (e) console.log(e.errors) 135 | }); 136 | ``` 137 | 138 | ### Validate.cookie(data [, callback]) 139 | 140 | Returns `true` or `false`. 141 | 142 | - **data**: `Object` *(Required)* 143 | a [cookie](http://www.softwareishard.com/blog/har-12-spec/#cookies) object 144 | 145 | - **callback**: `Function` 146 | gets two arguments (err, valid) 147 | 148 | ```js 149 | var validate = require('har-validator'); 150 | 151 | validate.cookie(data, function (e, valid) { 152 | if (e) console.log(e.errors) 153 | }); 154 | ``` 155 | 156 | ### Validate.creator(data [, callback]) 157 | 158 | Returns `true` or `false`. 159 | 160 | - **data**: `Object` *(Required)* 161 | a [creator](http://www.softwareishard.com/blog/har-12-spec/#creator) object 162 | 163 | - **callback**: `Function` 164 | gets two arguments (err, valid) 165 | 166 | ```js 167 | var validate = require('har-validator'); 168 | 169 | validate.creator(data, function (e, valid) { 170 | if (e) console.log(e.errors) 171 | }); 172 | ``` 173 | 174 | ### Validate.entry(data [, callback]) 175 | 176 | Returns `true` or `false`. 177 | 178 | - **data**: `Object` *(Required)* 179 | a [entry](http://www.softwareishard.com/blog/har-12-spec/#entries) object 180 | 181 | - **callback**: `Function` 182 | gets two arguments (err, valid) 183 | 184 | ```js 185 | var validate = require('har-validator'); 186 | 187 | validate.entry(data, function (e, valid) { 188 | if (e) console.log(e.errors) 189 | }); 190 | ``` 191 | 192 | ### Validate.log(data [, callback]) 193 | 194 | alias of [`Validate(data [, callback])`](#validate-data-callback-) 195 | 196 | ### Validate.page(data [, callback]) 197 | 198 | Returns `true` or `false`. 199 | 200 | - **data**: `Object` *(Required)* 201 | a [page](http://www.softwareishard.com/blog/har-12-spec/#pages) object 202 | 203 | - **callback**: `Function` 204 | gets two arguments (err, valid) 205 | 206 | ```js 207 | var validate = require('har-validator'); 208 | 209 | validate.page(data, function (e, valid) { 210 | if (e) console.log(e.errors) 211 | }); 212 | ``` 213 | 214 | ### Validate.pageTimings(data [, callback]) 215 | 216 | Returns `true` or `false`. 217 | 218 | - **data**: `Object` *(Required)* 219 | a [pageTimings](http://www.softwareishard.com/blog/har-12-spec/#pageTimings) object 220 | 221 | - **callback**: `Function` 222 | gets two arguments (err, valid) 223 | 224 | ```js 225 | var validate = require('har-validator'); 226 | 227 | validate.pageTimings(data, function (e, valid) { 228 | if (e) console.log(e.errors) 229 | }); 230 | ``` 231 | 232 | ### Validate.postData(data [, callback]) 233 | 234 | Returns `true` or `false`. 235 | 236 | - **data**: `Object` *(Required)* 237 | a [postData](http://www.softwareishard.com/blog/har-12-spec/#postData) object 238 | 239 | - **callback**: `Function` 240 | gets two arguments (err, valid) 241 | 242 | ```js 243 | var validate = require('har-validator'); 244 | 245 | validate.postData(data, function (e, valid) { 246 | if (e) console.log(e.errors) 247 | }); 248 | ``` 249 | 250 | ### Validate.record(data [, callback]) 251 | 252 | Returns `true` or `false`. 253 | 254 | - **data**: `Object` *(Required)* 255 | a [record](http://www.softwareishard.com/blog/har-12-spec/#headers) object 256 | 257 | - **callback**: `Function` 258 | gets two arguments (err, valid) 259 | 260 | ```js 261 | var validate = require('har-validator'); 262 | 263 | validate.record(data, function (e, valid) { 264 | if (e) console.log(e.errors) 265 | }); 266 | ``` 267 | 268 | ### Validate.request(data [, callback]) 269 | 270 | Returns `true` or `false`. 271 | 272 | - **data**: `Object` *(Required)* 273 | a [request](http://www.softwareishard.com/blog/har-12-spec/#request) object 274 | 275 | - **callback**: `Function` 276 | gets two arguments (err, valid) 277 | 278 | ```js 279 | var validate = require('har-validator'); 280 | 281 | validate.request(data, function (e, valid) { 282 | if (e) console.log(e.errors) 283 | }); 284 | ``` 285 | 286 | ### Validate.response(data [, callback]) 287 | 288 | Returns `true` or `false`. 289 | 290 | - **data**: `Object` *(Required)* 291 | a [response](http://www.softwareishard.com/blog/har-12-spec/#response) object 292 | 293 | - **callback**: `Function` 294 | gets two arguments (err, valid) 295 | 296 | ```js 297 | var validate = require('har-validator'); 298 | 299 | validate.cacheEntry(data, function (e, valid) { 300 | if (e) console.log(e.errors) 301 | }); 302 | ``` 303 | 304 | ### Validate.timings(data [, callback]) 305 | 306 | Returns `true` or `false`. 307 | 308 | - **data**: `Object` *(Required)* 309 | a [timings](http://www.softwareishard.com/blog/har-12-spec/#timings) object 310 | 311 | - **callback**: `Function` 312 | gets two arguments (err, valid) 313 | 314 | ```js 315 | var validate = require('har-validator'); 316 | 317 | validate.timings(data, function (e, valid) { 318 | if (e) console.log(e.errors) 319 | }); 320 | ``` 321 | 322 | ## License 323 | 324 | [MIT](LICENSE) © [Ahmad Nassri](https://www.ahmadnassri.com) 325 | 326 | [license-url]: https://github.com/ahmadnassri/har-validator/blob/master/LICENSE 327 | 328 | [travis-url]: https://travis-ci.org/ahmadnassri/har-validator 329 | [travis-image]: https://img.shields.io/travis/ahmadnassri/har-validator.svg?style=flat-square 330 | 331 | [npm-url]: https://www.npmjs.com/package/har-validator 332 | [npm-license]: https://img.shields.io/npm/l/har-validator.svg?style=flat-square 333 | [npm-version]: https://img.shields.io/npm/v/har-validator.svg?style=flat-square 334 | [npm-downloads]: https://img.shields.io/npm/dm/har-validator.svg?style=flat-square 335 | 336 | [codeclimate-url]: https://codeclimate.com/github/ahmadnassri/har-validator 337 | [codeclimate-quality]: https://img.shields.io/codeclimate/github/ahmadnassri/har-validator.svg?style=flat-square 338 | [codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/ahmadnassri/har-validator.svg?style=flat-square 339 | 340 | [david-url]: https://david-dm.org/ahmadnassri/har-validator 341 | [david-image]: https://img.shields.io/david/ahmadnassri/har-validator.svg?style=flat-square 342 | --------------------------------------------------------------------------------