@@ -296,13 +296,12 @@ mod tests {
296
296
297
297
#[ cfg( not( target_arch = "wasm32" ) ) ]
298
298
mod fixtures {
299
- use ic_http_certification:: { HttpRequest , HttpResponse } ;
300
- use ic_response_verification:: {
301
- cel:: cel_to_certification,
302
- hash:: { request_hash, response_hash} ,
299
+ use ic_http_certification:: {
300
+ cel:: CelExpression , request_hash, response_hash, DefaultCelBuilder ,
301
+ DefaultResponseCertification , HttpRequest , HttpResponse ,
303
302
} ;
304
303
use ic_response_verification_test_utils:: {
305
- create_expr_tree_path, deflate_encode, gzip_encode, hash, remove_whitespace , ExprTree ,
304
+ create_expr_tree_path, deflate_encode, gzip_encode, hash, ExprTree ,
306
305
} ;
307
306
use rstest:: * ;
308
307
@@ -324,7 +323,7 @@ mod fixtures {
324
323
headers : vec ! [
325
324
( "Content-Type" . into( ) , "text/html" . into( ) ) ,
326
325
( "Content-Encoding" . into( ) , "gzip" . into( ) ) ,
327
- ( "IC-CertificateExpression" . into( ) , cel) ,
326
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
328
327
] ,
329
328
}
330
329
}
@@ -340,7 +339,7 @@ mod fixtures {
340
339
headers : vec ! [
341
340
( "Content-Type" . into( ) , "text/javascript" . into( ) ) ,
342
341
( "Content-Encoding" . into( ) , "gzip" . into( ) ) ,
343
- ( "IC-CertificateExpression" . into( ) , cel) ,
342
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
344
343
] ,
345
344
}
346
345
}
@@ -356,7 +355,7 @@ mod fixtures {
356
355
headers : vec ! [
357
356
( "Content-Type" . into( ) , "text/plain" . into( ) ) ,
358
357
( "Content-Encoding" . into( ) , "identity" . into( ) ) ,
359
- ( "IC-CertificateExpression" . into( ) , cel) ,
358
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
360
359
] ,
361
360
}
362
361
}
@@ -371,7 +370,7 @@ mod fixtures {
371
370
body : body. to_vec ( ) ,
372
371
headers : vec ! [
373
372
( "Location" . into( ) , "/new-path" . into( ) ) ,
374
- ( "IC-CertificateExpression" . into( ) , cel) ,
373
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
375
374
] ,
376
375
}
377
376
}
@@ -386,7 +385,7 @@ mod fixtures {
386
385
headers : vec ! [
387
386
( "Content-Type" . into( ) , "text/html" . into( ) ) ,
388
387
( "Content-Encoding" . into( ) , "identity" . into( ) ) ,
389
- ( "IC-CertificateExpression" . into( ) , cel) ,
388
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
390
389
] ,
391
390
}
392
391
}
@@ -401,7 +400,7 @@ mod fixtures {
401
400
headers : vec ! [
402
401
( "Content-Type" . into( ) , "text/html" . into( ) ) ,
403
402
( "Content-Encoding" . into( ) , "gzip" . into( ) ) ,
404
- ( "IC-CertificateExpression" . into( ) , cel) ,
403
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
405
404
] ,
406
405
}
407
406
}
@@ -416,7 +415,7 @@ mod fixtures {
416
415
headers : vec ! [
417
416
( "Content-Type" . into( ) , "text/html" . into( ) ) ,
418
417
( "Content-Encoding" . into( ) , "deflate" . into( ) ) ,
419
- ( "IC-CertificateExpression" . into( ) , cel) ,
418
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
420
419
] ,
421
420
}
422
421
}
@@ -448,7 +447,7 @@ mod fixtures {
448
447
headers : vec ! [
449
448
( "Content-Type" . into( ) , "text/html" . into( ) ) ,
450
449
( "Content-Encoding" . into( ) , "deflate" . into( ) ) ,
451
- ( "IC-CertificateExpression" . into( ) , cel) ,
450
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
452
451
] ,
453
452
}
454
453
}
@@ -482,100 +481,57 @@ mod fixtures {
482
481
( "Content-Type" . into( ) , "text/html" . into( ) ) ,
483
482
( "Content-Encoding" . into( ) , "deflate" . into( ) ) ,
484
483
( "ETag" . into( ) , etag) ,
485
- ( "IC-CertificateExpression" . into( ) , cel) ,
484
+ ( "IC-CertificateExpression" . into( ) , cel. to_string ( ) ) ,
486
485
] ,
487
486
}
488
487
}
489
488
490
489
#[ fixture]
491
- pub fn asset_cel ( ) -> String {
492
- remove_whitespace (
493
- r#"
494
- default_certification (
495
- ValidationArgs {
496
- certification: Certification {
497
- no_request_certification: Empty {},
498
- response_certification: ResponseCertification {
499
- certified_response_headers: ResponseHeaderList {
500
- headers: ["Content-Type", "Content-Encoding"]
501
- }
502
- }
503
- }
504
- }
505
- )
506
- "# ,
507
- )
490
+ pub fn asset_cel ( ) -> CelExpression < ' static > {
491
+ DefaultCelBuilder :: response_certification ( )
492
+ . with_response_certification ( DefaultResponseCertification :: certified_response_headers (
493
+ & [ "Content-Type" , "Content-Encoding" ] ,
494
+ ) )
495
+ . build ( )
508
496
}
509
497
510
498
#[ fixture]
511
- pub fn redirect_cel ( ) -> String {
512
- remove_whitespace (
513
- r#"
514
- default_certification (
515
- ValidationArgs {
516
- certification: Certification {
517
- no_request_certification: Empty {},
518
- response_certification: ResponseCertification {
519
- certified_response_headers: ResponseHeaderList {
520
- headers: ["Location"]
521
- }
522
- }
523
- }
524
- }
525
- )
526
- "# ,
527
- )
499
+ pub fn redirect_cel ( ) -> CelExpression < ' static > {
500
+ DefaultCelBuilder :: response_certification ( )
501
+ . with_response_certification ( DefaultResponseCertification :: certified_response_headers (
502
+ & [ "Location" ] ,
503
+ ) )
504
+ . build ( )
528
505
}
529
506
530
507
#[ fixture]
531
- pub fn etag_caching_match_cel ( ) -> String {
532
- remove_whitespace (
533
- r#"
534
- default_certification (
535
- ValidationArgs {
536
- certification: Certification {
537
- request_certification: RequestCertification {
538
- certified_request_headers: ["If-None-Match"],
539
- certified_query_parameters: []
540
- },
541
- response_certification: ResponseCertification {
542
- certified_response_headers: ResponseHeaderList {
543
- headers: ["Content-Type", "Content-Encoding"]
544
- }
545
- }
546
- }
547
- }
548
- )
549
- "# ,
550
- )
508
+ pub fn etag_caching_match_cel ( ) -> CelExpression < ' static > {
509
+ DefaultCelBuilder :: full_certification ( )
510
+ . with_request_headers ( & [ "If-None-Match" ] )
511
+ . with_response_certification ( DefaultResponseCertification :: certified_response_headers (
512
+ & [ "Content-Type" , "Content-Encoding" , "ETag" ] ,
513
+ ) )
514
+ . build ( )
551
515
}
552
516
553
517
#[ fixture]
554
- pub fn etag_caching_mismatch_cel ( ) -> String {
555
- remove_whitespace (
556
- r#"
557
- default_certification (
558
- ValidationArgs {
559
- certification: Certification {
560
- no_request_certification: Empty {},
561
- response_certification: ResponseCertification {
562
- certified_response_headers: ResponseHeaderList {
563
- headers: ["Content-Type", "Content-Encoding", "ETag"]
564
- }
565
- }
566
- }
567
- }
568
- )
569
- "# ,
570
- )
518
+ pub fn etag_caching_mismatch_cel ( ) -> CelExpression < ' static > {
519
+ DefaultCelBuilder :: response_certification ( )
520
+ . with_response_certification ( DefaultResponseCertification :: certified_response_headers (
521
+ & [ "Content-Type" , "Content-Encoding" , "ETag" ] ,
522
+ ) )
523
+ . build ( )
571
524
}
572
525
573
526
#[ fixture]
574
527
pub fn certificate_tree ( ) -> ExprTree {
575
- let asset_cel = asset_cel ( ) ;
528
+ let asset_certification = asset_cel ( ) ;
529
+ let asset_cel = asset_certification. to_string ( ) ;
576
530
let asset_cel_hash = hash ( asset_cel. as_bytes ( ) ) ;
577
- let asset_certification = cel_to_certification ( & asset_cel) . unwrap ( ) . unwrap ( ) ;
578
531
532
+ let CelExpression :: DefaultCertification ( Some ( asset_certification) ) = asset_certification else {
533
+ panic ! ( "Expected asset certification to have response certification" )
534
+ } ;
579
535
let index_html_response_hash = response_hash (
580
536
& index_html_response ( ) ,
581
537
& asset_certification. response_certification ,
@@ -589,10 +545,13 @@ mod fixtures {
589
545
& asset_certification. response_certification ,
590
546
) ;
591
547
592
- let redirect_cel = redirect_cel ( ) ;
548
+ let redirect_certification = redirect_cel ( ) ;
549
+ let redirect_cel = redirect_certification. to_string ( ) ;
593
550
let redirect_cel_hash = hash ( redirect_cel. as_bytes ( ) ) ;
594
- let redirect_certification = cel_to_certification ( & redirect_cel) . unwrap ( ) . unwrap ( ) ;
595
551
552
+ let CelExpression :: DefaultCertification ( Some ( redirect_certification) ) = redirect_certification else {
553
+ panic ! ( "Expected asset certification to have response certification" )
554
+ } ;
596
555
let redirect_response_hash = response_hash (
597
556
& redirect_response ( ) ,
598
557
& redirect_certification. response_certification ,
@@ -660,11 +619,13 @@ mod fixtures {
660
619
661
620
#[ fixture]
662
621
pub fn etag_certificate_tree ( ) -> ExprTree {
663
- let etag_caching_match_cel = etag_caching_match_cel ( ) ;
622
+ let etag_caching_match_certification = etag_caching_match_cel ( ) ;
623
+ let etag_caching_match_cel = etag_caching_match_certification. to_string ( ) ;
664
624
let etag_caching_match_cel_hash = hash ( etag_caching_match_cel. as_bytes ( ) ) ;
665
- let etag_caching_match_certification = cel_to_certification ( & etag_caching_match_cel)
666
- . unwrap ( )
667
- . unwrap ( ) ;
625
+
626
+ let CelExpression :: DefaultCertification ( Some ( etag_caching_match_certification) ) = etag_caching_match_certification else {
627
+ panic ! ( "Expected asset certification to have response certification" )
628
+ } ;
668
629
let etag_caching_match_response_hash = response_hash (
669
630
& etag_caching_match_response ( ) ,
670
631
& etag_caching_match_certification. response_certification ,
@@ -677,11 +638,13 @@ mod fixtures {
677
638
)
678
639
. unwrap ( ) ;
679
640
680
- let etag_caching_mismatch_cel = etag_caching_mismatch_cel ( ) ;
641
+ let etag_caching_mismatch_certification = etag_caching_mismatch_cel ( ) ;
642
+ let etag_caching_mismatch_cel = etag_caching_mismatch_certification. to_string ( ) ;
681
643
let etag_caching_mismatch_cel_hash = hash ( etag_caching_mismatch_cel. as_bytes ( ) ) ;
682
- let etag_caching_mismatch_certification = cel_to_certification ( & etag_caching_mismatch_cel)
683
- . unwrap ( )
684
- . unwrap ( ) ;
644
+
645
+ let CelExpression :: DefaultCertification ( Some ( etag_caching_mismatch_certification) ) = etag_caching_mismatch_certification else {
646
+ panic ! ( "Expected asset certification to have response certification" )
647
+ } ;
685
648
let etag_caching_mismatch_response_hash = response_hash (
686
649
& etag_caching_mismatch_response ( ) ,
687
650
& etag_caching_mismatch_certification. response_certification ,
0 commit comments