Files
jwt-cpp/tests/fuzz/TokenDecodeFuzz.cpp
Chris Mc 7fd8470cf1 🧷 Fuzz testing (#98)
* Update coverage.yml

* adding a fuzz test

* adding more fuzzing

TBA how to handle input requirement of decode

* base64 encoding input to avoid "obvious" exceptions

trying out the EVP_ interface from #89

* fixing decode fuzz

* accepting exceptions are normal

After comparing with https://github.com/nlohmann/json/blob/v3.9.0/test/src/fuzzer-parse_json.cpp I must agree data can be random so it should be accepted

* decoding twice should produce the same result

again based on https://github.com/nlohmann/json/blob/v3.9.0/test/src/fuzzer-parse_json.cpp

* fixing token decode fuzzer

* adding corpus for fuzz tests + adding them to ci

* removing numbers with more meaning descriptions

* Update BaseEncodeFuzz.cpp

* Update coverage.yml

* Update coverage.yml

* shrink interations

* cleaning cmake

* Update and rename coverage.yml to jwt.yml

* Update lint.yml

* Update jwt.yml

* Update jwt.yml
2021-09-17 20:01:38 -04:00

29 lines
649 B
C++

#include <jwt-cpp/jwt.h>
extern "C" {
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
try {
// step 1: parse input
const auto jwt1 = jwt::decode(std::string{(char *)Data, Size});
try {
// step 2: round trip
std::string s1 = jwt1.get_token();
const auto jwt2 = jwt::decode(s1);
// tokens must match
if (s1 != jwt2.get_token())
abort();
} catch (...) {
// parsing raw data twice must not fail
abort();
}
} catch (...) {
// parse errors are ok, because input may be random bytes
}
return 0; // Non-zero return values are reserved for future use.
}
}