Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

io-ts-fuzzer

holvonix-open131Apache-2.04.3.2TypeScript support: included

Fuzzing for io-ts codecs and types

io-ts, codecs, fuzzer, fuzzing, security

readme

io-ts-fuzzer - Fuzzing for io-ts codecs and types

License npm Build Status GitHub last commit codecov Dependabot Status DeepScan grade Code Style: Google npm bundle size semantic-release

io-ts-fuzzer lets you generate examples of a given io-ts type.

Please note: API elements marked @experimental may be changed in breaking ways (including removal) without a major version release. Don't use such APIs if that's not acceptable for you.

Quick Start

After yarn add fp-ts io-ts io-ts-fuzzer...

import * as t from 'io-ts';
import * as fuzz from 'io-ts-fuzzer';

// Fuzzers for common types
const r = fuzz.createCoreRegistry();

// Type to fuzz
const target = t.union([t.string, t.type({ n: t.number, b: t.boolean })]);

// Builds a particular fuzzer from the registry.
const fuzzer = fuzz.exampleGenerator(r, target);

// Make examples. The input number and context
// fully determines the output example.
for (const n of new Array(10).keys()) {
  console.log(JSON.stringify(fuzzer.encode([n, fuzz.fuzzContext()])));
}

See examples/quickstart/index.ts.

Types Supported

Currently supports (along with their closure under composition):

  • t.array
  • t.boolean
  • t.exact
  • t.Int
  • t.intersection
  • t.keyof
  • t.literal
  • t.null
  • t.number
  • t.partial
  • t.readonly
  • t.readonlyArray
  • t.record
  • t.recursive
  • t.string
  • t.tuple
  • t.type (interface)
  • t.undefined
  • t.union
  • t.unknown
  • t.UnknownArray
  • t.UnknownRecord
  • t.void

If you yarn add monocle-ts io-ts-types and register the io-ts-types extra fuzzers via r.register(...await loadIoTsTypesFuzzers()), the following additional types will be supported:

  • date
  • BooleanFromString
  • DateFromISOString
  • DateFromNumber
  • DateFromUnixTime
  • IntFromString
  • NonEmptyString
  • NumberFromString
  • UUID
  • regexp

The following io-ts-types are composed of core types and you do not need to loadIoTsTypesFuzzers to fuzz them:

  • either
  • option

How To

Generate Conforming Examples and Verifying Decoder Behavior

Given a d = t.Decoder<I,A> (aka a t.Type), fuzz.exampleGenerator will build a t.Encoder<[number,FuzzContext],I> that will give example instances of I. The example instances should all pass on d.decode (which should return an identical example in the case of basic types). No exceptions should be thrown.

Configure Core Fuzzers

The FluentRegistry interface lets you easily configure certain core fuzzers, currently:

  • maximum array length (array, readonlyArray, UnknownArray)
  • extra properties inserted into partial and type (interface) objects
  • type used to fuzz unknown types
  • maximum record count (record, UnknownRecord)

Fuzz Recursive Types

When fuzzing recursive types, you can provide to the context a maxRecursionHint which specifies the requested maximum instantiations of any recursive type in a single path. Note that this is the maximum depth of recursive types, not all types. If the recursive depth has been reached, fuzzers that have a choice of which child(ren) to instantiate (like unions, partials, or arrays) will attempt to choose children that won't recurse.

Note this is only a hint -- sometimes the type definition won't allow the fuzzer to choose such a non-recursive path (and you'll get a stack limit error when attempting to generate the actual example from the generator).

Generate Variations of a Type

TODO

Piping Fuzzers

TODO

License

Read the LICENSE for details.
The entire NOTICE file serves as the NOTICE that must be included under Section 4d of the License.


# io-ts-fuzzer

This product contains software originally developed by Holvonix LLC.
Original Repository: https://github.com/holvonix-open/io-ts-fuzzer

Copyright (c) 2019 Holvonix LLC. All rights reserved.

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

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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Dependencies may have their own licenses.

changelog

4.3.2 (2019-11-12)

🐛 Bug Fixes

🧦 Miscellaneous

  • deps: bump seedrandom from 3.0.3 to 3.0.5 (#39) ()
  • deps-dev: bump @holvonix-open/release-config-js (#48) ()
  • deps-dev: bump @holvonix-open/release-config-js (#80) ()

4.3.1 (2019-08-28)

🐛 Bug Fixes

  • deps-dev: bump typescript from 3.5.3 to 3.6.2 (#30) (dfe4b31)

🧦 Miscellaneous

  • deps-dev: bump @holvonix-open/release-config-js (#29) (f57c47f)

4.3.0 (2019-08-25)

🌟🚀 Features

  • fluent record fuzzer configuration (b0a20bd)

4.2.1 (2019-08-25)

🐛 Bug Fixes

  • correct IOTSF0004 error message (e69009d)

💄 Polish

  • label record and unknownrecord as supported (9251714)

4.2.0 (2019-08-25)

🌟🚀 Features

  • support t.record and t.UnknownRecord, closes #27 (#28) (b60591f)

📖 Documentation

  • delete legacy bug template (d03195a)

🧦 Miscellaneous

  • deps-dev: bump @holvonix-open/release-config-js (#21) (ceaab1b)
  • deps-dev: bump @holvonix-open/release-config-js (#22) (2fc34c6)
  • stale issues (40c0d46)
  • deps-dev: bump @holvonix-open/release-config-js (#23) (dc4ac16)
  • deps-dev: bump @types/node from 12.7.1 to 12.7.2 (#24) (edf12b5)
  • deps-dev: bump concurrently from 4.1.1 to 4.1.2 (#25) (f54d59e)
  • deps-dev: bump husky from 3.0.3 to 3.0.4 (#26) (9c60283)

4.1.3 (2019-08-10)

📖 Documentation

  • include min size badge [skip-release] (54b04c6)

🧦 Miscellaneous

  • deps-dev: bump @holvonix-open/release-config-js (#20) (75e16cd)

4.1.2 (2019-08-10)

📖 Documentation

4.1.1 (2019-08-10)

🐛 Bug Fixes

  • need seedrandom types as prod dep (27c1860)

🔬 Tests

  • remove spurious debugging timeout (8338f6e)

4.1.0 (2019-08-10)

🌟🚀 Features

🐛 Bug Fixes

  • randomize NonEmptyArray elements independently (818a366)

4.0.1 (2019-08-10)

💄 Polish

📖 Documentation

4.0.0 (2019-08-09)

🌟🚀 Features

📖 Documentation

🧦 Miscellaneous

  • deps: bump seedrandom from 3.0.1 to 3.0.3 (#16) (91e2346)
  • deps-dev: bump @types/chai from 4.1.7 to 4.2.0 (#15) (593a4dc)
  • deps-dev: bump @types/node from 12.7.0 to 12.7.1 (9be1c28)
  • deps-dev: bump fp-ts from 2.0.4 to 2.0.5 (#17) (6d16718)
  • deps-dev: bump husky from 3.0.2 to 3.0.3 (#14) (83b11a5)
  • make prod deps updates chores by default (1d16fd1)

⚠️ BREAKING CHANGES

  • Fuzzers now have an input and decoded type. Fuzzer generate as output the input of the t.Type, not the decoded or output types.

3.0.5 (2019-08-08)

🐛 Bug Fixes

  • ensure non-integers can be used as input to fuzzers (2d5cc60)

3.0.4 (2019-08-08)

🐛 Bug Fixes

  • string examples made slightly more interesting (4213c0e)

3.0.3 (2019-08-07)

📖 Documentation

  • make examples work without yarn (ec06241)

3.0.2 (2019-08-07)

💄 Polish

📖 Documentation

3.0.1 (2019-08-07)

🐛 Bug Fixes

  • move fp-ts and io-ts to peer dependencies (6a95707)

💄 Polish

  • run non-typescript through prettier (d95bf76)

📖 Documentation

  • add runnable quick start example (34109f9)
  • fix up README typos (518e880)

🔧 Build / Continuous Integration

  • use cd instead of pushd in build scripts (96ad9e9)

🔬 Tests

  • tests never test for uniqueness for examples (a52f4c3)

3.0.0 (2019-08-07)

🌟🚀 Features

  • support date from io-ts-types. This new dependency is added as a peer -- code using it is only imported on calling loadIoTsTypesFuzzers() (#11) (4384326)

⚠️ BREAKING CHANGES

  • core exports re-organized; some removed. From here on, only breaking changes to exports from index.ts will be deemed breaking changes for the package.

2.0.0 (2019-08-07)

🌟🚀 Features

⚠️ BREAKING CHANGES

  • ExampleGenerator now requires as input a tuple [number,FuzzContext]
  • concrete fuzzer functions are passed as their first argument a FuzzContext specifying whether to recurse further or not
  • deprecated, non-configurable versions of core fuzzers removed

1.10.2 (2019-08-06)

🐛 Bug Fixes

  • deps: bump io-ts from 2.0.0 to 2.0.1 (#8) (b957951)

1.10.1 (2019-08-05)

📖 Documentation

  • fix readme quick start bug (1496897)

1.10.0 (2019-08-05)

🌟🚀 Features

  • support configuring unknown type fuzzing (8d15e73)
  • support configuring extra properties for interface fuzzers (6a9dab1)
  • support exact types (883ec4b)
  • support readonly types (03fbecf)
  • support readonlyArray types (279ab9e)
  • support UnknownArray (0ff9aa7)

🐛 Bug Fixes

  • intersection fuzzer emits only examples consistent with each child type (15ae0cd)

💄 Polish

1.9.0 (2019-08-05)

🌟🚀 Features

  • support configuring extra properties for partial fuzzers (5e80982)

1.8.0 (2019-08-05)

🌟🚀 Features

1.7.0 (2019-08-05)

🌟🚀 Features

  • allow customizable max length of array fuzzing (89a3590)

🐛 Bug Fixes

  • use small max array length to avoid DoS (c8ed240)

1.6.0 (2019-08-05)

🌟🚀 Features

💄 Polish

📖 Documentation

  • make clear nested types are supported (0d113e2)

1.5.0 (2019-08-05)

🌟🚀 Features

1.4.3 (2019-08-05)

🐛 Bug Fixes

  • don't run tests on end-users machines (4432f34)

1.4.2 (2019-08-04)

🐛 Bug Fixes

  • fp-ts needs to be a dependency, peer to io-ts (fd2ce1b)

1.4.1 (2019-08-04)

📖 Documentation

  • try changelog with misc changes collapsed (d124c50)

🧦 Miscellaneous

1.4.0 (2019-08-04)

🌟🚀 Features

  • fluent Registry#register function and a Registry#exampleGenerator implementation (aa46fc6)

🐛 Bug Fixes

  • further simply types with defaults (8dd6364)
  • improve typesafety by eliminating use of any (2af1539)
<summary>🔧 Build / Continuous Integration</summary>

  • fix dep on release-config-js (5c3aa19)
  • use release-config-js (294f594)

<summary>🔬 Tests</summary>

  • improve registration tests (1124707)

1.3.0 (2019-08-03)

Features

1.2.2 (2019-08-03)

Performance Improvements

1.2.1 (2019-08-03)

1.2.0 (2019-08-03)

Features

  • support arrays, intersection, null, undefined, void, unknown (9860450)

Performance Improvements

  • mark package as side-effect-free (2ef3c69)

1.1.0 (2019-08-03)

Features

  • support interfaces and partials (9d7e0b0)

1.0.0 (2019-08-03)

Features

  • basic framework + fuzz strings, numbers, bools, and unions (d718348)