Lines Matching refs:fixture

43 static void tear_down(CMP_VFY_TEST_FIXTURE *fixture)  in tear_down()  argument
45 OSSL_CMP_MSG_free(fixture->msg); in tear_down()
46 OSSL_CMP_CTX_free(fixture->cmp_ctx); in tear_down()
47 OPENSSL_free(fixture); in tear_down()
55 CMP_VFY_TEST_FIXTURE *fixture; in set_up() local
57 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) in set_up()
61 fixture->test_case_name = test_case_name; in set_up()
63 || !TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(libctx, NULL)) in set_up()
64 || !OSSL_CMP_CTX_set0_trusted(fixture->cmp_ctx, ts) in set_up()
65 || !OSSL_CMP_CTX_set_log_cb(fixture->cmp_ctx, print_to_bio_out)) { in set_up()
66 tear_down(fixture); in set_up()
72 return fixture; in set_up()
100 static int execute_verify_popo_test(CMP_VFY_TEST_FIXTURE *fixture) in execute_verify_popo_test() argument
102 if ((fixture->msg = load_pkimsg(ir_protected_f, libctx)) == NULL) in execute_verify_popo_test()
104 if (fixture->expected == 0) { in execute_verify_popo_test()
105 const OSSL_CRMF_MSGS *reqs = fixture->msg->body->value.ir; in execute_verify_popo_test()
111 return TEST_int_eq(fixture->expected, in execute_verify_popo_test()
112 ossl_cmp_verify_popo(fixture->cmp_ctx, fixture->msg, in execute_verify_popo_test()
113 fixture->additional_arg)); in execute_verify_popo_test()
119 fixture->expected = 1; in test_verify_popo()
128 fixture->expected = 0; in test_verify_popo_bad()
135 static int execute_validate_msg_test(CMP_VFY_TEST_FIXTURE *fixture) in execute_validate_msg_test() argument
137 int res = TEST_int_eq(fixture->expected, in execute_validate_msg_test()
138 ossl_cmp_msg_check_update(fixture->cmp_ctx, in execute_validate_msg_test()
139 fixture->msg, NULL, 0)); in execute_validate_msg_test()
140 X509 *validated = OSSL_CMP_CTX_get0_validatedSrvCert(fixture->cmp_ctx); in execute_validate_msg_test()
142 return res && (!fixture->expected || TEST_ptr_eq(validated, fixture->cert)); in execute_validate_msg_test()
145 static int execute_validate_cert_path_test(CMP_VFY_TEST_FIXTURE *fixture) in execute_validate_cert_path_test() argument
147 X509_STORE *ts = OSSL_CMP_CTX_get0_trusted(fixture->cmp_ctx); in execute_validate_cert_path_test()
148 int res = TEST_int_eq(fixture->expected, in execute_validate_cert_path_test()
149 OSSL_CMP_validate_cert_path(fixture->cmp_ctx, in execute_validate_cert_path_test()
150 ts, fixture->cert)); in execute_validate_cert_path_test()
152 OSSL_CMP_CTX_print_errors(fixture->cmp_ctx); in execute_validate_cert_path_test()
159 fixture->cert = NULL; in test_validate_msg_mac_alg_protection()
161 fixture->expected = !miss && !wrong; in test_validate_msg_mac_alg_protection()
162 if (!TEST_true(miss ? OSSL_CMP_CTX_set0_trusted(fixture->cmp_ctx, NULL) in test_validate_msg_mac_alg_protection()
163 : OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_1, in test_validate_msg_mac_alg_protection()
165 || !TEST_ptr(fixture->msg = load_pkimsg(ip_waiting_f, libctx))) { in test_validate_msg_mac_alg_protection()
166 tear_down(fixture); in test_validate_msg_mac_alg_protection()
167 fixture = NULL; in test_validate_msg_mac_alg_protection()
197 fixture->cert = NULL; in test_validate_msg_mac_alg_protection_bad()
198 fixture->expected = 0; in test_validate_msg_mac_alg_protection_bad()
200 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_bad, in test_validate_msg_mac_alg_protection_bad()
202 || !TEST_ptr(fixture->msg = load_pkimsg(ip_waiting_f, libctx))) { in test_validate_msg_mac_alg_protection_bad()
203 tear_down(fixture); in test_validate_msg_mac_alg_protection_bad()
204 fixture = NULL; in test_validate_msg_mac_alg_protection_bad()
227 fixture->cert = srvcert; in test_validate_msg_signature_partial_chain()
229 ts = OSSL_CMP_CTX_get0_trusted(fixture->cmp_ctx); in test_validate_msg_signature_partial_chain()
230 fixture->expected = !expired; in test_validate_msg_signature_partial_chain()
232 || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx)) in test_validate_msg_signature_partial_chain()
233 || !add_trusted(fixture->cmp_ctx, srvcert)) { in test_validate_msg_signature_partial_chain()
234 tear_down(fixture); in test_validate_msg_signature_partial_chain()
235 fixture = NULL; in test_validate_msg_signature_partial_chain()
262 fixture->cert = srvcert; in test_validate_msg_signature_srvcert()
263 fixture->expected = !bad_sig && !wrong && !miss; in test_validate_msg_signature_srvcert()
264 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx)) in test_validate_msg_signature_srvcert()
265 || !TEST_true(miss ? OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_validate_msg_signature_srvcert()
267 : OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, in test_validate_msg_signature_srvcert()
269 || (bad_sig && !flip_bit(fixture->msg->protection))) { in test_validate_msg_signature_srvcert()
270 tear_down(fixture); in test_validate_msg_signature_srvcert()
271 fixture = NULL; in test_validate_msg_signature_srvcert()
304 fixture->cert = insta_cert; in test_validate_msg_signature_sender_cert_untrusted()
305 fixture->expected = 1; in test_validate_msg_signature_sender_cert_untrusted()
306 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_0_extracerts, libctx)) in test_validate_msg_signature_sender_cert_untrusted()
307 || !add_trusted(fixture->cmp_ctx, instaca_cert) in test_validate_msg_signature_sender_cert_untrusted()
308 || !add_untrusted(fixture->cmp_ctx, insta_cert)) { in test_validate_msg_signature_sender_cert_untrusted()
309 tear_down(fixture); in test_validate_msg_signature_sender_cert_untrusted()
310 fixture = NULL; in test_validate_msg_signature_sender_cert_untrusted()
319 fixture->cert = insta_cert; in test_validate_msg_signature_sender_cert_trusted()
320 fixture->expected = 1; in test_validate_msg_signature_sender_cert_trusted()
321 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_0_extracerts, libctx)) in test_validate_msg_signature_sender_cert_trusted()
322 || !add_trusted(fixture->cmp_ctx, instaca_cert) in test_validate_msg_signature_sender_cert_trusted()
323 || !add_trusted(fixture->cmp_ctx, insta_cert)) { in test_validate_msg_signature_sender_cert_trusted()
324 tear_down(fixture); in test_validate_msg_signature_sender_cert_trusted()
325 fixture = NULL; in test_validate_msg_signature_sender_cert_trusted()
334 fixture->expected = 1; in test_validate_msg_signature_sender_cert_extracert()
335 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_2_extracerts, libctx)) in test_validate_msg_signature_sender_cert_extracert()
336 || !add_trusted(fixture->cmp_ctx, instaca_cert)) { in test_validate_msg_signature_sender_cert_extracert()
337 tear_down(fixture); in test_validate_msg_signature_sender_cert_extracert()
338 fixture = NULL; in test_validate_msg_signature_sender_cert_extracert()
340 fixture->cert = sk_X509_value(fixture->msg->extraCerts, 1); /* Insta CA */ in test_validate_msg_signature_sender_cert_extracert()
350 fixture->expected = 0; in test_validate_msg_signature_sender_cert_absent()
351 if (!TEST_ptr(fixture->msg = in test_validate_msg_signature_sender_cert_absent()
353 tear_down(fixture); in test_validate_msg_signature_sender_cert_absent()
354 fixture = NULL; in test_validate_msg_signature_sender_cert_absent()
364 fixture->cert = srvcert; in test_validate_with_sender()
365 fixture->expected = expected; in test_validate_with_sender()
366 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx)) in test_validate_with_sender()
367 || !TEST_true(OSSL_CMP_CTX_set1_expected_sender(fixture->cmp_ctx, name)) in test_validate_with_sender()
368 || !TEST_true(OSSL_CMP_CTX_set1_srvCert(fixture->cmp_ctx, srvcert))) { in test_validate_with_sender()
369 tear_down(fixture); in test_validate_with_sender()
370 fixture = NULL; in test_validate_with_sender()
390 fixture->expected = 0; in test_validate_msg_unprotected_request()
391 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f, libctx))) { in test_validate_msg_unprotected_request()
392 tear_down(fixture); in test_validate_msg_unprotected_request()
393 fixture = NULL; in test_validate_msg_unprotected_request()
400 static void setup_path(CMP_VFY_TEST_FIXTURE **fixture, X509 *wrong, int expired) in setup_path() argument
402 (*fixture)->cert = endentity2; in setup_path()
403 (*fixture)->expected = wrong == NULL && !expired; in setup_path()
405 X509_STORE *ts = OSSL_CMP_CTX_get0_trusted((*fixture)->cmp_ctx); in setup_path()
410 if (!add_trusted((*fixture)->cmp_ctx, wrong == NULL ? root : wrong) in setup_path()
411 || !add_untrusted((*fixture)->cmp_ctx, endentity1) in setup_path()
412 || !add_untrusted((*fixture)->cmp_ctx, intermediate)) { in setup_path()
413 tear_down((*fixture)); in setup_path()
414 (*fixture) = NULL; in setup_path()
421 setup_path(&fixture, NULL, 0); in test_validate_cert_path_ok()
429 setup_path(&fixture, srvcert /* wrong/non-root cert */, 0); in test_validate_cert_path_wrong_anchor()
437 setup_path(&fixture, NULL, 1); in test_validate_cert_path_expired()
442 static int execute_msg_check_test(CMP_VFY_TEST_FIXTURE *fixture) in execute_msg_check_test() argument
444 const OSSL_CMP_PKIHEADER *hdr = OSSL_CMP_MSG_get0_header(fixture->msg); in execute_msg_check_test()
447 if (!TEST_int_eq(fixture->expected, in execute_msg_check_test()
448 ossl_cmp_msg_check_update(fixture->cmp_ctx, in execute_msg_check_test()
449 fixture->msg, in execute_msg_check_test()
450 fixture->allow_unprotected_cb, in execute_msg_check_test()
451 fixture->additional_arg))) in execute_msg_check_test()
454 if (fixture->expected == 0) /* error expected already during above check */ in execute_msg_check_test()
459 fixture->cmp_ctx->recipNonce)) in execute_msg_check_test()
462 fixture->cmp_ctx->transactionID)); in execute_msg_check_test()
471 static void setup_check_update(CMP_VFY_TEST_FIXTURE **fixture, int expected, in setup_check_update() argument
476 OSSL_CMP_CTX *ctx = (*fixture)->cmp_ctx; in setup_check_update()
479 (*fixture)->expected = expected; in setup_check_update()
480 (*fixture)->allow_unprotected_cb = cb; in setup_check_update()
481 (*fixture)->additional_arg = arg; in setup_check_update()
482 (*fixture)->msg = OSSL_CMP_MSG_dup(ir_rmprotection); in setup_check_update()
483 if ((*fixture)->msg == NULL in setup_check_update()
487 tear_down((*fixture)); in setup_check_update()
488 (*fixture) = NULL; in setup_check_update()
496 tear_down((*fixture)); in setup_check_update()
497 (*fixture) = NULL; in setup_check_update()
507 setup_check_update(&fixture, 0, NULL, 0, NULL, NULL); in test_msg_check_no_protection_no_cb()
515 setup_check_update(&fixture, 0, allow_unprotected, 0, NULL, NULL); in test_msg_check_no_protection_restrictive_cb()
524 setup_check_update(&fixture, 1, allow_unprotected, 1, NULL, NULL); in test_msg_check_no_protection_permissive_cb()
538 setup_check_update(&fixture, 1, allow_unprotected, 1, trans_id, NULL); in test_msg_check_transaction_id()
547 setup_check_update(&fixture, 0, allow_unprotected, 1, rand_data, NULL); in test_msg_check_transaction_id_bad()
562 setup_check_update(&fixture, 1, allow_unprotected, 1, NULL, rec_nonce); in test_msg_check_recipient_nonce()
571 setup_check_update(&fixture, 0, allow_unprotected, 1, NULL, rand_data); in test_msg_check_recipient_nonce_bad()