From 7338dcae8a73e0cd7be9ad6266ccd50fe65fa40c Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 24 Jun 2014 15:22:33 +0200 Subject: [PATCH] some negative tests of parse_name() --- tool/tests/parse_name.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tool/tests/parse_name.c b/tool/tests/parse_name.c index ab80bfc..a3fe30d 100644 --- a/tool/tests/parse_name.c +++ b/tool/tests/parse_name.c @@ -27,6 +27,7 @@ */ #include +#include #ifdef _WIN32 #include @@ -36,11 +37,21 @@ #include "util.h" -static void test_name(const char *name, const char *expected) { +static void test_name(const char *name, const char *expected, bool fail) { char buf[1024]; - X509_NAME *parsed = parse_name(name); - BIO *bio = BIO_new(BIO_s_mem()); + BIO *bio; const char none[] = {0}; + X509_NAME *parsed = parse_name(name); + if(parsed == NULL) { + if(fail) { + return; + } else { + printf("Failed parsing of '%s'!\n", name); + exit(EXIT_FAILURE); + } + } + + bio = BIO_new(BIO_s_mem()); X509_NAME_print_ex(bio, parsed, 0, XN_FLAG_ONELINE); BIO_write(bio, none, 1); @@ -54,7 +65,11 @@ static void test_name(const char *name, const char *expected) { } int main(void) { - test_name("/CN=test foo/", "CN = test foo"); - test_name("/CN=test/OU=bar/O=EXAMPLE/", "CN = test, OU = bar, O = EXAMPLE"); + test_name("/CN=test foo/", "CN = test foo", false); + test_name("/CN=test/OU=bar/O=EXAMPLE/", "CN = test, OU = bar, O = EXAMPLE", false); + test_name("/foo/", "", true); + test_name("/CN=test/foobar/", "", true); + test_name("/CN=test/foo=bar/", "", true); + return EXIT_SUCCESS; }