summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamenim@samba.org>2010-10-20 13:46:34 +0300
committerKamen Mazdrashki <kamenim@samba.org>2010-10-22 01:48:58 +0300
commit14cb61da8fe4fb24c3e066e5731d0be00ddb893b (patch)
treeffa20011787d344bddaf50a8cc0e884917d48cec /lib/util
parent6b63ad6ff1bfcb7fcfb3e0f3cd4636ff222ab88f (diff)
downloadsamba-14cb61da8fe4fb24c3e066e5731d0be00ddb893b.tar.gz
samba-14cb61da8fe4fb24c3e066e5731d0be00ddb893b.tar.bz2
samba-14cb61da8fe4fb24c3e066e5731d0be00ddb893b.zip
asn1_tests: Implement negative unit-tests for ber_write_OID_String()
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/tests/asn1_tests.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c
index b11e9d5dcf..97f7756590 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;