Lines Matching refs:fixture

39 static void tear_down(CMP_PROTECT_TEST_FIXTURE *fixture)  in tear_down()  argument
41 if (fixture != NULL) { in tear_down()
42 OSSL_CMP_CTX_free(fixture->cmp_ctx); in tear_down()
43 OSSL_CMP_MSG_free(fixture->msg); in tear_down()
44 OSSL_CMP_PKISI_free(fixture->si); in tear_down()
46 OPENSSL_free(fixture->mem); in tear_down()
47 sk_X509_free(fixture->certs); in tear_down()
48 sk_X509_free(fixture->chain); in tear_down()
50 OPENSSL_free(fixture); in tear_down()
56 CMP_PROTECT_TEST_FIXTURE *fixture; in set_up() local
58 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) in set_up()
60 fixture->test_case_name = test_case_name; in set_up()
61 if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(libctx, NULL))) { in set_up()
62 tear_down(fixture); in set_up()
65 return fixture; in set_up()
80 static int execute_calc_protection_fails_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_calc_protection_fails_test() argument
83 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_fails_test()
90 static int execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_calc_protection_pbmac_test() argument
93 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_pbmac_test()
96 fixture->msg->protection) == 0); in execute_calc_protection_pbmac_test()
121 fixture) in execute_calc_protection_signature_test() argument
124 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_signature_test()
126 && TEST_true(verify_signature(fixture->msg, protection, in execute_calc_protection_signature_test()
127 fixture->pubkey, in execute_calc_protection_signature_test()
128 fixture->cmp_ctx->digest))); in execute_calc_protection_signature_test()
137 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f, libctx)) in test_cmp_calc_protection_no_key_no_secret()
138 || !TEST_ptr(fixture->msg->header->protectionAlg = in test_cmp_calc_protection_no_key_no_secret()
140 tear_down(fixture); in test_cmp_calc_protection_no_key_no_secret()
141 fixture = NULL; in test_cmp_calc_protection_no_key_no_secret()
151 fixture->pubkey = prot_RSA_key; in test_cmp_calc_protection_pkey()
152 if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, prot_RSA_key)) in test_cmp_calc_protection_pkey()
153 || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))) { in test_cmp_calc_protection_pkey()
154 tear_down(fixture); in test_cmp_calc_protection_pkey()
155 fixture = NULL; in test_cmp_calc_protection_pkey()
165 fixture->pubkey = prot_Ed_key; in test_cmp_calc_protection_pkey_Ed()
166 if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, prot_Ed_key)) in test_cmp_calc_protection_pkey_Ed()
167 || !TEST_ptr(fixture->msg = load_pkimsg(genm_prot_Ed_f, libctx))) { in test_cmp_calc_protection_pkey_Ed()
168 tear_down(fixture); in test_cmp_calc_protection_pkey_Ed()
169 fixture = NULL; in test_cmp_calc_protection_pkey_Ed()
181 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_cmp_calc_protection_pbmac()
183 || !TEST_ptr(fixture->msg = load_pkimsg(ip_PBM_f, libctx))) { in test_cmp_calc_protection_pbmac()
184 tear_down(fixture); in test_cmp_calc_protection_pbmac()
185 fixture = NULL; in test_cmp_calc_protection_pbmac()
190 static int execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_MSG_protect_test() argument
192 return TEST_int_eq(fixture->expected, in execute_MSG_protect_test()
193 ossl_cmp_msg_protect(fixture->cmp_ctx, fixture->msg)); in execute_MSG_protect_test()
202 fixture->expected = 1; in test_MSG_protect_unprotected_request()
203 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_unprotected_request()
204 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))) { in test_MSG_protect_unprotected_request()
205 tear_down(fixture); in test_MSG_protect_unprotected_request()
206 fixture = NULL; in test_MSG_protect_unprotected_request()
217 fixture->expected = 1; in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
219 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
220 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
225 || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
227 || !TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
230 tear_down(fixture); in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
231 fixture = NULL; in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
240 fixture->expected = 1; in test_MSG_protect_with_certificate_and_key()
242 if (!TEST_ptr(fixture->msg = in test_MSG_protect_with_certificate_and_key()
244 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) in test_MSG_protect_with_certificate_and_key()
245 || !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, server_key)) in test_MSG_protect_with_certificate_and_key()
246 || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, in test_MSG_protect_with_certificate_and_key()
248 tear_down(fixture); in test_MSG_protect_with_certificate_and_key()
249 fixture = NULL; in test_MSG_protect_with_certificate_and_key()
260 ctx = fixture->cmp_ctx; in test_MSG_protect_certificate_based_without_cert()
261 fixture->expected = 0; in test_MSG_protect_certificate_based_without_cert()
262 if (!TEST_ptr(fixture->msg = in test_MSG_protect_certificate_based_without_cert()
266 tear_down(fixture); in test_MSG_protect_certificate_based_without_cert()
267 fixture = NULL; in test_MSG_protect_certificate_based_without_cert()
277 fixture->expected = 0; in test_MSG_protect_no_key_no_secret()
278 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_no_key_no_secret()
279 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))) { in test_MSG_protect_no_key_no_secret()
280 tear_down(fixture); in test_MSG_protect_no_key_no_secret()
281 fixture = NULL; in test_MSG_protect_no_key_no_secret()
293 fixture->expected = with_ref; in test_MSG_protect_pbmac_no_sender()
294 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_pbmac_no_sender()
295 || !SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0) in test_MSG_protect_pbmac_no_sender()
296 || !ossl_cmp_hdr_set1_sender(fixture->msg->header, NULL) in test_MSG_protect_pbmac_no_sender()
297 || !OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_MSG_protect_pbmac_no_sender()
299 || (!OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, in test_MSG_protect_pbmac_no_sender()
302 tear_down(fixture); in test_MSG_protect_pbmac_no_sender()
303 fixture = NULL; in test_MSG_protect_pbmac_no_sender()
319 static int execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_MSG_add_extraCerts_test() argument
321 return TEST_true(ossl_cmp_msg_add_extraCerts(fixture->cmp_ctx, in execute_MSG_add_extraCerts_test()
322 fixture->msg)); in execute_MSG_add_extraCerts_test()
328 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_protected))) { in test_MSG_add_extraCerts()
329 tear_down(fixture); in test_MSG_add_extraCerts()
330 fixture = NULL; in test_MSG_add_extraCerts()
338 static int execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_cmp_build_cert_chain_test() argument
341 OSSL_CMP_CTX *ctx = fixture->cmp_ctx; in execute_cmp_build_cert_chain_test()
344 X509_build_chain(fixture->cert, fixture->certs, NULL, in execute_cmp_build_cert_chain_test()
345 fixture->with_ss, ctx->libctx, ctx->propq); in execute_cmp_build_cert_chain_test()
349 ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain)); in execute_cmp_build_cert_chain_test()
359 chain = X509_build_chain(fixture->cert, fixture->certs, store, in execute_cmp_build_cert_chain_test()
360 fixture->with_ss, ctx->libctx, ctx->propq); in execute_cmp_build_cert_chain_test()
361 ret = TEST_int_eq(fixture->expected, chain != NULL); in execute_cmp_build_cert_chain_test()
364 ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain)); in execute_cmp_build_cert_chain_test()
375 fixture->expected = 1; in test_cmp_build_cert_chain()
376 fixture->with_ss = 0; in test_cmp_build_cert_chain()
377 fixture->cert = endentity2; in test_cmp_build_cert_chain()
378 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain()
379 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain()
380 || !TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_cmp_build_cert_chain()
381 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_cmp_build_cert_chain()
382 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_cmp_build_cert_chain()
383 || !TEST_true(sk_X509_push(fixture->chain, endentity2)) in test_cmp_build_cert_chain()
384 || !TEST_true(sk_X509_push(fixture->chain, intermediate))) { in test_cmp_build_cert_chain()
385 tear_down(fixture); in test_cmp_build_cert_chain()
386 fixture = NULL; in test_cmp_build_cert_chain()
388 if (fixture != NULL) { in test_cmp_build_cert_chain()
389 result = execute_cmp_build_cert_chain_test(fixture); in test_cmp_build_cert_chain()
390 fixture->with_ss = 1; in test_cmp_build_cert_chain()
391 if (result && TEST_true(sk_X509_push(fixture->chain, root))) in test_cmp_build_cert_chain()
392 result = execute_cmp_build_cert_chain_test(fixture); in test_cmp_build_cert_chain()
394 tear_down(fixture); in test_cmp_build_cert_chain()
401 fixture->expected = 0; in test_cmp_build_cert_chain_missing_intermediate()
402 fixture->with_ss = 0; in test_cmp_build_cert_chain_missing_intermediate()
403 fixture->cert = endentity2; in test_cmp_build_cert_chain_missing_intermediate()
404 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_missing_intermediate()
405 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_missing_intermediate()
406 || !TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_cmp_build_cert_chain_missing_intermediate()
407 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_cmp_build_cert_chain_missing_intermediate()
408 || !TEST_true(sk_X509_push(fixture->chain, endentity2))) { in test_cmp_build_cert_chain_missing_intermediate()
409 tear_down(fixture); in test_cmp_build_cert_chain_missing_intermediate()
410 fixture = NULL; in test_cmp_build_cert_chain_missing_intermediate()
419 fixture->expected = 1; in test_cmp_build_cert_chain_no_root()
420 fixture->with_ss = 0; in test_cmp_build_cert_chain_no_root()
421 fixture->cert = endentity2; in test_cmp_build_cert_chain_no_root()
422 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_no_root()
423 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_no_root()
424 || !TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_cmp_build_cert_chain_no_root()
425 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_cmp_build_cert_chain_no_root()
426 || !TEST_true(sk_X509_push(fixture->chain, endentity2)) in test_cmp_build_cert_chain_no_root()
427 || !TEST_true(sk_X509_push(fixture->chain, intermediate))) { in test_cmp_build_cert_chain_no_root()
428 tear_down(fixture); in test_cmp_build_cert_chain_no_root()
429 fixture = NULL; in test_cmp_build_cert_chain_no_root()
438 fixture->expected = 1; in test_cmp_build_cert_chain_only_root()
439 fixture->with_ss = 0; /* still chain must include the only cert (root) */ in test_cmp_build_cert_chain_only_root()
440 fixture->cert = root; in test_cmp_build_cert_chain_only_root()
441 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_only_root()
442 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_only_root()
443 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_cmp_build_cert_chain_only_root()
444 || !TEST_true(sk_X509_push(fixture->chain, root))) { in test_cmp_build_cert_chain_only_root()
445 tear_down(fixture); in test_cmp_build_cert_chain_only_root()
446 fixture = NULL; in test_cmp_build_cert_chain_only_root()
455 fixture->expected = 0; in test_cmp_build_cert_chain_no_certs()
456 fixture->with_ss = 0; in test_cmp_build_cert_chain_no_certs()
457 fixture->cert = endentity2; in test_cmp_build_cert_chain_no_certs()
458 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_no_certs()
459 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_no_certs()
460 || !TEST_true(sk_X509_push(fixture->chain, endentity2))) { in test_cmp_build_cert_chain_no_certs()
461 tear_down(fixture); in test_cmp_build_cert_chain_no_certs()
462 fixture = NULL; in test_cmp_build_cert_chain_no_certs()
469 static int execute_X509_STORE_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_X509_STORE_test() argument
476 fixture->certs, in execute_X509_STORE_test()
477 fixture->callback_arg))) in execute_X509_STORE_test()
480 if (!TEST_int_eq(0, STACK_OF_X509_cmp(sk, fixture->chain))) in execute_X509_STORE_test()
493 fixture->callback_arg = 0; /* self-issued allowed */ in test_X509_STORE()
494 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_X509_STORE()
495 || !sk_X509_push(fixture->certs, endentity1) in test_X509_STORE()
496 || !sk_X509_push(fixture->certs, endentity2) in test_X509_STORE()
497 || !sk_X509_push(fixture->certs, root) in test_X509_STORE()
498 || !sk_X509_push(fixture->certs, intermediate) in test_X509_STORE()
499 || !TEST_ptr(fixture->chain = sk_X509_dup(fixture->certs))) { in test_X509_STORE()
500 tear_down(fixture); in test_X509_STORE()
501 fixture = NULL; in test_X509_STORE()
510 fixture->certs = sk_X509_new_null(); in test_X509_STORE_only_self_issued()
511 fixture->chain = sk_X509_new_null(); in test_X509_STORE_only_self_issued()
512 fixture->callback_arg = 1; /* only self-issued */ in test_X509_STORE_only_self_issued()
513 if (!TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_X509_STORE_only_self_issued()
514 || !TEST_true(sk_X509_push(fixture->certs, endentity2)) in test_X509_STORE_only_self_issued()
515 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_X509_STORE_only_self_issued()
516 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_X509_STORE_only_self_issued()
517 || !TEST_true(sk_X509_push(fixture->chain, root))) { in test_X509_STORE_only_self_issued()
518 tear_down(fixture); in test_X509_STORE_only_self_issued()
519 fixture = NULL; in test_X509_STORE_only_self_issued()