@@ -932,6 +932,7 @@ mod tests {
932
932
933
933
builder. add_right ( "file1" , "read" ) ;
934
934
builder. add_right ( "file2" , "read" ) ;
935
+ builder. add_authority_fact ( "key(0000)" ) . unwrap ( ) ;
935
936
936
937
let biscuit1 = builder. build_with_rng ( & mut rng) . unwrap ( ) ;
937
938
@@ -958,14 +959,14 @@ mod tests {
958
959
authorizer. add_fact ( "operation(\" read\" )" ) . unwrap ( ) ;
959
960
authorizer. set_time ( ) ;
960
961
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 ( ) ;
963
964
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)" ) ;
969
970
println ! ( "res2: {:?}" , res2) ;
970
971
let mut res2 = res2
971
972
. unwrap ( )
@@ -974,14 +975,23 @@ mod tests {
974
975
. collect :: < Vec < _ > > ( ) ;
975
976
res2. sort ( ) ;
976
977
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( ) ,
981
983
]
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( ) ]
985
995
) ;
986
996
}
987
997
}
0 commit comments