Browse Source

[test] Add tests for x509_check_name()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
357f23da9a
1 changed files with 38 additions and 0 deletions
  1. 38
    0
      src/tests/x509_test.c

+ 38
- 0
src/tests/x509_test.c View File

@@ -852,6 +852,40 @@ static void x509_check_time_fail_okx ( struct x509_test_certificate *crt,
852 852
 #define x509_check_time_fail_ok( crt, time ) \
853 853
 	x509_check_time_fail_okx ( crt, time, __FILE__, __LINE__ )
854 854
 
855
+/**
856
+ * Report certificate name validation test result
857
+ *
858
+ * @v crt		Test certificate
859
+ * @v name		Test name
860
+ * @v file		Test code file
861
+ * @v line		Test code line
862
+ */
863
+static void x509_check_name_okx ( struct x509_test_certificate *crt,
864
+				  const char *name, const char *file,
865
+				  unsigned int line ) {
866
+
867
+	okx ( x509_check_name ( crt->cert, name ) == 0, file, line );
868
+}
869
+#define x509_check_name_ok( crt, name ) \
870
+	x509_check_name_okx ( crt, name, __FILE__, __LINE__ )
871
+
872
+/**
873
+ * Report certificate name validation failure test result
874
+ *
875
+ * @v crt		Test certificate
876
+ * @v name		Test name
877
+ * @v file		Test code file
878
+ * @v line		Test code line
879
+ */
880
+static void x509_check_name_fail_okx ( struct x509_test_certificate *crt,
881
+				       const char *name, const char *file,
882
+				       unsigned int line ) {
883
+
884
+	okx ( x509_check_name ( crt->cert, name ) != 0, file, line );
885
+}
886
+#define x509_check_name_fail_ok( crt, name ) \
887
+	x509_check_name_fail_okx ( crt, name, __FILE__, __LINE__ )
888
+
855 889
 /**
856 890
  * Report certificate chain parsing test result
857 891
  *
@@ -981,6 +1015,10 @@ static void x509_test_exec ( void ) {
981 1015
 	x509_check_time_ok ( &root_crt, test_expired );
982 1016
 	x509_check_time_fail_ok ( &root_crt, test_ca_expired );
983 1017
 
1018
+	/* Check certificate names */
1019
+	x509_check_name_ok ( &server_crt, "boot.test.ipxe.org" );
1020
+	x509_check_name_fail_ok ( &server_crt, "incorrect.test.ipxe.org" );
1021
+
984 1022
 	/* Parse all certificate chains */
985 1023
 	x509_chain_ok ( &server_chain );
986 1024
 	x509_chain_ok ( &broken_server_chain );

Loading…
Cancel
Save