Skip to content
Randomly mutate JSON, XML, HTML forms, text and binary data for fuzz testing
Kotlin HTML XSLT Makefile Shell
Branch: kotlin
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Track Kotlin version to 1.3 Feb 12, 2020
common/src Track Kotlin version to 1.3 Feb 12, 2020
demo/com/natpryce/snodge/demo Track Kotlin version to 1.3 Feb 12, 2020
doc Update mutagen-operators.md Feb 12, 2020
live-demo Track Kotlin version to 1.3 Feb 12, 2020
platform Track Kotlin version to 1.3 Feb 12, 2020
tools Track Kotlin version to 1.3 Feb 12, 2020
.gitignore Ignore the build/ directory, created by IntelliJ Feb 12, 2020
.java-version Use JEnv to pin JDK to 11 (current LTS version) Feb 12, 2020
.travis.yml Travis build config for OpenJDK 8 instead of Oracle JDK8 Feb 12, 2020
LICENSE Initial commit Mar 20, 2014
Makefile Delete obsolete make rules Aug 11, 2017
Makefile_js
Makefile_jvm Track Kotlin version to 1.3 Feb 12, 2020
README.md Update README to reflect Kotlin version Feb 12, 2020
main.dependencies Depend on the JSR-374 javax.json API, and define a runtime dependency… Jun 7, 2017
package.json Generate contents of package.json for distribution from Makefile vari… Jul 3, 2017
runtime.dependencies Track Kotlin version to 1.3 Feb 12, 2020
snodge.iml Simple HTML demo Jul 3, 2017
test-js.html A little bit further... can run QUnit tests in the browser, but not o… Jun 29, 2017
test.dependencies Track Kotlin version to 1.3 Feb 12, 2020

README.md

Snodge

Kotlin Build Status Maven Central npm

A small, extensible Kotlin library to randomly mutate JSON & XML documents, text and binary data. Useful for fuzz testing.

Examples of things you can test by mutating known good data:

  • unexpected structures will not make your application code throw unchecked exceptions
  • your application code ignores additional properties
  • your application code does not throw unchecked exceptions when parsing values from text properties
  • your application does not instantiate arbitrary classes named in data (a potential security risk)
  • your application copes with invalid Unicode encoding of text
  • and much, much more!

See an interactive demonstration.

In a Nutshell

Add a dependency on Snodge:

compile 'com.natpryce:snodge:3.3.0.1'

For the JVM platform, add an implementation of the JSR-374 JSONP API, such as:

runtime 'org.glassfish:javax.json:1.1'

Import the library:

import com.natpryce.snodge.mutants
import com.natpryce.snodge.json.defaultJsonMutagens

Output 10 random mutations of the JSON document:

val random = Random()
val originalJson = "{\"x\": \"hello\", \"y\": [1,2,3]}"

random.mutants(defaultJsonMutagens().forStrings(), 10, originalJson)
    .forEach(::println)

Example output:

{"x":"hello","y":[1,2,3,null]}
{"y":[1,2,3],"x":{}}
{"x":"hello","y":[2,3]}
{"x":"hello","y":[{},2,3]}
{"x":"hello"}
{"x":"hello","y":[1,2,{}]}
{"x":"hello","y":[1,null,3]}
{"y":[1,2,3],"x":"hello"}
{"y":[1,2,3],"x":"a string"}
{"x":"hello","y":[99,2,3]}

API Adapters

On the JVM, Snodge can mutate the JSON object models of the Jackson, GSON & JSR-374 JSONP and Argo APIs, XML DOM, and JSON and XML serialised as text and binary.

On JavaScript, Snodge can mutate XML as DOM Documents, and XML and JSON as text.

For more information, continue reading the documentation.

Other versions

The Kotlin library is version 3.x.x.x.

Previous versions:

  • Version 2.x.x.x (java8 branch) is for Java 8, and uses streams and Java 8 function types
  • Version 1.x.x.x (java7 branch) is for Java 7 and depends on Guava

Download from Maven Central Download from NPM

You can’t perform that action at this time.