Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add 4 new tests for parsing wrong manifest files
Baptiste Daroussin committed 15 years ago
commit 625c0f82b792fa58d32fa2292e94e6da1c66011b
parent c287fe0
2 files changed +98 -7
modified libpkg/pkg_manifest.c
@@ -52,6 +52,9 @@ m_parse_set_string(struct pkg *pkg, char *buf, pkg_attr attr) {
	while (isspace(*buf))
		buf++;

+
	if (*buf == '\0')
+
		return (EPKG_FATAL);
+

	pkg_set(pkg, attr, buf);

	return (EPKG_OK);
@@ -146,8 +149,8 @@ m_parse_dep(struct pkg *pkg, char *buf)

	buf_ptr = buf;

-
	if (split_chr(buf_ptr, ' ') > 2)
-
		return (-1);
+
	if (split_chr(buf_ptr, ' ') != 2)
+
		return (EPKG_FATAL);

	next = strlen(buf_ptr);
	name = buf_ptr;
@@ -164,7 +167,7 @@ m_parse_dep(struct pkg *pkg, char *buf)

	pkg_adddep(pkg, name, origin, version);

-
	return (0);
+
	return (EPKG_OK);
}

static int
@@ -175,7 +178,7 @@ m_parse_conflict(struct pkg *pkg, char *buf)

	pkg_addconflict(pkg, buf);

-
	return (0);
+
	return (EPKG_OK);
}

int
@@ -201,7 +204,8 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
	for (i = 1; i <= nbel; i++) {
		for (j = 0; j < manifest_key_len; j++) {
			if (STARTS_WITH(buf_ptr, manifest_key[j].key)) {
-
				manifest_key[j].parse(pkg, buf_ptr + strlen(manifest_key[j].key));
+
				if (manifest_key[j].parse(pkg, buf_ptr + strlen(manifest_key[j].key)) != EPKG_OK)
+
					return (EPKG_FATAL);
				break;
			}
		}
@@ -212,7 +216,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
		}
	}

-
	return (0);
+
	return (EPKG_OK);
}

int
@@ -249,7 +253,7 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)

	if ((deps = pkg_deps(pkg)) != NULL) {
		for (i = 0; deps[i] != NULL; i++) {
-
			sbuf_printf(manifest, "@dep %s %s %s\n", 
+
			sbuf_printf(manifest, "@dep %s %s %s\n",
					pkg_get(deps[i], PKG_NAME),
					pkg_get(deps[i], PKG_ORIGIN),
					pkg_get(deps[i], PKG_VERSION));
modified tests/manifest.c
@@ -23,6 +23,63 @@ char manifest[] = ""
	"@option foo true\n"
	"@option bar false\n";

+
char wrong_manifest1[] = ""
+
	"@pkg_format_version 0.9\n"
+
	"@name\n"
+
	"@version 0.3\n"
+
	"@origin foo/bar\n"
+
	"@comment A dummy manifest\n"
+
	"@arch amd64\n"
+
	"@osversion 800500\n"
+
	"@www http://www.foobar.com\n"
+
	"@maintainer test@pkgng.lan\n"
+
	"@dep depfoo dep/foo 1.2\n"
+
	"@dep depbar dep/bar 3.4\n"
+
	"@conflict foo-*\n"
+
	"@conflict bar-*\n"
+
	"@exec true && echo hello\n"
+
	"@exec false || echo world\n"
+
	"@option foo true\n"
+
	"@option bar false\n";
+

+
char wrong_manifest2[] = ""
+
	"@pkg_format_version 0.9\n"
+
	"@name foobar\n"
+
	"@version 0.3\n"
+
	"@origin foo/bar\n"
+
	"@comment A dummy manifest\n"
+
	"@arch amd64\n"
+
	"@osversion 800500\n"
+
	"@www http://www.foobar.com\n"
+
	"@maintainer test@pkgng.lan\n"
+
	"@dep depfoo\n"
+
	"@dep depbar dep/bar 3.4\n"
+
	"@conflict foo-*\n"
+
	"@conflict bar-*\n"
+
	"@exec true && echo hello\n"
+
	"@exec false || echo world\n"
+
	"@option foo true\n"
+
	"@option bar false\n";
+

+
char wrong_manifest3[] = ""
+
	"@pkg_format_version 0.9\n"
+
	"@name foobar\n"
+
	"@version 0.3\n"
+
	"@origin foo/bar\n"
+
	"@comment A dummy manifest\n"
+
	"@arch amd64\n"
+
	"@osversion 800500\n"
+
	"@www http://www.foobar.com\n"
+
	"@maintainer test@pkgng.lan\n"
+
	"@dep depfoo\n"
+
	"@dep depbar dep/bar 3.4\n"
+
	"@conflict foo-*\n"
+
	"@conflict \n"
+
	"@exec true && echo hello\n"
+
	"@exec false || echo world\n"
+
	"@option foo true\n"
+
	"@option bar false\n";
+

START_TEST(parse_manifest)
{
	struct pkg *p;
@@ -89,11 +146,41 @@ START_TEST(parse_manifest)
}
END_TEST

+
START_TEST(parse_wrong_manifest1)
+
{
+
	struct pkg *p;
+

+
	fail_unless(pkg_new(&p) == EPKG_OK);
+
	fail_unless(pkg_parse_manifest(p, wrong_manifest1) == EPKG_FATAL);
+

+
}
+
END_TEST
+

+
START_TEST(parse_wrong_manifest2)
+
{
+
	struct pkg *p;
+

+
	fail_unless(pkg_new(&p) == EPKG_OK);
+
	fail_unless(pkg_parse_manifest(p, wrong_manifest2) == EPKG_FATAL);
+
}
+
END_TEST
+

+
START_TEST(parse_wrong_manifest3)
+
{
+
	struct pkg *p;
+
	fail_unless(pkg_new(&p) == EPKG_OK);
+
	fail_unless(pkg_parse_manifest(p, wrong_manifest3) == EPKG_FATAL);
+
}
+
END_TEST
+

TCase *
tcase_manifest(void)
{
	TCase *tc = tcase_create("Manifest");
	tcase_add_test(tc, parse_manifest);
+
	tcase_add_test(tc, parse_wrong_manifest1);
+
	tcase_add_test(tc, parse_wrong_manifest2);
+
	tcase_add_test(tc, parse_wrong_manifest3);

	return (tc);
}