Skip to content

Commit 3c0a14d

Browse files
committed
Add more control tests
1 parent 2222ff7 commit 3c0a14d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/syntax.c

+88
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,91 @@ void been_there_done_that(void **state)
665665
free(include);
666666
assert_int_equal(code, ZONE_SYNTAX_ERROR);
667667
}
668+
669+
/*!cmocka */
670+
void bad_a_rrs(void **state)
671+
{
672+
(void)state;
673+
674+
int32_t code;
675+
size_t count = 0;
676+
static const char *no_a = PAD("foo. A ; no-address");
677+
static const char *double_a = PAD("foo. A 192.168.0.1 192.168.0.2");
678+
static const char *bad_a = PAD("foo. A 192.168.0.256");
679+
680+
code = parse(no_a, &count);
681+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
682+
code = parse(double_a, &count);
683+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
684+
code = parse(bad_a, &count);
685+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
686+
}
687+
688+
/*!cmocka */
689+
void bad_ttls(void **state)
690+
{
691+
(void)state;
692+
693+
int32_t code;
694+
size_t count = 0;
695+
696+
static const char *too_little = PAD("$TTL ; no time");
697+
static const char *too_late = PAD("$TTL 2147483648"); // one second too much
698+
static const char *too_much = PAD("$TTL 1 2"); // trailing data
699+
700+
code = parse(too_little, &count);
701+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
702+
code = parse(too_late, &count);
703+
assert_int_equal(code, ZONE_SEMANTIC_ERROR);
704+
code = parse(too_much, &count);
705+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
706+
}
707+
708+
/*!cmocka */
709+
void bad_origins(void **state)
710+
{
711+
(void)state;
712+
713+
int32_t code;
714+
size_t count = 0;
715+
716+
static const char *no_origin = PAD("$ORIGIN ; no origin");
717+
static const char *extra_origin = PAD("$ORIGIN a. b.");
718+
719+
code = parse(no_origin, &count);
720+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
721+
code = parse(extra_origin, &count);
722+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
723+
}
724+
725+
/*!cmocka */
726+
void bad_includes(void **state)
727+
{
728+
(void)state;
729+
730+
int32_t code;
731+
size_t count = 0;
732+
733+
static const char *no_include = PAD("$INCLUDE ; no include");
734+
735+
code = parse(no_include, &count);
736+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
737+
738+
char *path = generate_include(" ");
739+
assert_non_null(path);
740+
FILE* handle = fopen(path, "wb");
741+
assert_non_null(handle);
742+
char dummy[32];
743+
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\" foo. bar\n", path);
744+
assert_true(length > 0 && length < INT_MAX - ZONE_PADDING_SIZE);
745+
char *include = malloc((size_t)length + 1 + ZONE_PADDING_SIZE);
746+
assert_non_null(include);
747+
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\" foo. bar.\n", path);
748+
int result = fputs(include, handle);
749+
assert_true(result >= 0);
750+
(void)fclose(handle);
751+
free(path);
752+
code = parse(include, &count);
753+
free(include);
754+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
755+
}

0 commit comments

Comments
 (0)