Skip to content

Commit 6df5d3a

Browse files
committed
test: use cel expression builder in response verification integration tests
1 parent 1ee5f7c commit 6df5d3a

File tree

3 files changed

+147
-216
lines changed

3 files changed

+147
-216
lines changed

packages/ic-response-verification/tests/v2_response_verification_certification_scenarios.rs

Lines changed: 60 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,12 @@ mod tests {
296296

297297
#[cfg(not(target_arch = "wasm32"))]
298298
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,
303302
};
304303
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,
306305
};
307306
use rstest::*;
308307

@@ -324,7 +323,7 @@ mod fixtures {
324323
headers: vec![
325324
("Content-Type".into(), "text/html".into()),
326325
("Content-Encoding".into(), "gzip".into()),
327-
("IC-CertificateExpression".into(), cel),
326+
("IC-CertificateExpression".into(), cel.to_string()),
328327
],
329328
}
330329
}
@@ -340,7 +339,7 @@ mod fixtures {
340339
headers: vec![
341340
("Content-Type".into(), "text/javascript".into()),
342341
("Content-Encoding".into(), "gzip".into()),
343-
("IC-CertificateExpression".into(), cel),
342+
("IC-CertificateExpression".into(), cel.to_string()),
344343
],
345344
}
346345
}
@@ -356,7 +355,7 @@ mod fixtures {
356355
headers: vec![
357356
("Content-Type".into(), "text/plain".into()),
358357
("Content-Encoding".into(), "identity".into()),
359-
("IC-CertificateExpression".into(), cel),
358+
("IC-CertificateExpression".into(), cel.to_string()),
360359
],
361360
}
362361
}
@@ -371,7 +370,7 @@ mod fixtures {
371370
body: body.to_vec(),
372371
headers: vec![
373372
("Location".into(), "/new-path".into()),
374-
("IC-CertificateExpression".into(), cel),
373+
("IC-CertificateExpression".into(), cel.to_string()),
375374
],
376375
}
377376
}
@@ -386,7 +385,7 @@ mod fixtures {
386385
headers: vec![
387386
("Content-Type".into(), "text/html".into()),
388387
("Content-Encoding".into(), "identity".into()),
389-
("IC-CertificateExpression".into(), cel),
388+
("IC-CertificateExpression".into(), cel.to_string()),
390389
],
391390
}
392391
}
@@ -401,7 +400,7 @@ mod fixtures {
401400
headers: vec![
402401
("Content-Type".into(), "text/html".into()),
403402
("Content-Encoding".into(), "gzip".into()),
404-
("IC-CertificateExpression".into(), cel),
403+
("IC-CertificateExpression".into(), cel.to_string()),
405404
],
406405
}
407406
}
@@ -416,7 +415,7 @@ mod fixtures {
416415
headers: vec![
417416
("Content-Type".into(), "text/html".into()),
418417
("Content-Encoding".into(), "deflate".into()),
419-
("IC-CertificateExpression".into(), cel),
418+
("IC-CertificateExpression".into(), cel.to_string()),
420419
],
421420
}
422421
}
@@ -448,7 +447,7 @@ mod fixtures {
448447
headers: vec![
449448
("Content-Type".into(), "text/html".into()),
450449
("Content-Encoding".into(), "deflate".into()),
451-
("IC-CertificateExpression".into(), cel),
450+
("IC-CertificateExpression".into(), cel.to_string()),
452451
],
453452
}
454453
}
@@ -482,100 +481,57 @@ mod fixtures {
482481
("Content-Type".into(), "text/html".into()),
483482
("Content-Encoding".into(), "deflate".into()),
484483
("ETag".into(), etag),
485-
("IC-CertificateExpression".into(), cel),
484+
("IC-CertificateExpression".into(), cel.to_string()),
486485
],
487486
}
488487
}
489488

490489
#[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()
508496
}
509497

510498
#[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()
528505
}
529506

530507
#[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()
551515
}
552516

553517
#[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()
571524
}
572525

573526
#[fixture]
574527
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();
576530
let asset_cel_hash = hash(asset_cel.as_bytes());
577-
let asset_certification = cel_to_certification(&asset_cel).unwrap().unwrap();
578531

532+
let CelExpression::DefaultCertification(Some(asset_certification)) = asset_certification else {
533+
panic!("Expected asset certification to have response certification")
534+
};
579535
let index_html_response_hash = response_hash(
580536
&index_html_response(),
581537
&asset_certification.response_certification,
@@ -589,10 +545,13 @@ mod fixtures {
589545
&asset_certification.response_certification,
590546
);
591547

592-
let redirect_cel = redirect_cel();
548+
let redirect_certification = redirect_cel();
549+
let redirect_cel = redirect_certification.to_string();
593550
let redirect_cel_hash = hash(redirect_cel.as_bytes());
594-
let redirect_certification = cel_to_certification(&redirect_cel).unwrap().unwrap();
595551

552+
let CelExpression::DefaultCertification(Some(redirect_certification)) = redirect_certification else {
553+
panic!("Expected asset certification to have response certification")
554+
};
596555
let redirect_response_hash = response_hash(
597556
&redirect_response(),
598557
&redirect_certification.response_certification,
@@ -660,11 +619,13 @@ mod fixtures {
660619

661620
#[fixture]
662621
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();
664624
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+
};
668629
let etag_caching_match_response_hash = response_hash(
669630
&etag_caching_match_response(),
670631
&etag_caching_match_certification.response_certification,
@@ -677,11 +638,13 @@ mod fixtures {
677638
)
678639
.unwrap();
679640

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();
681643
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+
};
685648
let etag_caching_mismatch_response_hash = response_hash(
686649
&etag_caching_mismatch_response(),
687650
&etag_caching_mismatch_certification.response_certification,

0 commit comments

Comments
 (0)