mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-07-26 07:58:14 +00:00
Add fuzing for AdminApiToken CRDT (#1443)
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1443 Reviewed-by: Alex <lx@deuxfleurs.fr>
This commit is contained in:
@@ -43,3 +43,10 @@ path = "fuzz_targets/block_ref_crdt.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "admin_api_token_crdt"
|
||||
path = "fuzz_targets/admin_api_token_crdt.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#![no_main]
|
||||
|
||||
use garage_fuzz::check_crdt_laws;
|
||||
use garage_model::admin_token_table::{AdminApiToken, AdminApiTokenParams, AdminApiTokenScope};
|
||||
use garage_util::crdt;
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
type Input = (
|
||||
bool,
|
||||
crdt::Lww<String>,
|
||||
crdt::Lww<Option<u64>>,
|
||||
crdt::Lww<AdminApiTokenScope>,
|
||||
);
|
||||
|
||||
fn make(input: Input) -> AdminApiToken {
|
||||
let (deleted, name, expiration, scope) = input;
|
||||
let state = if deleted {
|
||||
crdt::Deletable::Deleted
|
||||
} else {
|
||||
crdt::Deletable::present(AdminApiTokenParams {
|
||||
created: 0,
|
||||
token_hash: String::new(),
|
||||
name,
|
||||
expiration,
|
||||
scope,
|
||||
})
|
||||
};
|
||||
AdminApiToken {
|
||||
prefix: String::new(),
|
||||
state,
|
||||
}
|
||||
}
|
||||
|
||||
fuzz_target!(|inputs: (Input, Input, Input)| {
|
||||
let (a, b, c) = inputs;
|
||||
check_crdt_laws(make(a), make(b), make(c));
|
||||
});
|
||||
@@ -51,6 +51,14 @@ mod v2 {
|
||||
|
||||
pub use v2::*;
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<'a> arbitrary::Arbitrary<'a> for AdminApiTokenScope {
|
||||
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
let set: std::collections::BTreeSet<String> = arbitrary::Arbitrary::arbitrary(u)?;
|
||||
Ok(AdminApiTokenScope(set.into_iter().collect()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Crdt for AdminApiTokenParams {
|
||||
fn merge(&mut self, o: &Self) {
|
||||
self.name.merge(&o.name);
|
||||
|
||||
Reference in New Issue
Block a user