[svn-commits] mmichelson: branch group/dns_naptr r433366 - in /team/group/dns_naptr: main/ ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 24 18:20:57 CDT 2015


Author: mmichelson
Date: Tue Mar 24 18:20:55 2015
New Revision: 433366

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433366
Log:
Add off-nominal interactive test and more records to nominal test.

The interactive test tests for NAPTR records that have individual valid
parts, but have errors when those parts are combined. This test currently
only has a single record, which contains both a valid regex and a valid
replacement domain.

I also added some more nominal records to the nominal test. This found
errors in my services validating functions.


Modified:
    team/group/dns_naptr/main/dns_naptr.c
    team/group/dns_naptr/tests/test_dns_naptr.c

Modified: team/group/dns_naptr/main/dns_naptr.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/main/dns_naptr.c?view=diff&rev=433366&r1=433365&r2=433366
==============================================================================
--- team/group/dns_naptr/main/dns_naptr.c (original)
+++ team/group/dns_naptr/main/dns_naptr.c Tue Mar 24 18:20:55 2015
@@ -127,11 +127,15 @@
 static int services_invalid(const char *services, uint8_t services_size)
 {
 	const char *current_pos = services;
-	uint8_t remaining_size = services_size;
+	const char *end_of_services = services + services_size;
+
+	if (services_size == 0) {
+		return 0;
+	}
 
 	while (1) {
-		char *plus_pos = memchr(current_pos, '+', remaining_size);
-		uint8_t current_size = plus_pos ? plus_pos - current_pos : remaining_size;
+		char *plus_pos = memchr(current_pos, '+', end_of_services - current_pos);
+		uint8_t current_size = plus_pos ? plus_pos - current_pos : end_of_services - current_pos;
 		int i;
 
 		if (!isalpha(current_pos[0])) {
@@ -148,11 +152,9 @@
 			}
 		}
 
-		remaining_size -= current_size;
-		if (!remaining_size) {
+		if (!plus_pos) {
 			break;
 		}
-
 		current_pos = plus_pos + 1;
 	}
 
@@ -498,6 +500,14 @@
 		return NULL;
 	}
 
+	/* replacement_size takes into account the NULL label, so a NAPTR record with no replacement
+	 * will have a replacement_size of 1.
+	 */
+	if (regexp_size && replacement_size > 1) {
+		ast_log(LOG_ERROR, "NAPTR record contained both a regexp and replacement\n");
+		return NULL;
+	}
+
 	naptr = ast_calloc(1, sizeof(*naptr) + size + flags_size + 1 + services_size + 1 + regexp_size + 1 + replacement_size + 1);
 	if (!naptr) {
 		return NULL;

Modified: team/group/dns_naptr/tests/test_dns_naptr.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/tests/test_dns_naptr.c?view=diff&rev=433366&r1=433365&r2=433366
==============================================================================
--- team/group/dns_naptr/tests/test_dns_naptr.c (original)
+++ team/group/dns_naptr/tests/test_dns_naptr.c Tue Mar 24 18:20:55 2015
@@ -245,13 +245,25 @@
 	RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free);
 	const struct ast_dns_record *record;
 	struct naptr_record records[] = {
-		{ 100, 100, {1, "A"}, {4, "BLAH"}, {0, ""}, "goose.down" },
-		{ 200, 200, {1, "A"}, {4, "BLAH"}, {0, ""}, "duck.down" },
-		{ 100, 200, {1, "A"}, {4, "BLAH"}, {18, "![^\\.]+\\.(.*)$!\\1!"}, "" },
-		{ 200, 100, {1, "A"}, {4, "BLAH"}, {29, "!([^\\.]+\\.)(.*)$!\\1.happy.\\2!"}, "" },
-	};
-
-	int naptr_record_order[] = { 0, 2, 3, 1 };
+		/* Incredibly plain record */
+		{ 200, 100, {1, "A"}, {4, "BLAH"}, {0, ""}, "goose.down" },
+		/* Records with valid but unusual flags */
+		{ 300,   8, {0, ""}, {4, "BLAH"}, {0, ""}, "goose.down" },
+		{ 300,   6, {1, "3"}, {4, "BLAH"}, {0, ""}, "goose.down" },
+		{ 100,   2, {2, "32"}, {4, "BLAH"}, {0, ""}, "goose.down" },
+		{ 400, 100, {3, "A32"}, {4, "BLAH"}, {0, ""}, "goose.down" },
+		/* Records with valid but unusual services */
+		{ 100, 700, {0, ""}, {0, ""}, {0, ""}, "goose.down" },
+		//{ 500, 100, {1, "A"}, {42, "A+B12+C+D+EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"}, {0, ""}, "goose.down" },
+		{ 500, 100, {1, "A"}, {14, "A+B12+C+D+EEEE"}, {0, ""}, "goose.down" },
+		/* Records with valid regexes (regexes are always unusual) */
+		{ 500, 101, {1, "A"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, "" },
+		{ 500,  99, {1, "A"}, {4, "BLAH"}, {15, "0.*0horse.mane0"}, "" },
+		{  10, 100, {1, "A"}, {4, "BLAH"}, {11, "!.*!\\!\\!\\!!"}, "" },
+		{ 700, 999, {1, "A"}, {4, "BLAH"}, {30, "!(.)(.)(.)(.)!\\1.m.\\2.n\\3.o\\4!"}, "" },
+	};
+
+	int naptr_record_order[] = { 9, 3, 5, 0, 2, 1, 4, 8, 6, 7, 10};
 	enum ast_test_result_state res = AST_TEST_PASS;
 	int i;
 
@@ -509,6 +521,32 @@
 	return off_nominal_test(test, records, ARRAY_LEN(records));
 }
 
+AST_TEST_DEFINE(naptr_resolve_off_nominal_interactions)
+{
+	struct naptr_record records[] = {
+		/* Both regexp and replacement are specified */
+		{ 100, 100, {1, "A"}, {4, "BLAH"}, {15, "!.*!horse.mane!"}, "goose.down"},
+		/* XXX RFC 2915 says that a service MUST be present if terminal flags are
+		 * specified. However, RFCs 3401-3404 do not specify this behavior, so
+		 * I am not putting in a test for it
+		 */
+	};
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "naptr_resolve_off_nominal_interactions";
+		info->category = "/main/dns/naptr/";
+		info->summary = "Ensure that NAPTR records with invalid interactions are not presented in results";
+		info->description = "This test defines a set of records where all parts are individually valid,\n"
+			"but when combined do not make sense and are thus invalid.\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	return off_nominal_test(test, records, ARRAY_LEN(records));
+}
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(naptr_resolve_nominal);
@@ -516,6 +554,7 @@
 	AST_TEST_UNREGISTER(naptr_resolve_off_nominal_flags);
 	AST_TEST_UNREGISTER(naptr_resolve_off_nominal_services);
 	AST_TEST_UNREGISTER(naptr_resolve_off_nominal_regexp);
+	AST_TEST_UNREGISTER(naptr_resolve_off_nominal_interactions);
 
 	return 0;
 }
@@ -527,6 +566,7 @@
 	AST_TEST_REGISTER(naptr_resolve_off_nominal_flags);
 	AST_TEST_REGISTER(naptr_resolve_off_nominal_services);
 	AST_TEST_REGISTER(naptr_resolve_off_nominal_regexp);
+	AST_TEST_REGISTER(naptr_resolve_off_nominal_interactions);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }




More information about the svn-commits mailing list