Lines Matching full:fixture
38 static void tear_down(CMP_PROTECT_TEST_FIXTURE *fixture) in tear_down() argument
40 if (fixture != NULL) { in tear_down()
41 OSSL_CMP_CTX_free(fixture->cmp_ctx); in tear_down()
42 OSSL_CMP_MSG_free(fixture->msg); in tear_down()
43 OSSL_CMP_PKISI_free(fixture->si); in tear_down()
45 OPENSSL_free(fixture->mem); in tear_down()
46 sk_X509_free(fixture->certs); in tear_down()
47 sk_X509_free(fixture->chain); in tear_down()
49 OPENSSL_free(fixture); in tear_down()
55 CMP_PROTECT_TEST_FIXTURE *fixture; in set_up() local
57 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) in set_up()
59 fixture->test_case_name = test_case_name; in set_up()
60 if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(libctx, NULL))) { in set_up()
61 tear_down(fixture); in set_up()
64 return fixture; in set_up()
76 static int execute_calc_protection_fails_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_calc_protection_fails_test() argument
79 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_fails_test()
86 static int execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_calc_protection_pbmac_test() argument
89 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_pbmac_test()
92 fixture->msg->protection) == 0); in execute_calc_protection_pbmac_test()
130 fixture) in execute_calc_protection_signature_test() argument
133 ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_signature_test()
136 fixture->msg->protection) == 0) in execute_calc_protection_signature_test()
137 && TEST_true(verify_signature(fixture->msg, protection, in execute_calc_protection_signature_test()
138 fixture->pubkey, in execute_calc_protection_signature_test()
139 fixture->cmp_ctx->digest))); in execute_calc_protection_signature_test()
148 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f, libctx)) in test_cmp_calc_protection_no_key_no_secret()
149 || !TEST_ptr(fixture->msg->header->protectionAlg = in test_cmp_calc_protection_no_key_no_secret()
151 tear_down(fixture); in test_cmp_calc_protection_no_key_no_secret()
152 fixture = NULL; in test_cmp_calc_protection_no_key_no_secret()
162 fixture->pubkey = loadedpubkey; in test_cmp_calc_protection_pkey()
163 if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedprivkey)) in test_cmp_calc_protection_pkey()
164 || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))) { in test_cmp_calc_protection_pkey()
165 tear_down(fixture); in test_cmp_calc_protection_pkey()
166 fixture = NULL; in test_cmp_calc_protection_pkey()
177 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_cmp_calc_protection_pbmac()
179 || !TEST_ptr(fixture->msg = load_pkimsg(ip_PBM_f, libctx))) { in test_cmp_calc_protection_pbmac()
180 tear_down(fixture); in test_cmp_calc_protection_pbmac()
181 fixture = NULL; in test_cmp_calc_protection_pbmac()
186 static int execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_MSG_protect_test() argument
188 return TEST_int_eq(fixture->expected, in execute_MSG_protect_test()
189 ossl_cmp_msg_protect(fixture->cmp_ctx, fixture->msg)); in execute_MSG_protect_test()
198 fixture->expected = 1; in test_MSG_protect_unprotected_request()
199 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_unprotected_request()
200 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))) { in test_MSG_protect_unprotected_request()
201 tear_down(fixture); in test_MSG_protect_unprotected_request()
202 fixture = NULL; in test_MSG_protect_unprotected_request()
213 fixture->expected = 1; in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
215 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
216 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
221 || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
223 || !TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
226 tear_down(fixture); in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
227 fixture = NULL; in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
236 fixture->expected = 1; in test_MSG_protect_with_certificate_and_key()
238 if (!TEST_ptr(fixture->msg = in test_MSG_protect_with_certificate_and_key()
240 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) in test_MSG_protect_with_certificate_and_key()
241 || !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, loadedkey)) in test_MSG_protect_with_certificate_and_key()
242 || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, cert))) { in test_MSG_protect_with_certificate_and_key()
243 tear_down(fixture); in test_MSG_protect_with_certificate_and_key()
244 fixture = NULL; in test_MSG_protect_with_certificate_and_key()
255 ctx = fixture->cmp_ctx; in test_MSG_protect_certificate_based_without_cert()
256 fixture->expected = 0; in test_MSG_protect_certificate_based_without_cert()
257 if (!TEST_ptr(fixture->msg = in test_MSG_protect_certificate_based_without_cert()
261 tear_down(fixture); in test_MSG_protect_certificate_based_without_cert()
262 fixture = NULL; in test_MSG_protect_certificate_based_without_cert()
272 fixture->expected = 0; in test_MSG_protect_no_key_no_secret()
273 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_no_key_no_secret()
274 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))) { in test_MSG_protect_no_key_no_secret()
275 tear_down(fixture); in test_MSG_protect_no_key_no_secret()
276 fixture = NULL; in test_MSG_protect_no_key_no_secret()
288 fixture->expected = with_ref; in test_MSG_protect_pbmac_no_sender()
289 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_pbmac_no_sender()
290 || !SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0) in test_MSG_protect_pbmac_no_sender()
291 || !ossl_cmp_hdr_set1_sender(fixture->msg->header, NULL) in test_MSG_protect_pbmac_no_sender()
292 || !OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_MSG_protect_pbmac_no_sender()
294 || (!OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, in test_MSG_protect_pbmac_no_sender()
297 tear_down(fixture); in test_MSG_protect_pbmac_no_sender()
298 fixture = NULL; in test_MSG_protect_pbmac_no_sender()
314 static int execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_MSG_add_extraCerts_test() argument
316 return TEST_true(ossl_cmp_msg_add_extraCerts(fixture->cmp_ctx, in execute_MSG_add_extraCerts_test()
317 fixture->msg)); in execute_MSG_add_extraCerts_test()
323 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_protected))) { in test_MSG_add_extraCerts()
324 tear_down(fixture); in test_MSG_add_extraCerts()
325 fixture = NULL; in test_MSG_add_extraCerts()
333 static int execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_cmp_build_cert_chain_test() argument
336 OSSL_CMP_CTX *ctx = fixture->cmp_ctx; in execute_cmp_build_cert_chain_test()
339 X509_build_chain(fixture->cert, fixture->certs, NULL, in execute_cmp_build_cert_chain_test()
340 fixture->with_ss, ctx->libctx, ctx->propq); in execute_cmp_build_cert_chain_test()
344 ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain)); in execute_cmp_build_cert_chain_test()
354 chain = X509_build_chain(fixture->cert, fixture->certs, store, in execute_cmp_build_cert_chain_test()
355 fixture->with_ss, ctx->libctx, ctx->propq); in execute_cmp_build_cert_chain_test()
356 ret = TEST_int_eq(fixture->expected, chain != NULL); in execute_cmp_build_cert_chain_test()
359 ret = TEST_int_eq(0, STACK_OF_X509_cmp(chain, fixture->chain)); in execute_cmp_build_cert_chain_test()
370 fixture->expected = 1; in test_cmp_build_cert_chain()
371 fixture->with_ss = 0; in test_cmp_build_cert_chain()
372 fixture->cert = endentity2; in test_cmp_build_cert_chain()
373 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain()
374 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain()
375 || !TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_cmp_build_cert_chain()
376 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_cmp_build_cert_chain()
377 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_cmp_build_cert_chain()
378 || !TEST_true(sk_X509_push(fixture->chain, endentity2)) in test_cmp_build_cert_chain()
379 || !TEST_true(sk_X509_push(fixture->chain, intermediate))) { in test_cmp_build_cert_chain()
380 tear_down(fixture); in test_cmp_build_cert_chain()
381 fixture = NULL; in test_cmp_build_cert_chain()
383 if (fixture != NULL) { in test_cmp_build_cert_chain()
384 result = execute_cmp_build_cert_chain_test(fixture); in test_cmp_build_cert_chain()
385 fixture->with_ss = 1; in test_cmp_build_cert_chain()
386 if (result && TEST_true(sk_X509_push(fixture->chain, root))) in test_cmp_build_cert_chain()
387 result = execute_cmp_build_cert_chain_test(fixture); in test_cmp_build_cert_chain()
389 tear_down(fixture); in test_cmp_build_cert_chain()
396 fixture->expected = 0; in test_cmp_build_cert_chain_missing_intermediate()
397 fixture->with_ss = 0; in test_cmp_build_cert_chain_missing_intermediate()
398 fixture->cert = endentity2; in test_cmp_build_cert_chain_missing_intermediate()
399 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_missing_intermediate()
400 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_missing_intermediate()
401 || !TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_cmp_build_cert_chain_missing_intermediate()
402 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_cmp_build_cert_chain_missing_intermediate()
403 || !TEST_true(sk_X509_push(fixture->chain, endentity2))) { in test_cmp_build_cert_chain_missing_intermediate()
404 tear_down(fixture); in test_cmp_build_cert_chain_missing_intermediate()
405 fixture = NULL; in test_cmp_build_cert_chain_missing_intermediate()
414 fixture->expected = 1; in test_cmp_build_cert_chain_no_root()
415 fixture->with_ss = 0; in test_cmp_build_cert_chain_no_root()
416 fixture->cert = endentity2; in test_cmp_build_cert_chain_no_root()
417 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_no_root()
418 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_no_root()
419 || !TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_cmp_build_cert_chain_no_root()
420 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_cmp_build_cert_chain_no_root()
421 || !TEST_true(sk_X509_push(fixture->chain, endentity2)) in test_cmp_build_cert_chain_no_root()
422 || !TEST_true(sk_X509_push(fixture->chain, intermediate))) { in test_cmp_build_cert_chain_no_root()
423 tear_down(fixture); in test_cmp_build_cert_chain_no_root()
424 fixture = NULL; in test_cmp_build_cert_chain_no_root()
433 fixture->expected = 1; in test_cmp_build_cert_chain_only_root()
434 fixture->with_ss = 0; /* still chain must include the only cert (root) */ in test_cmp_build_cert_chain_only_root()
435 fixture->cert = root; in test_cmp_build_cert_chain_only_root()
436 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_only_root()
437 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_only_root()
438 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_cmp_build_cert_chain_only_root()
439 || !TEST_true(sk_X509_push(fixture->chain, root))) { in test_cmp_build_cert_chain_only_root()
440 tear_down(fixture); in test_cmp_build_cert_chain_only_root()
441 fixture = NULL; in test_cmp_build_cert_chain_only_root()
450 fixture->expected = 0; in test_cmp_build_cert_chain_no_certs()
451 fixture->with_ss = 0; in test_cmp_build_cert_chain_no_certs()
452 fixture->cert = endentity2; in test_cmp_build_cert_chain_no_certs()
453 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_cmp_build_cert_chain_no_certs()
454 || !TEST_ptr(fixture->chain = sk_X509_new_null()) in test_cmp_build_cert_chain_no_certs()
455 || !TEST_true(sk_X509_push(fixture->chain, endentity2))) { in test_cmp_build_cert_chain_no_certs()
456 tear_down(fixture); in test_cmp_build_cert_chain_no_certs()
457 fixture = NULL; in test_cmp_build_cert_chain_no_certs()
464 static int execute_X509_STORE_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_X509_STORE_test() argument
471 fixture->certs, in execute_X509_STORE_test()
472 fixture->callback_arg))) in execute_X509_STORE_test()
475 if (!TEST_int_eq(0, STACK_OF_X509_cmp(sk, fixture->chain))) in execute_X509_STORE_test()
488 fixture->callback_arg = 0; /* self-issued allowed */ in test_X509_STORE()
489 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_X509_STORE()
490 || !sk_X509_push(fixture->certs, endentity1) in test_X509_STORE()
491 || !sk_X509_push(fixture->certs, endentity2) in test_X509_STORE()
492 || !sk_X509_push(fixture->certs, root) in test_X509_STORE()
493 || !sk_X509_push(fixture->certs, intermediate) in test_X509_STORE()
494 || !TEST_ptr(fixture->chain = sk_X509_dup(fixture->certs))) { in test_X509_STORE()
495 tear_down(fixture); in test_X509_STORE()
496 fixture = NULL; in test_X509_STORE()
505 fixture->certs = sk_X509_new_null(); in test_X509_STORE_only_self_issued()
506 fixture->chain = sk_X509_new_null(); in test_X509_STORE_only_self_issued()
507 fixture->callback_arg = 1; /* only self-issued */ in test_X509_STORE_only_self_issued()
508 if (!TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_X509_STORE_only_self_issued()
509 || !TEST_true(sk_X509_push(fixture->certs, endentity2)) in test_X509_STORE_only_self_issued()
510 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_X509_STORE_only_self_issued()
511 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_X509_STORE_only_self_issued()
512 || !TEST_true(sk_X509_push(fixture->chain, root))) { in test_X509_STORE_only_self_issued()
513 tear_down(fixture); in test_X509_STORE_only_self_issued()
514 fixture = NULL; in test_X509_STORE_only_self_issued()