mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-24 17:32:09 +00:00
Add some coverage tests for FwupdRemote
This commit is contained in:
parent
358b1e0229
commit
6243e9f62a
@ -24,6 +24,10 @@ fwupd_remote_set_priority(FwupdRemote *self, gint priority);
|
||||
void
|
||||
fwupd_remote_set_agreement(FwupdRemote *self, const gchar *agreement);
|
||||
void
|
||||
fwupd_remote_set_checksum(FwupdRemote *self, const gchar *checksum);
|
||||
void
|
||||
fwupd_remote_set_filename_cache(FwupdRemote *self, const gchar *filename);
|
||||
void
|
||||
fwupd_remote_set_mtime(FwupdRemote *self, guint64 mtime);
|
||||
gchar **
|
||||
fwupd_remote_get_order_after(FwupdRemote *self);
|
||||
|
@ -188,7 +188,16 @@ fwupd_remote_set_agreement(FwupdRemote *self, const gchar *agreement)
|
||||
priv->agreement = g_strdup(agreement);
|
||||
}
|
||||
|
||||
static void
|
||||
/**
|
||||
* fwupd_remote_set_checksum:
|
||||
* @self: a #FwupdRemote
|
||||
* @checksum: (nullable): checksum string
|
||||
*
|
||||
* Sets the remote checksum, typically only useful in the self tests.
|
||||
*
|
||||
* Since: 1.8.2
|
||||
**/
|
||||
void
|
||||
fwupd_remote_set_checksum(FwupdRemote *self, const gchar *checksum)
|
||||
{
|
||||
FwupdRemotePrivate *priv = GET_PRIVATE(self);
|
||||
@ -462,7 +471,16 @@ fwupd_remote_kind_to_string(FwupdRemoteKind kind)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
/**
|
||||
* fwupd_remote_set_filename_cache:
|
||||
* @self: a #FwupdRemote
|
||||
* @filename: (nullable): filename string
|
||||
*
|
||||
* Sets the remote filename cache filename, typically only useful in the self tests.
|
||||
*
|
||||
* Since: 1.8.2
|
||||
**/
|
||||
void
|
||||
fwupd_remote_set_filename_cache(FwupdRemote *self, const gchar *filename)
|
||||
{
|
||||
FwupdRemotePrivate *priv = GET_PRIVATE(self);
|
||||
|
@ -242,6 +242,8 @@ fwupd_remote_baseuri_func(void)
|
||||
g_assert_cmpint(fwupd_remote_get_keyring_kind(remote), ==, FWUPD_KEYRING_KIND_JCAT);
|
||||
g_assert_cmpint(fwupd_remote_get_priority(remote), ==, 0);
|
||||
g_assert_true(fwupd_remote_get_enabled(remote));
|
||||
g_assert_cmpstr(fwupd_remote_get_firmware_base_uri(remote), ==, "https://my.fancy.cdn/");
|
||||
g_assert_cmpstr(fwupd_remote_get_agreement(remote), ==, NULL);
|
||||
g_assert_cmpstr(fwupd_remote_get_checksum(remote), ==, NULL);
|
||||
g_assert_cmpstr(fwupd_remote_get_metadata_uri(remote),
|
||||
==,
|
||||
@ -255,6 +257,136 @@ fwupd_remote_baseuri_func(void)
|
||||
g_assert_cmpstr(firmware_uri, ==, "https://my.fancy.cdn/firmware.cab");
|
||||
}
|
||||
|
||||
static gchar *
|
||||
fwupd_remote_to_json_string(FwupdRemote *remote, GError **error)
|
||||
{
|
||||
g_autofree gchar *data = NULL;
|
||||
g_autoptr(JsonGenerator) json_generator = NULL;
|
||||
g_autoptr(JsonBuilder) builder = json_builder_new();
|
||||
g_autoptr(JsonNode) json_root = NULL;
|
||||
json_builder_begin_object(builder);
|
||||
fwupd_remote_to_json(remote, builder);
|
||||
json_builder_end_object(builder);
|
||||
json_root = json_builder_get_root(builder);
|
||||
json_generator = json_generator_new();
|
||||
json_generator_set_pretty(json_generator, TRUE);
|
||||
json_generator_set_root(json_generator, json_root);
|
||||
data = json_generator_to_data(json_generator, NULL);
|
||||
if (data == NULL) {
|
||||
g_set_error(error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_INTERNAL,
|
||||
"Failed to convert remote to json.");
|
||||
return NULL;
|
||||
}
|
||||
return g_steal_pointer(&data);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_remote_auth_func(void)
|
||||
{
|
||||
gboolean ret;
|
||||
gchar **order;
|
||||
g_autofree gchar *fn = NULL;
|
||||
g_autofree gchar *remotes_dir = NULL;
|
||||
g_autofree gchar *json = NULL;
|
||||
g_autoptr(FwupdRemote) remote = fwupd_remote_new();
|
||||
g_autoptr(FwupdRemote) remote2 = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) data = NULL;
|
||||
|
||||
remotes_dir = g_test_build_filename(G_TEST_BUILT, "tests", NULL);
|
||||
fwupd_remote_set_remotes_dir(remote, remotes_dir);
|
||||
|
||||
fn = g_test_build_filename(G_TEST_DIST, "tests", "auth.conf", NULL);
|
||||
ret = fwupd_remote_load_from_filename(remote, fn, NULL, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
g_assert_cmpstr(fwupd_remote_get_username(remote), ==, "user");
|
||||
g_assert_cmpstr(fwupd_remote_get_password(remote), ==, "pass");
|
||||
g_assert_cmpstr(fwupd_remote_get_security_report_uri(remote),
|
||||
==,
|
||||
"https://fwupd.org/lvfs/hsireports/upload");
|
||||
g_assert_false(fwupd_remote_get_approval_required(remote));
|
||||
g_assert_false(fwupd_remote_get_automatic_reports(remote));
|
||||
g_assert_true(fwupd_remote_get_automatic_security_reports(remote));
|
||||
|
||||
g_assert_true(
|
||||
g_str_has_suffix(fwupd_remote_get_filename_source(remote), "tests/auth.conf"));
|
||||
g_assert_true(g_str_has_suffix(fwupd_remote_get_remotes_dir(remote), "/libfwupd/tests"));
|
||||
g_assert_cmpint(fwupd_remote_get_age(remote), >, 1000000);
|
||||
|
||||
ret = fwupd_remote_setup(remote, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
order = fwupd_remote_get_order_before(remote);
|
||||
g_assert_nonnull(order);
|
||||
g_assert_cmpint(g_strv_length(order), ==, 1);
|
||||
g_assert_cmpstr(order[0], ==, "before");
|
||||
order = fwupd_remote_get_order_after(remote);
|
||||
g_assert_nonnull(order);
|
||||
g_assert_cmpint(g_strv_length(order), ==, 1);
|
||||
g_assert_cmpstr(order[0], ==, "after");
|
||||
|
||||
/* to/from GVariant */
|
||||
fwupd_remote_set_priority(remote, 999);
|
||||
data = fwupd_remote_to_variant(remote);
|
||||
remote2 = fwupd_remote_from_variant(data);
|
||||
g_assert_cmpstr(fwupd_remote_get_username(remote2), ==, "user");
|
||||
g_assert_cmpint(fwupd_remote_get_priority(remote2), ==, 999);
|
||||
|
||||
/* jcat-tool is not a hard dep, and the tests create an empty file if unfound */
|
||||
ret = fwupd_remote_load_signature(remote,
|
||||
fwupd_remote_get_filename_cache_sig(remote),
|
||||
&error);
|
||||
if (!ret) {
|
||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT)) {
|
||||
g_test_skip("no jcat-tool, so skipping test");
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
|
||||
/* to JSON */
|
||||
fwupd_remote_set_filename_source(remote2, NULL);
|
||||
fwupd_remote_set_checksum(
|
||||
remote2,
|
||||
"dd1b4fd2a59bb0e4d9ea760c658ac3cf9336c7b6729357bab443485b5cf071b2");
|
||||
fwupd_remote_set_filename_cache(remote2, "./libfwupd/tests/auth/metadata.xml.gz");
|
||||
json = fwupd_remote_to_json_string(remote2, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_nonnull(json);
|
||||
ret = fu_test_compare_lines(
|
||||
json,
|
||||
"{\n"
|
||||
" \"Id\" : \"auth\",\n"
|
||||
" \"Kind\" : \"download\",\n"
|
||||
" \"KeyringKind\" : \"jcat\",\n"
|
||||
" \"FirmwareBaseUri\" : \"https://my.fancy.cdn/\",\n"
|
||||
" \"ReportUri\" : \"https://fwupd.org/lvfs/firmware/report\",\n"
|
||||
" \"SecurityReportUri\" : \"https://fwupd.org/lvfs/hsireports/upload\",\n"
|
||||
" \"MetadataUri\" : \"https://cdn.fwupd.org/downloads/firmware.xml.gz\",\n"
|
||||
" \"MetadataUriSig\" : \"https://cdn.fwupd.org/downloads/firmware.xml.gz.jcat\",\n"
|
||||
" \"Username\" : \"user\",\n"
|
||||
" \"Password\" : \"pass\",\n"
|
||||
" \"Checksum\" : "
|
||||
"\"dd1b4fd2a59bb0e4d9ea760c658ac3cf9336c7b6729357bab443485b5cf071b2\",\n"
|
||||
" \"FilenameCache\" : \"./libfwupd/tests/auth/metadata.xml.gz\",\n"
|
||||
" \"FilenameCacheSig\" : \"./libfwupd/tests/auth/metadata.xml.gz.jcat\",\n"
|
||||
" \"Enabled\" : \"true\",\n"
|
||||
" \"ApprovalRequired\" : \"false\",\n"
|
||||
" \"AutomaticReports\" : \"false\",\n"
|
||||
" \"AutomaticSecurityReports\" : \"true\",\n"
|
||||
" \"Priority\" : 999,\n"
|
||||
" \"Mtime\" : 0\n"
|
||||
"}",
|
||||
&error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_remote_duplicate_func(void)
|
||||
{
|
||||
@ -328,8 +460,11 @@ fwupd_remote_local_func(void)
|
||||
{
|
||||
gboolean ret;
|
||||
g_autofree gchar *fn = NULL;
|
||||
g_autofree gchar *json = NULL;
|
||||
g_autoptr(FwupdRemote) remote = NULL;
|
||||
g_autoptr(FwupdRemote) remote2 = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GVariant) data = NULL;
|
||||
|
||||
remote = fwupd_remote_new();
|
||||
fn = g_test_build_filename(G_TEST_DIST, "tests", "dell-esrt.conf", NULL);
|
||||
@ -350,6 +485,35 @@ fwupd_remote_local_func(void)
|
||||
"@datadir@/fwupd/remotes.d/dell-esrt/metadata.xml");
|
||||
g_assert_cmpstr(fwupd_remote_get_filename_cache_sig(remote), ==, NULL);
|
||||
g_assert_cmpstr(fwupd_remote_get_checksum(remote), ==, NULL);
|
||||
|
||||
/* to/from GVariant */
|
||||
data = fwupd_remote_to_variant(remote);
|
||||
remote2 = fwupd_remote_from_variant(data);
|
||||
g_assert_null(fwupd_remote_get_metadata_uri(remote));
|
||||
|
||||
/* to JSON */
|
||||
fwupd_remote_set_filename_source(remote2, NULL);
|
||||
json = fwupd_remote_to_json_string(remote2, &error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_nonnull(json);
|
||||
ret = fu_test_compare_lines(
|
||||
json,
|
||||
"{\n"
|
||||
" \"Id\" : \"dell-esrt\",\n"
|
||||
" \"Kind\" : \"local\",\n"
|
||||
" \"KeyringKind\" : \"none\",\n"
|
||||
" \"Title\" : \"Enable UEFI capsule updates on Dell systems\",\n"
|
||||
" \"FilenameCache\" : \"@datadir@/fwupd/remotes.d/dell-esrt/metadata.xml\",\n"
|
||||
" \"Enabled\" : \"true\",\n"
|
||||
" \"ApprovalRequired\" : \"false\",\n"
|
||||
" \"AutomaticReports\" : \"false\",\n"
|
||||
" \"AutomaticSecurityReports\" : \"false\",\n"
|
||||
" \"Priority\" : 0,\n"
|
||||
" \"Mtime\" : 0\n"
|
||||
"}",
|
||||
&error);
|
||||
g_assert_no_error(error);
|
||||
g_assert_true(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1031,6 +1195,7 @@ main(int argc, char **argv)
|
||||
g_test_add_func("/fwupd/remote{no-path}", fwupd_remote_nopath_func);
|
||||
g_test_add_func("/fwupd/remote{local}", fwupd_remote_local_func);
|
||||
g_test_add_func("/fwupd/remote{duplicate}", fwupd_remote_duplicate_func);
|
||||
g_test_add_func("/fwupd/remote{auth}", fwupd_remote_auth_func);
|
||||
if (fwupd_has_system_bus()) {
|
||||
g_test_add_func("/fwupd/client{remotes}", fwupd_client_remotes_func);
|
||||
g_test_add_func("/fwupd/client{devices}", fwupd_client_devices_func);
|
||||
|
@ -784,5 +784,7 @@ LIBFWUPD_1.8.1 {
|
||||
LIBFWUPD_1.8.2 {
|
||||
global:
|
||||
fwupd_device_to_json_full;
|
||||
fwupd_remote_set_checksum;
|
||||
fwupd_remote_set_filename_cache;
|
||||
local: *;
|
||||
} LIBFWUPD_1.8.1;
|
||||
|
@ -1,3 +1,7 @@
|
||||
if get_option('tests')
|
||||
subdir('tests')
|
||||
endif
|
||||
|
||||
fwupd_version_h = configure_file(
|
||||
input: 'fwupd-version.h.in',
|
||||
output: 'fwupd-version.h',
|
||||
@ -180,6 +184,7 @@ if get_option('tests')
|
||||
env.set('G_TEST_BUILDDIR', meson.current_build_dir())
|
||||
e = executable(
|
||||
'fwupd-self-test',
|
||||
metadata_xml_gz_jcat,
|
||||
sources: [
|
||||
'fwupd-self-test.c'
|
||||
],
|
||||
|
11
libfwupd/tests/auth.conf
Normal file
11
libfwupd/tests/auth.conf
Normal file
@ -0,0 +1,11 @@
|
||||
[fwupd Remote]
|
||||
Enabled=true
|
||||
MetadataURI=https://cdn.fwupd.org/downloads/firmware.xml.gz
|
||||
ReportURI=https://fwupd.org/lvfs/firmware/report
|
||||
SecurityReportURI=https://fwupd.org/lvfs/hsireports/upload
|
||||
AutomaticSecurityReports=true
|
||||
Username=user
|
||||
Password=pass
|
||||
OrderBefore=before
|
||||
OrderAfter=after
|
||||
FirmwareBaseURI=https://my.fancy.cdn/
|
23
libfwupd/tests/auth/meson.build
Normal file
23
libfwupd/tests/auth/meson.build
Normal file
@ -0,0 +1,23 @@
|
||||
jcat_tool = find_program('jcat-tool', required: false)
|
||||
|
||||
if jcat_tool.found()
|
||||
metadata_xml_gz_jcat = custom_target('metadata-xml-gz-jcat',
|
||||
input: [
|
||||
'metadata.xml.gz',
|
||||
],
|
||||
output: 'metadata.xml.gz.jcat',
|
||||
command: [
|
||||
jcat_tool, '--basename', '--appstream-id', 'localhost', 'self-sign', '@OUTPUT@', '@INPUT@',
|
||||
],
|
||||
)
|
||||
else
|
||||
metadata_xml_gz_jcat = custom_target('metadata-xml-gz-jcat',
|
||||
input: [
|
||||
'metadata.xml.gz',
|
||||
],
|
||||
output: 'metadata.xml.gz.jcat',
|
||||
command: [
|
||||
'touch', '@OUTPUT@',
|
||||
],
|
||||
)
|
||||
endif
|
1
libfwupd/tests/auth/metadata.xml.gz
Normal file
1
libfwupd/tests/auth/metadata.xml.gz
Normal file
@ -0,0 +1 @@
|
||||
hello world
|
1
libfwupd/tests/meson.build
Normal file
1
libfwupd/tests/meson.build
Normal file
@ -0,0 +1 @@
|
||||
subdir('auth')
|
Loading…
Reference in New Issue
Block a user