Skip to content

Commit

Permalink
Add extension module for testing with BLNS (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 authored Aug 14, 2024
1 parent 4f2ae80 commit a720188
Show file tree
Hide file tree
Showing 19 changed files with 3,918 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ build/
logs/
!gradle/wrapper/gradle-wrapper.jar
!docs/gradle/wrapper/gradle-wrapper.jar
# kotlin-language-server
kls_database.db
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[discrete]
=== Added

* https://github.com/serpro69/kotlin-faker/pull/245[#245] (:extension) Add extension for testing with BLNS
* https://github.com/serpro69/kotlin-faker/pull/243[#243] (:core) Add collection element and map k/v type gen for random class instance
* https://github.com/serpro69/kotlin-faker/pull/234[#234] (:extension) Add extension module for kotest property testing
* https://github.com/serpro69/kotlin-faker/pull/232[#232] (:core) Add support for alternative primary key when resolving values
Expand Down
45 changes: 27 additions & 18 deletions docs/src/orchid/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ theme:
- type: 'sourcedocModules'
moduleType: 'kotlindoc'
moduleGroup: 'faker-module'
- type: separator
- type: 'sourcedocModules'
moduleType: 'kotlindoc'
moduleGroup: 'faker-extension'
- type: 'submenu'
title: 'Information'
icon: 'info-circle'
Expand Down Expand Up @@ -137,24 +141,29 @@ kotlindoc:
itemTitleType: 'signature' # optional, one of [NAME, ID, SIGNATURE]
includeItems: true # optional
modules:
- { name: 'Full Core API', slug: 'core-api', sourceDirs: [ './../../../../core/src/main/kotlin/', './../../../../core/src/main/java/' ], moduleGroup: 'core-api' }
- { name: 'Core Data Provider API', slug: 'core-data-provider', sourceDirs: [ './../../../../core/src/main/kotlin/io/github/serpro69/kfaker/provider' ], moduleGroup: 'core-provider' }
- { name: 'Books Provider API', slug: 'books-data-provider', sourceDirs: [ './../../../../faker/books/src/main/kotlin/io/github/serpro69/kfaker/books' ], moduleGroup: 'faker-module' }
- { name: 'Commerce Provider API', slug: 'commerce-data-provider', sourceDirs: [ './../../../../faker/commerce/src/main/kotlin/io/github/serpro69/kfaker/commerce' ], moduleGroup: 'faker-module' }
- { name: 'Creatures Provider API', slug: 'creatures-data-provider', sourceDirs: [ './../../../../faker/creatures/src/main/kotlin/io/github/serpro69/kfaker/creatures' ], moduleGroup: 'faker-module' }
- { name: 'Databases Provider API', slug: 'databases-data-provider', sourceDirs: [ './../../../../faker/databases/src/main/kotlin/io/github/serpro69/kfaker/databases' ], moduleGroup: 'faker-module' }
- { name: 'Edu Provider API', slug: 'edu-data-provider', sourceDirs: [ './../../../../faker/edu/src/main/kotlin/io/github/serpro69/kfaker/edu' ], moduleGroup: 'faker-module' }
- { name: 'Games Provider API', slug: 'games-data-provider', sourceDirs: [ './../../../../faker/games/src/main/kotlin/io/github/serpro69/kfaker/games' ], moduleGroup: 'faker-module' }
- { name: 'Humor Provider API', slug: 'humor-data-provider', sourceDirs: [ './../../../../faker/humor/src/main/kotlin/io/github/serpro69/kfaker/humor' ], moduleGroup: 'faker-module' }
- { name: 'JapMedia Provider API', slug: 'japmedia-data-provider', sourceDirs: [ './../../../../faker/japmedia/src/main/kotlin/io/github/serpro69/kfaker/japmedia' ], moduleGroup: 'faker-module' }
- { name: 'Lorem Provider API', slug: 'lorem-data-provider', sourceDirs: [ './../../../../faker/lorem/src/main/kotlin/io/github/serpro69/kfaker/lorem' ], moduleGroup: 'faker-module' }
- { name: 'Misc Provider API', slug: 'misc-data-provider', sourceDirs: [ './../../../../faker/misc/src/main/kotlin/io/github/serpro69/kfaker/misc' ], moduleGroup: 'faker-module' }
- { name: 'Movies Provider API', slug: 'movies-data-provider', sourceDirs: [ './../../../../faker/movies/src/main/kotlin/io/github/serpro69/kfaker/movies' ], moduleGroup: 'faker-module' }
- { name: 'Music Provider API', slug: 'music-data-provider', sourceDirs: [ './../../../../faker/music/src/main/kotlin/io/github/serpro69/kfaker/music' ], moduleGroup: 'faker-module' }
- { name: 'Sports Provider API', slug: 'sports-data-provider', sourceDirs: [ './../../../../faker/sports/src/main/kotlin/io/github/serpro69/kfaker/sports' ], moduleGroup: 'faker-module' }
- { name: 'Tech Provider API', slug: 'tech-data-provider', sourceDirs: [ './../../../../faker/tech/src/main/kotlin/io/github/serpro69/kfaker/tech' ], moduleGroup: 'faker-module' }
- { name: 'Travel Provider API', slug: 'travel-data-provider', sourceDirs: [ './../../../../faker/travel/src/main/kotlin/io/github/serpro69/kfaker/travel' ], moduleGroup: 'faker-module' }
- { name: 'TvShows Provider API', slug: 'tvshows-data-provider', sourceDirs: [ './../../../../faker/tvshows/src/main/kotlin/io/github/serpro69/kfaker/tvshows' ], moduleGroup: 'faker-module' }
# :core
- { name: 'Full Core API', slug: 'core-api', sourceDirs: [ './../../../../core/src/main/kotlin/', './../../../../core/src/main/java/' ], moduleGroup: 'core-api' }
- { name: 'Core Data Provider API', slug: 'core-data-provider', sourceDirs: [ './../../../../core/src/main/kotlin/io/github/serpro69/kfaker/provider' ], moduleGroup: 'core-provider' }
# :faker
- { name: 'Books Provider API', slug: 'books-data-provider', sourceDirs: [ './../../../../faker/books/src/main/kotlin/io/github/serpro69/kfaker/books' ], moduleGroup: 'faker-module' }
- { name: 'Commerce Provider API', slug: 'commerce-data-provider', sourceDirs: [ './../../../../faker/commerce/src/main/kotlin/io/github/serpro69/kfaker/commerce' ], moduleGroup: 'faker-module' }
- { name: 'Creatures Provider API', slug: 'creatures-data-provider', sourceDirs: [ './../../../../faker/creatures/src/main/kotlin/io/github/serpro69/kfaker/creatures' ], moduleGroup: 'faker-module' }
- { name: 'Databases Provider API', slug: 'databases-data-provider', sourceDirs: [ './../../../../faker/databases/src/main/kotlin/io/github/serpro69/kfaker/databases' ], moduleGroup: 'faker-module' }
- { name: 'Edu Provider API', slug: 'edu-data-provider', sourceDirs: [ './../../../../faker/edu/src/main/kotlin/io/github/serpro69/kfaker/edu' ], moduleGroup: 'faker-module' }
- { name: 'Games Provider API', slug: 'games-data-provider', sourceDirs: [ './../../../../faker/games/src/main/kotlin/io/github/serpro69/kfaker/games' ], moduleGroup: 'faker-module' }
- { name: 'Humor Provider API', slug: 'humor-data-provider', sourceDirs: [ './../../../../faker/humor/src/main/kotlin/io/github/serpro69/kfaker/humor' ], moduleGroup: 'faker-module' }
- { name: 'JapMedia Provider API', slug: 'japmedia-data-provider', sourceDirs: [ './../../../../faker/japmedia/src/main/kotlin/io/github/serpro69/kfaker/japmedia' ], moduleGroup: 'faker-module' }
- { name: 'Lorem Provider API', slug: 'lorem-data-provider', sourceDirs: [ './../../../../faker/lorem/src/main/kotlin/io/github/serpro69/kfaker/lorem' ], moduleGroup: 'faker-module' }
- { name: 'Misc Provider API', slug: 'misc-data-provider', sourceDirs: [ './../../../../faker/misc/src/main/kotlin/io/github/serpro69/kfaker/misc' ], moduleGroup: 'faker-module' }
- { name: 'Movies Provider API', slug: 'movies-data-provider', sourceDirs: [ './../../../../faker/movies/src/main/kotlin/io/github/serpro69/kfaker/movies' ], moduleGroup: 'faker-module' }
- { name: 'Music Provider API', slug: 'music-data-provider', sourceDirs: [ './../../../../faker/music/src/main/kotlin/io/github/serpro69/kfaker/music' ], moduleGroup: 'faker-module' }
- { name: 'Sports Provider API', slug: 'sports-data-provider', sourceDirs: [ './../../../../faker/sports/src/main/kotlin/io/github/serpro69/kfaker/sports' ], moduleGroup: 'faker-module' }
- { name: 'Tech Provider API', slug: 'tech-data-provider', sourceDirs: [ './../../../../faker/tech/src/main/kotlin/io/github/serpro69/kfaker/tech' ], moduleGroup: 'faker-module' }
- { name: 'Travel Provider API', slug: 'travel-data-provider', sourceDirs: [ './../../../../faker/travel/src/main/kotlin/io/github/serpro69/kfaker/travel' ], moduleGroup: 'faker-module' }
- { name: 'TvShows Provider API', slug: 'tvshows-data-provider', sourceDirs: [ './../../../../faker/tvshows/src/main/kotlin/io/github/serpro69/kfaker/tvshows' ], moduleGroup: 'faker-module' }
# :extension
- { name: 'Blns Extension API', slug: 'blns-extension', sourceDirs: [ './../../../../extension/blns/src/main/kotlin/io/github/serpro69/kfaker/blns' ], moduleGroup: 'faker-extension' }
- { name: 'Kotest Property Extension API', slug: 'kotest-property-extension', sourceDirs: [ './../../../../extension/kotest-property/src/main/kotlin/io/github/serpro69/kfaker/kotest' ], moduleGroup: 'faker-extension' }

snippets:
sections:
Expand Down
107 changes: 107 additions & 0 deletions docs/src/orchid/resources/pages/extensions/blns-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
---

# Big List of Naughty Strings Extension

## TOC

- [About](#about)
- [Usage](#usage)
- [Installation](#installation)
- [Generate Arb Extensions](#generate-arb-extensions)
- [Random Class Instance ARBs](#random-class-instance-arb)

## About

Kotlin-faker `blns` artifact provides convenience functions for returning strings from [The Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings) - a list of strings which have a high probability of causing issues when used as user-input data, and can therefore be quite useful in testing.

## Disclaimer

> The Big List of Naughty Strings is intended to be used for _software you own and manage_. Some of the Naughty Strings can indicate security vulnerabilities, and as a result using such strings with third-party software may be a crime. The maintainer is not responsible for any negative actions that result from the use of the list.
>
> Additionally, the Big List of Naughty Strings is not a fully-comprehensive substitute for formal security/penetration testing for your service.
## Usage

### Installation

- ① add the core `kotlin-faker` dependency to the test classpath
- ② then add the dependency for the `kotlin-faker-blns` extension

{% tabs %}

{% kotlin "Kotlin" %}
{% filter compileAs('md') %}

```kotlin
dependencies {
testImplementation("io.github.serpro69:kotlin-faker:$fakerVersion") //
testImplementation("io.github.serpro69:kotlin-faker-blns:$fakerVersion") //
}
```

{% endfilter %}
{% endkotlin %}

{% endtabs %}

{% btc %}{% endbtc %}

<br>

### Using the Big List of Naughty Strings

The `Blns` class provides properties and functions to get all strings, as well as a sublist of strings, and a single random string.

There is also corresponding functionality for getting base64-encoded strings.

For example, using [JUnit5 Parameterized Testing](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests) capabilities:

- ① Create an instance of `Blns` class
- ② Get `all` strings
- ③ Get a `sublist` of strings
- ④ Get a `random` string
-`get` strings by a `Category`
- ⑥ Test your inputs
- Profit 💸

{% tabs %}

{% kotlin "Kotlin" %}
{% filter compileAs('md') %}

```kotlin
class Test {
@ParameterizedTest
@MethodSource("allStrings") //
fun `test input with a naughty string`(s: String) {
inputField.sendKeys(s) //
}

companion object {
private val blns = blns { /*faker configuration*/ } //
@JvmStatic private fun allStrings() = blns.all.stream() //
@JvmStatic private fun allBase64 () = blns.allBase64.stream() //
@JvmStatic private fun sublist() = blns.sublist(10).stream() //
@JvmStatic private fun sublistBase64() = blns.sublist(10, base64 = true).stream() //
val randomString: String get() = blns.random() //
val randomBase64String: String get() = blns.random(base64 = true) //
val emojiStrings = blns.get(Category.EMOJI) //
val emojiAndKaomojiStrings = blns.get(Category.EMOJI, Category.KAOMOJI) //
val basicCategories = blns.get(Category.RESERVED, Category.NUMERIC, Category.SPECIAL) //
}
}
```

{% endfilter %}
{% endkotlin %}

{% endtabs %}

{% btc %}{% endbtc %}

<br>

## Credits

The input for this extension is maintained by [github.com/minimaxir](https://github.com/minimaxir) at https://github.com/minimaxir/big-list-of-naughty-strings.
15 changes: 12 additions & 3 deletions docs/src/orchid/resources/wiki/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ The extension modules require the [main `kotlin-faker` dependency]({{ link(colle

## ToC

- [BLNS](#blns)
- [Kotest Property](#kotest-property)

<br>

## BLNS

Kotlin-faker `blns` artifact provides convenience functions for returning strings from [The Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings) - a list of strings which have a high probability of causing issues when used as user-input data, and can therefore be quite useful in testing.

See the [Big List of Naughty Strings Extension]({{ link(collectionType='pages', collectionId='extensions', itemId='Blns Extension') }}) page for usage details.

{% btc %}{% endbtc %}

<br>

## Kotest Property

Kotlin-faker `kotest-property` and `kotest-property-ksp` artifacts provide faker-based [`Arb` generators](https://kotest.io/docs/proptest/property-test-generators.html) extensions via [KSP](https://kotlinlang.org/docs/ksp-overview.html) compiler plugin for [kotest property testing](https://kotest.io/docs/proptest/property-based-testing.html).
`kotlin-faker-kotest-property` artifact extends [`Arb` generators](https://kotest.io/docs/proptest/property-test-generators.html) and provides an easy way to use kotlin-faker functionality with [kotest property testing](https://kotest.io/docs/proptest/property-based-testing.html).

See the [Kotest Property Extension]({{ link(collectionType='pages', collectionId='extensions', itemId='Kotest Property Extension') }}) page for usage details.

A full working example can also be found in the [kotest-property-test](https://github.com/serpro69/kotlin-faker/tree/master/extension/kotest-property-test) project.

{% btc %}{% endbtc %}

<br>
Expand Down
10 changes: 10 additions & 0 deletions extension/blns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `kotlin-faker-blns`

[![Maven Central](https://img.shields.io/maven-central/v/io.github.serpro69/kotlin-faker-blns?style=for-the-badge)](https://search.maven.org/artifact/io.github.serpro69/kotlin-faker-blns)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.serpro69/kotlin-faker-blns?label=snapshot-version&server=https%3A%2F%2Foss.sonatype.org&style=for-the-badge&color=yellow)](#downloading)

`kotlin-faker-blns` module provides extensions for the [big-list-of-naughty-strings](https://github.com/minimaxir/big-list-of-naughty-strings), a list of strings which have a high probability of causing issues when used as user-input data, and can therefore be quite useful in testing.

## Usage

Documentation for this extension is available at [serpro69.github.io/kotlin-faker/](https://serpro69.github.io/kotlin-faker/extensions/blns-extension).
Loading

0 comments on commit a720188

Please sign in to comment.