tests/tls-certificate: Change to g_assert_null/nonnull

Use g_assert_null/g_assert_nonnull instead of g_assert since
g_assert can be compiled out with G_DISABLE_ASSERT.
This commit is contained in:
Fredrik Ternerot 2018-12-18 10:39:01 +01:00
parent c46565d56a
commit c7ee522172

View File

@ -44,12 +44,12 @@ pem_parser (const Reference *ref)
/* Check PEM parsing in certificate, private key order. */ /* Check PEM parsing in certificate, private key order. */
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert-key.pem", NULL), &pem, &pem_len, &error); g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert-key.pem", NULL), &pem, &pem_len, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (pem); g_assert_nonnull (pem);
g_assert_cmpuint (pem_len, >=, 10); g_assert_cmpuint (pem_len, >=, 10);
cert = g_tls_certificate_new_from_pem (pem, -1, &error); cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -79,11 +79,11 @@ pem_parser (const Reference *ref)
/* Check PEM parsing in private key, certificate order */ /* Check PEM parsing in private key, certificate order */
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "key-cert.pem", NULL), &pem, NULL, &error); g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "key-cert.pem", NULL), &pem, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (pem); g_assert_nonnull (pem);
cert = g_tls_certificate_new_from_pem (pem, -1, &error); cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -101,11 +101,11 @@ pem_parser (const Reference *ref)
/* Check certificate only PEM */ /* Check certificate only PEM */
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert1.pem", NULL), &pem, NULL, &error); g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert1.pem", NULL), &pem, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (pem); g_assert_nonnull (pem);
cert = g_tls_certificate_new_from_pem (pem, -1, &error); cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -114,7 +114,7 @@ pem_parser (const Reference *ref)
g_assert_cmpstr (parsed_cert_pem, ==, ref->cert_pems[0]); g_assert_cmpstr (parsed_cert_pem, ==, ref->cert_pems[0]);
g_free (parsed_cert_pem); g_free (parsed_cert_pem);
parsed_cert_pem = NULL; parsed_cert_pem = NULL;
g_assert (parsed_key_pem == NULL); g_assert_null (parsed_key_pem);
g_free (pem); g_free (pem);
g_object_unref (cert); g_object_unref (cert);
@ -122,12 +122,12 @@ pem_parser (const Reference *ref)
/* Check error with private key only PEM */ /* Check error with private key only PEM */
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL), &pem, NULL, &error); g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL), &pem, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (pem); g_assert_nonnull (pem);
cert = g_tls_certificate_new_from_pem (pem, -1, &error); cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE); g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error); g_clear_error (&error);
g_assert (cert == NULL); g_assert_null (cert);
g_free (pem); g_free (pem);
} }
@ -145,12 +145,12 @@ pem_parser_handles_chain (const Reference *ref)
/* Check that a chain with exactly three certificates is returned */ /* Check that a chain with exactly three certificates is returned */
g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert-list.pem", NULL), &pem, NULL, &error); g_file_get_contents (g_test_get_filename (G_TEST_DIST, "cert-tests", "cert-list.pem", NULL), &pem, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (pem); g_assert_nonnull (pem);
cert = original_cert = g_tls_certificate_new_from_pem (pem, -1, &error); cert = original_cert = g_tls_certificate_new_from_pem (pem, -1, &error);
g_free (pem); g_free (pem);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -165,11 +165,11 @@ pem_parser_handles_chain (const Reference *ref)
/* Now test the second cert */ /* Now test the second cert */
issuer = g_tls_certificate_get_issuer (cert); issuer = g_tls_certificate_get_issuer (cert);
g_assert (issuer); g_assert_nonnull (issuer);
cert = issuer; cert = issuer;
issuer = g_tls_certificate_get_issuer (cert); issuer = g_tls_certificate_get_issuer (cert);
g_assert (issuer); g_assert_nonnull (issuer);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -179,12 +179,12 @@ pem_parser_handles_chain (const Reference *ref)
/* Only the first cert should have a private key */ /* Only the first cert should have a private key */
parsed_key_pem = g_test_tls_connection_get_private_key_pem (cert); parsed_key_pem = g_test_tls_connection_get_private_key_pem (cert);
g_assert (!parsed_key_pem); g_assert_null (parsed_key_pem);
/* Now test the final cert */ /* Now test the final cert */
cert = issuer; cert = issuer;
issuer = g_tls_certificate_get_issuer (cert); issuer = g_tls_certificate_get_issuer (cert);
g_assert (!issuer); g_assert_null (issuer);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -193,7 +193,7 @@ pem_parser_handles_chain (const Reference *ref)
g_clear_pointer (&parsed_cert_pem, g_free); g_clear_pointer (&parsed_cert_pem, g_free);
parsed_key_pem = g_test_tls_connection_get_private_key_pem (cert); parsed_key_pem = g_test_tls_connection_get_private_key_pem (cert);
g_assert (!parsed_key_pem); g_assert_null (parsed_key_pem);
g_object_unref (original_cert); g_object_unref (original_cert);
} }
@ -209,7 +209,7 @@ from_file (const Reference *ref)
cert = g_tls_certificate_new_from_file (g_test_get_filename (G_TEST_DIST, "cert-tests", "key-cert.pem", NULL), cert = g_tls_certificate_new_from_file (g_test_get_filename (G_TEST_DIST, "cert-tests", "key-cert.pem", NULL),
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -236,7 +236,7 @@ from_files (const Reference *ref)
g_test_get_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL), g_test_get_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL),
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -256,7 +256,7 @@ from_files (const Reference *ref)
&error); &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE); g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error); g_clear_error (&error);
g_assert (cert == NULL); g_assert_null (cert);
/* Missing certificate */ /* Missing certificate */
cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL), cert = g_tls_certificate_new_from_files (g_test_get_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL),
@ -264,7 +264,7 @@ from_files (const Reference *ref)
&error); &error);
g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE); g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE);
g_clear_error (&error); g_clear_error (&error);
g_assert (cert == NULL); g_assert_null (cert);
/* Using this method twice with a file containing both private key and /* Using this method twice with a file containing both private key and
* certificate as a way to inforce private key presence is a fair use * certificate as a way to inforce private key presence is a fair use
@ -273,7 +273,7 @@ from_files (const Reference *ref)
g_test_get_filename (G_TEST_DIST, "cert-tests", "key-cert.pem", NULL), g_test_get_filename (G_TEST_DIST, "cert-tests", "key-cert.pem", NULL),
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_unref (cert); g_object_unref (cert);
} }
@ -290,7 +290,7 @@ from_files_pkcs8 (const Reference *ref)
g_test_get_filename (G_TEST_DIST, "cert-tests", "key8.pem", NULL), g_test_get_filename (G_TEST_DIST, "cert-tests", "key8.pem", NULL),
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (cert); g_assert_nonnull (cert);
g_object_get (cert, g_object_get (cert,
"certificate-pem", &parsed_cert_pem, "certificate-pem", &parsed_cert_pem,
@ -356,27 +356,27 @@ main (int argc,
path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert1.pem", NULL); path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert1.pem", NULL);
g_file_get_contents (path, &ref.cert_pems[0], NULL, &error); g_file_get_contents (path, &ref.cert_pems[0], NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ref.cert_pems[0]); g_assert_nonnull (ref.cert_pems[0]);
g_free (path); g_free (path);
path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert2.pem", NULL); path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert2.pem", NULL);
g_file_get_contents (path, &ref.cert_pems[1], NULL, &error); g_file_get_contents (path, &ref.cert_pems[1], NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ref.cert_pems[1]); g_assert_nonnull (ref.cert_pems[1]);
g_free (path); g_free (path);
path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert3.pem", NULL); path = g_test_build_filename (G_TEST_DIST, "cert-tests", "cert3.pem", NULL);
g_file_get_contents (path, &ref.cert_pems[2], NULL, &error); g_file_get_contents (path, &ref.cert_pems[2], NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ref.cert_pems[2]); g_assert_nonnull (ref.cert_pems[2]);
g_free (path); g_free (path);
path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL); path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key.pem", NULL);
g_file_get_contents (path, &ref.key_pem, NULL, &error); g_file_get_contents (path, &ref.key_pem, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ref.key_pem); g_assert_nonnull (ref.key_pem);
g_free (path); g_free (path);
path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key8.pem", NULL); path = g_test_build_filename (G_TEST_DIST, "cert-tests", "key8.pem", NULL);
g_file_get_contents (path, &ref.key8_pem, NULL, &error); g_file_get_contents (path, &ref.key8_pem, NULL, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ref.key8_pem); g_assert_nonnull (ref.key8_pem);
g_free (path); g_free (path);
g_test_add_data_func ("/tls-certificate/pem-parser", g_test_add_data_func ("/tls-certificate/pem-parser",