]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[test] Add tests for x509_check_name()
authorMichael Brown <mcb30@ipxe.org>
Mon, 31 Mar 2014 12:15:42 +0000 (13:15 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 31 Mar 2014 12:16:46 +0000 (13:16 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/tests/x509_test.c

index 6496ac7281b430f11796d0c9d80b52435adf8e68..17f5d94cc49d7d2e1db066561d0812d30f4ba0e6 100644 (file)
@@ -852,6 +852,40 @@ static void x509_check_time_fail_okx ( struct x509_test_certificate *crt,
 #define x509_check_time_fail_ok( crt, time ) \
        x509_check_time_fail_okx ( crt, time, __FILE__, __LINE__ )
 
+/**
+ * Report certificate name validation test result
+ *
+ * @v crt              Test certificate
+ * @v name             Test name
+ * @v file             Test code file
+ * @v line             Test code line
+ */
+static void x509_check_name_okx ( struct x509_test_certificate *crt,
+                                 const char *name, const char *file,
+                                 unsigned int line ) {
+
+       okx ( x509_check_name ( crt->cert, name ) == 0, file, line );
+}
+#define x509_check_name_ok( crt, name ) \
+       x509_check_name_okx ( crt, name, __FILE__, __LINE__ )
+
+/**
+ * Report certificate name validation failure test result
+ *
+ * @v crt              Test certificate
+ * @v name             Test name
+ * @v file             Test code file
+ * @v line             Test code line
+ */
+static void x509_check_name_fail_okx ( struct x509_test_certificate *crt,
+                                      const char *name, const char *file,
+                                      unsigned int line ) {
+
+       okx ( x509_check_name ( crt->cert, name ) != 0, file, line );
+}
+#define x509_check_name_fail_ok( crt, name ) \
+       x509_check_name_fail_okx ( crt, name, __FILE__, __LINE__ )
+
 /**
  * Report certificate chain parsing test result
  *
@@ -981,6 +1015,10 @@ static void x509_test_exec ( void ) {
        x509_check_time_ok ( &root_crt, test_expired );
        x509_check_time_fail_ok ( &root_crt, test_ca_expired );
 
+       /* Check certificate names */
+       x509_check_name_ok ( &server_crt, "boot.test.ipxe.org" );
+       x509_check_name_fail_ok ( &server_crt, "incorrect.test.ipxe.org" );
+
        /* Parse all certificate chains */
        x509_chain_ok ( &server_chain );
        x509_chain_ok ( &broken_server_chain );