Skip to content

Commit

Permalink
UnverifiedBiscuit: add consistency tests with Biscuit
Browse files Browse the repository at this point in the history
  • Loading branch information
divarvel committed Jan 27, 2025
1 parent a3a040c commit 1066bd5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions biscuit-auth/src/token/unverified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,44 @@ impl UnverifiedBiscuit {
self.append_third_party(&decoded)
}
}

#[cfg(test)]
mod tests {
use crate::{BiscuitBuilder, BlockBuilder, KeyPair};

use super::UnverifiedBiscuit;

#[test]
fn consistent_with_biscuit() {
let root_key = KeyPair::new();
let external_key = KeyPair::new();
let biscuit = BiscuitBuilder::new()
.fact("test(true)")
.unwrap()
.build(&root_key)
.unwrap()
.append(BlockBuilder::new().fact("test(false)").unwrap())
.unwrap();
let req = biscuit.third_party_request().unwrap();
let res = req
.create_block(
&external_key.private(),
BlockBuilder::new().fact("third_party(true)").unwrap(),
)
.unwrap();
let biscuit = biscuit
.append_third_party(external_key.public(), res)
.unwrap();

let unverified = UnverifiedBiscuit::from_base64(biscuit.to_base64().unwrap()).unwrap();

unverified.clone().verify(root_key.public()).unwrap();

assert_eq!(unverified.blocks, biscuit.blocks);

assert_eq!(
unverified.external_public_keys(),
biscuit.external_public_keys()
);
}
}

0 comments on commit 1066bd5

Please sign in to comment.