lib/core: Add ostree_validate_remote_name() for remote names

There are a few places in the code where ad-hoc validation was being
performed. Might as well formalise it a bit more.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #948
Approved by: cgwalters
This commit is contained in:
Philip Withnall authored and Atomic Bot committed 2017-06-20 21:52:22 +00:00
1 parent fd50c97322
commit 20dc9454b3
6 files changed
+62 -6

No files matched your search

+20
View File
@@ -185,6 +185,25 @@ static gboolean hi_content_stream_new (GInputStream **out_stream,
return ostree_raw_file_to_content_stream ((GInputStream*)hi_memstream, finfo, NULL, out_stream, out_length, NULL, error);
}
static void
test_validate_remotename (void)
{
const char *valid[] = {"foo", "hello-world"};
const char *invalid[] = {"foo/bar", ""};
for (guint i = 0; i < G_N_ELEMENTS(valid); i++)
{
g_autoptr(GError) error = NULL;
g_assert (ostree_validate_remote_name (valid[i], &error));
g_assert_no_error (error);
}
for (guint i = 0; i < G_N_ELEMENTS(invalid); i++)
{
g_autoptr(GError) error = NULL;
g_assert (!ostree_validate_remote_name (invalid[i], &error));
g_assert (error != NULL);
}
}
static void
test_object_writes (gconstpointer data)
{
@@ -232,6 +251,7 @@ int main (int argc, char **argv)
g_test_add_data_func ("/repo-not-system", repo, test_repo_is_not_system);
g_test_add_data_func ("/raw-file-to-archive-z2-stream", repo, test_raw_file_to_archive_z2_stream);
g_test_add_data_func ("/objectwrites", repo, test_object_writes);
g_test_add_func ("/remotename", test_validate_remotename);
return g_test_run();
out: