Skip to content

Commit b1770f0

Browse files
committed
add some tests for authorizer cloning
1 parent 6da6509 commit b1770f0

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/token/mod.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ mod tests {
932932

933933
builder.add_right("file1", "read");
934934
builder.add_right("file2", "read");
935+
builder.add_authority_fact("key(0000)").unwrap();
935936

936937
let biscuit1 = builder.build_with_rng(&mut rng).unwrap();
937938

@@ -958,14 +959,14 @@ mod tests {
958959
authorizer.add_fact("operation(\"read\")").unwrap();
959960
authorizer.set_time();
960961

961-
let res = authorizer.authorize();
962-
println!("res1: {:?}", res);
962+
// test that cloning correctly embeds the first block's facts
963+
let mut other_authorizer = authorizer.clone();
963964

964-
let res2: Result<Vec<builder::Fact>, crate::error::Token> = authorizer.query(rule(
965-
"key_verif",
966-
&[builder::Term::Variable("id".to_string())],
967-
&[pred("key", &[builder::Term::Variable("id".to_string())])],
968-
));
965+
let authorization_res = authorizer.authorize();
966+
println!("authorization result: {:?}", authorization_res);
967+
968+
let res2: Result<Vec<builder::Fact>, crate::error::Token> =
969+
authorizer.query("key_verif($id) <- key($id)");
969970
println!("res2: {:?}", res2);
970971
let mut res2 = res2
971972
.unwrap()
@@ -974,14 +975,23 @@ mod tests {
974975
.collect::<Vec<_>>();
975976
res2.sort();
976977
assert_eq!(
977-
&res2,
978-
&[
979-
fact("key_verif", &[int(1234)]),
980-
fact("key_verif", &[int(5678)])
978+
res2,
979+
vec![
980+
"key_verif(0)".to_string(),
981+
"key_verif(1234)".to_string(),
982+
"key_verif(5678)".to_string(),
981983
]
982-
.iter()
983-
.map(|f| f.to_string())
984-
.collect::<Vec<_>>()
984+
);
985+
986+
let res1: Result<Vec<builder::Fact>, crate::error::Token> =
987+
other_authorizer.query("key_verif($id) <- key($id)");
988+
println!("res1: {:?}", res1);
989+
assert_eq!(
990+
res1.unwrap()
991+
.into_iter()
992+
.map(|f| f.to_string())
993+
.collect::<Vec<_>>(),
994+
vec!["key_verif(0)".to_string()]
985995
);
986996
}
987997
}

0 commit comments

Comments
 (0)