Code Monkey home page Code Monkey logo

snodge's Introduction

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 (replace <version> with the version of Snodge you wish to use):

testImplementation 'com.natpryce:snodge:<version>'

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

testRuntimeOnly '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

snodge's People

Contributors

npryce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snodge's Issues

Ensure mutations do not reorder JSON object properties

Currently mutations change the order in which JSON object properties are written out.

If a JSON processor cannot handle reordered properties (e.g. a streaming processor), the current Snodge behaviour will mask errors that should be detected by the mutation -- the processor will fail because the mutated field has changed order before the actual mutation can affect it.

Therefore Snodge should ensure that mutations do not reorder properties. The ReorderObjectProperties mutagen can be used to explicitly test for sensitivity to property order.

Make GSON an implementation detail, not dependency at API

The dependency on GSON introduces dependency clash in big (unwieldy) projects.

To fix: remove dependency from GSON at the API, only exposing APIs that work with generic JSON representations (e.g. strings, encoded strings).

Unfortunately Maven's dependency model does not distinguish between private and public dependencies, so the build will have to repackage GSON when zipping the compiled code into JARs.

Support JDK 6

Yes, it's EOL. But there's lots of legacy systems that need some snodging.

Outdated readme

Read me is outdated with the latest version.
Provided sample snippet in the readme does not work with Android, there is a ClassNotFoundException with reflection.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.