From 14cb61da8fe4fb24c3e066e5731d0be00ddb893b Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Wed, 20 Oct 2010 13:46:34 +0300 Subject: [PATCH] asn1_tests: Implement negative unit-tests for ber_write_OID_String() --- lib/util/tests/asn1_tests.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c index b11e9d5dcf2..97f77565901 100644 --- a/lib/util/tests/asn1_tests.c +++ b/lib/util/tests/asn1_tests.c @@ -64,6 +64,17 @@ static const struct oid_data oid_data_ok[] = { }, }; +/* Data for successful OIDs conversions */ +static const char *oid_data_err[] = { + "", /* empty OID */ + ".2.5.4.130", /* first sub-identifier is empty */ + "2.5.4.130.", /* last sub-identifier is empty */ + "2..5.4.130", /* second sub-identifier is empty */ + "2.5..4.130", /* third sub-identifier is empty */ + "2.abc.4.130", /* invalid sub-identifier */ + "2.5abc.4.130", /* invalid sub-identifier (alpha-numeric)*/ +}; + /* Data for successful Partial OIDs conversions */ static const struct oid_data partial_oid_data_ok[] = { { @@ -104,6 +115,7 @@ static bool test_ber_write_OID_String(struct torture_context *tctx) mem_ctx = talloc_new(tctx); + /* check for valid OIDs */ for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) { torture_assert(tctx, ber_write_OID_String(mem_ctx, &blob, data[i].oid), "ber_write_OID_String failed"); @@ -117,6 +129,16 @@ static bool test_ber_write_OID_String(struct torture_context *tctx) data[i].oid, data[i].bin_oid)); } + /* check for invalid OIDs */ + for (i = 0; i < ARRAY_SIZE(oid_data_err); i++) { + torture_assert(tctx, + !ber_write_OID_String(mem_ctx, &blob, oid_data_err[i]), + talloc_asprintf(mem_ctx, + "Should fail for [%s] -> %s", + oid_data_err[i], + hex_encode_talloc(mem_ctx, blob.data, blob.length))); + } + talloc_free(mem_ctx); return true;