Lines Matching full: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
82 ASN1_BIT_STRING *protection = ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_fails_test()
89 static int execute_calc_protection_pbmac_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_calc_protection_pbmac_test() argument
91 ASN1_BIT_STRING *protection = ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_pbmac_test()
94 fixture->msg->protection) in execute_calc_protection_pbmac_test()
121 fixture) in execute_calc_protection_signature_test()
123 ASN1_BIT_STRING *protection = ossl_cmp_calc_protection(fixture->cmp_ctx, fixture->msg); in execute_calc_protection_signature_test()
125 && TEST_true(verify_signature(fixture->msg, protection, in execute_calc_protection_signature_test()
126 fixture->pubkey, in execute_calc_protection_signature_test()
127 fixture->cmp_ctx->digest))); in execute_calc_protection_signature_test()
136 if (!TEST_ptr(fixture->msg = load_pkimsg(ir_unprotected_f, libctx)) in test_cmp_calc_protection_no_key_no_secret()
137 …|| !TEST_ptr(fixture->msg->header->protectionAlg = X509_ALGOR_new() /* no specific alg needed here… in test_cmp_calc_protection_no_key_no_secret()
138 tear_down(fixture); in test_cmp_calc_protection_no_key_no_secret()
139 fixture = NULL; in test_cmp_calc_protection_no_key_no_secret()
149 fixture->pubkey = prot_RSA_key; in test_cmp_calc_protection_pkey()
150 if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, prot_RSA_key)) in test_cmp_calc_protection_pkey()
151 || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f, libctx))) { in test_cmp_calc_protection_pkey()
152 tear_down(fixture); in test_cmp_calc_protection_pkey()
153 fixture = NULL; in test_cmp_calc_protection_pkey()
163 fixture->pubkey = prot_Ed_key; in test_cmp_calc_protection_pkey_Ed()
164 if (!TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, prot_Ed_key)) in test_cmp_calc_protection_pkey_Ed()
165 || !TEST_ptr(fixture->msg = load_pkimsg(genm_prot_Ed_f, libctx))) { in test_cmp_calc_protection_pkey_Ed()
166 tear_down(fixture); in test_cmp_calc_protection_pkey_Ed()
167 fixture = NULL; in test_cmp_calc_protection_pkey_Ed()
179 if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_cmp_calc_protection_pbmac()
181 || !TEST_ptr(fixture->msg = load_pkimsg(ip_PBM_f, libctx))) { in test_cmp_calc_protection_pbmac()
182 tear_down(fixture); in test_cmp_calc_protection_pbmac()
183 fixture = NULL; in test_cmp_calc_protection_pbmac()
188 static int execute_MSG_protect_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_MSG_protect_test() argument
190 return TEST_int_eq(fixture->expected, in execute_MSG_protect_test()
191 ossl_cmp_msg_protect(fixture->cmp_ctx, fixture->msg)); in execute_MSG_protect_test()
200 fixture->expected = 1; in test_MSG_protect_unprotected_request()
201 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_unprotected_request()
202 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 1))) { in test_MSG_protect_unprotected_request()
203 tear_down(fixture); in test_MSG_protect_unprotected_request()
204 fixture = NULL; in test_MSG_protect_unprotected_request()
215 fixture->expected = 1; in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
217 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
218 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
223 || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
225 || !TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
228 tear_down(fixture); in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
229 fixture = NULL; in test_MSG_protect_with_msg_sig_alg_protection_plus_rsa_key()
238 fixture->expected = 1; in test_MSG_protect_with_certificate_and_key()
240 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_with_certificate_and_key()
241 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0)) in test_MSG_protect_with_certificate_and_key()
242 || !TEST_true(OSSL_CMP_CTX_set1_pkey(fixture->cmp_ctx, server_key)) in test_MSG_protect_with_certificate_and_key()
243 || !TEST_true(OSSL_CMP_CTX_set1_cert(fixture->cmp_ctx, in test_MSG_protect_with_certificate_and_key()
245 tear_down(fixture); in test_MSG_protect_with_certificate_and_key()
246 fixture = NULL; in test_MSG_protect_with_certificate_and_key()
257 ctx = fixture->cmp_ctx; in test_MSG_protect_certificate_based_without_cert()
258 fixture->expected = 0; in test_MSG_protect_certificate_based_without_cert()
259 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_certificate_based_without_cert()
263 tear_down(fixture); in test_MSG_protect_certificate_based_without_cert()
264 fixture = NULL; in test_MSG_protect_certificate_based_without_cert()
273 fixture->expected = 0; in test_MSG_protect_no_key_no_secret()
274 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_no_key_no_secret()
275 || !TEST_true(SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0))) { in test_MSG_protect_no_key_no_secret()
276 tear_down(fixture); in test_MSG_protect_no_key_no_secret()
277 fixture = NULL; in test_MSG_protect_no_key_no_secret()
289 fixture->expected = with_ref; in test_MSG_protect_pbmac_no_sender()
290 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected)) in test_MSG_protect_pbmac_no_sender()
291 || !SET_OPT_UNPROTECTED_SEND(fixture->cmp_ctx, 0) in test_MSG_protect_pbmac_no_sender()
292 || !ossl_cmp_hdr_set1_sender(fixture->msg->header, NULL) in test_MSG_protect_pbmac_no_sender()
293 || !OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, in test_MSG_protect_pbmac_no_sender()
295 || (!OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, in test_MSG_protect_pbmac_no_sender()
298 tear_down(fixture); in test_MSG_protect_pbmac_no_sender()
299 fixture = NULL; in test_MSG_protect_pbmac_no_sender()
315 static int execute_MSG_add_extraCerts_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_MSG_add_extraCerts_test() argument
317 return TEST_true(ossl_cmp_msg_add_extraCerts(fixture->cmp_ctx, in execute_MSG_add_extraCerts_test()
318 fixture->msg)); in execute_MSG_add_extraCerts_test()
324 if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_protected))) { in test_MSG_add_extraCerts()
325 tear_down(fixture); in test_MSG_add_extraCerts()
326 fixture = NULL; in test_MSG_add_extraCerts()
334 static int execute_cmp_build_cert_chain_test(CMP_PROTECT_TEST_FIXTURE *fixture) in execute_cmp_build_cert_chain_test() argument
337 OSSL_CMP_CTX *ctx = fixture->cmp_ctx; in execute_cmp_build_cert_chain_test()
339 STACK_OF(X509) *chain = 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()
487 fixture->callback_arg = 0; /* self-issued allowed */ in test_X509_STORE()
488 if (!TEST_ptr(fixture->certs = sk_X509_new_null()) in test_X509_STORE()
489 || !sk_X509_push(fixture->certs, endentity1) in test_X509_STORE()
490 || !sk_X509_push(fixture->certs, endentity2) in test_X509_STORE()
491 || !sk_X509_push(fixture->certs, root) in test_X509_STORE()
492 || !sk_X509_push(fixture->certs, intermediate) in test_X509_STORE()
493 || !TEST_ptr(fixture->chain = sk_X509_dup(fixture->certs))) { in test_X509_STORE()
494 tear_down(fixture); in test_X509_STORE()
495 fixture = NULL; in test_X509_STORE()
504 fixture->certs = sk_X509_new_null(); in test_X509_STORE_only_self_issued()
505 fixture->chain = sk_X509_new_null(); in test_X509_STORE_only_self_issued()
506 fixture->callback_arg = 1; /* only self-issued */ in test_X509_STORE_only_self_issued()
507 if (!TEST_true(sk_X509_push(fixture->certs, endentity1)) in test_X509_STORE_only_self_issued()
508 || !TEST_true(sk_X509_push(fixture->certs, endentity2)) in test_X509_STORE_only_self_issued()
509 || !TEST_true(sk_X509_push(fixture->certs, root)) in test_X509_STORE_only_self_issued()
510 || !TEST_true(sk_X509_push(fixture->certs, intermediate)) in test_X509_STORE_only_self_issued()
511 || !TEST_true(sk_X509_push(fixture->chain, root))) { in test_X509_STORE_only_self_issued()
512 tear_down(fixture); in test_X509_STORE_only_self_issued()
513 fixture = NULL; in test_X509_STORE_only_self_issued()