Skip to main content

A Proof of Concept multi-lingual test generation suite intended for parsers.

Project description

ParserKiosk: A Proof of Concept multi-lingual test generation suite intended for parsers

Coverage Status Downloads

Motivation

After reading this article and this one, I am now paranoid and under the assumption that implementations of data serialization and deserialization have a lot of quirks that differ from language to language, and implementation to implementation.

This could lead to serious security issues as applications, especially web applicatons usually utilize multiple services, written in multiple languages that use the same format to communicate.

Reference implementations usually provide tests, but translating them from language to language is tiresome and tedious. I wanted to compose a library to generate simple, functional tests for multiple languages with minimal repitition.

Usage

  1. Install
$ pip install parserkiosk
  1. Define a config.yaml
# config.yaml
---
import_string: "from my_parser import serialize, deserialize"
serialize_function: "serialize"
de_serialize_function: "deserialize"
assert_functions:
  - my_assert_function
  1. Define a yaml file prefixed with test_ in the same directory as config.yaml
# test_serialize.yaml
type: "SERIALIZE"
tests:
  test_something:
      info: "Example Test"
      input:
        type: "str"
        arg: "hello, world"
      assert:
        func: "my_assert_function"
        arg: "[\"hello\", \" world\"]"
  1. Run parserkiosk in the same directory as config.yaml and test_serialize.yaml
$ parserkiosk . --builtin python
  1. See output directory tests/
$ ls tests/
test_serialize.py

See HOWTO for a complete guide.

How does it work?

Parserkiosk uses jinja2 templates to generate test cases from yaml file(s). You can either expect something to fail(raise an "exception" or "error") or use a function that you define in a special file called commons to assert if the parsed data matches the expected internal representation.

Let's say you've written a reference implementation of your data de/serialization format in Go and I wanted to implement it in Python.
All I would need to do to implement your test-suite is:

  1. Write a commons.py file implementing the same assertion functions that you've written in your commons.go file
  2. Adapt your parserkiosk config to use my implementation
  3. Run $ parserkiosk folder_with_yaml_test_files/ --builtin python and voila I have your entire test suite implemented!

For more on this, see examples/json/

Languages supported

  • Python / pytest / python
  • NodeJS / jest (sync) / node_js
  • NodeJS / jest (async)
  • Lua
  • Go
  • Java
  • PHP
  • Perl
  • Ruby
  • ...

License

All work is licensed under GPL-3.0 excluding the example JSON test-suite which is licensed under MIT

Contributing

Issues, feedback and pull requests are welcome. I have tried my best to keep the code simple. Please keep in mind that I wish to limit features that we accomodate to keep it simple. Tests should be simple and readable.

Installing for development

$ git clone https://github.com/you/your-fork-of-parserkiosk.git
$ cd your-fork-of-parserkiosk
$ poetry install
$ poetry run pre-commit install
# do some changes
$ ./runtests.sh
# you are ready!

Thanks

Special thanks to nst for inspiring Parserkiosk. All test cases in examples/json come from his incredible work

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parserkiosk-0.3.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

parserkiosk-0.3.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file parserkiosk-0.3.0.tar.gz.

File metadata

  • Download URL: parserkiosk-0.3.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.10.0-13-amd64

File hashes

Hashes for parserkiosk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6e7aa1ec92062c1952e1a63ed400484ead8d05613a4287bcc2183785e2235078
MD5 0ea67e52f90ed37dba0a05e883a41f97
BLAKE2b-256 367c1bb99dc59410a7628a983a3c747377b096fcdde313dd9e2130b4f0f8b6fa

See more details on using hashes here.

File details

Details for the file parserkiosk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: parserkiosk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.10.0-13-amd64

File hashes

Hashes for parserkiosk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ceca6df705a8e24cb67e6de17730079ef3aebdcbe757444ae9a2e6982d5116b
MD5 641a6adedf1650005e7614401db1ead4
BLAKE2b-256 52ff5635ca1c882c8e555a3ede9522ad17f918ff67c9356a5133b423ec94e7df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page