diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | common/flatpak-dir.c | 28 | ||||
-rw-r--r-- | common/flatpak-dir.h | 2 | ||||
-rw-r--r-- | doc/reference/flatpak-docs.xml | 1 | ||||
-rw-r--r-- | doc/reference/flatpak-sections.txt | 35 | ||||
-rw-r--r-- | lib/flatpak-bundle-ref.c | 28 | ||||
-rw-r--r-- | lib/flatpak-installation.c | 24 | ||||
-rw-r--r-- | lib/flatpak-remote.c | 2 | ||||
-rw-r--r-- | system-helper/flatpak-system-helper.c | 42 | ||||
-rw-r--r-- | system-helper/org.freedesktop.Flatpak.SystemHelper.service.in | 2 | ||||
-rw-r--r-- | tests/Makefile.am.inc | 17 | ||||
-rw-r--r-- | tests/libtest.sh | 40 | ||||
-rwxr-xr-x | tests/make-test-app.sh | 6 | ||||
-rwxr-xr-x | tests/make-test-runtime.sh | 2 | ||||
-rwxr-xr-x | tests/test-builder.sh | 8 | ||||
-rwxr-xr-x | tests/test-run-system.sh | 22 | ||||
-rwxr-xr-x | tests/test-run.sh | 78 |
17 files changed, 272 insertions, 67 deletions
diff --git a/Makefile.am b/Makefile.am index d599bdf..36c7bb8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,7 @@ endif SUBDIRS += po %.service: %.service.in config.log - $(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ + $(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@extraargs\@||" $< > $@ dbus_servicedir = $(DBUS_SERVICE_DIR) service_in_files = $(NULL) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 57986ea..9c1b0d8 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -62,6 +62,7 @@ struct FlatpakDir gboolean user; GFile *basedir; OstreeRepo *repo; + gboolean no_system_helper; FlatpakSystemHelper *system_helper; @@ -177,7 +178,20 @@ flatpak_deploy_new (GFile *dir, GKeyFile *metadata) GFile * flatpak_get_system_base_dir_location (void) { - return g_file_new_for_path (FLATPAK_SYSTEMDIR); + static gsize path = 0; + + if (g_once_init_enter (&path)) + { + gsize setup_value = 0; + const char *system_dir = g_getenv ("FLATPAK_SYSTEM_DIR"); + if (system_dir != NULL) + setup_value = (gsize)system_dir; + else + setup_value = (gsize)FLATPAK_SYSTEMDIR; + g_once_init_leave (&path, setup_value); + } + + return g_file_new_for_path ((char *)path); } GFile * @@ -223,12 +237,13 @@ flatpak_dir_get_system_helper (FlatpakDir *self) if (g_once_init_enter (&self->system_helper)) { FlatpakSystemHelper *system_helper; + const char *on_session = g_getenv ("FLATPAK_SYSTEM_HELPER_ON_SESSION"); /* To ensure reverse mapping */ flatpak_error_quark (); system_helper = - flatpak_system_helper_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + flatpak_system_helper_proxy_new_for_bus_sync (on_session != NULL ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, "org.freedesktop.Flatpak.SystemHelper", @@ -253,7 +268,7 @@ flatpak_dir_use_system_helper (FlatpakDir *self) { FlatpakSystemHelper *system_helper; - if (self->user || getuid () == 0) + if (self->no_system_helper || self->user || getuid () == 0) return FALSE; system_helper = flatpak_dir_get_system_helper (self); @@ -370,6 +385,13 @@ flatpak_dir_is_user (FlatpakDir *self) return self->user; } +void +flatpak_dir_set_no_system_helper (FlatpakDir *self, + gboolean no_system_helper) +{ + self->no_system_helper = no_system_helper; +} + GFile * flatpak_dir_get_path (FlatpakDir *self) { diff --git a/common/flatpak-dir.h b/common/flatpak-dir.h index 385139a..b4e1e3a 100644 --- a/common/flatpak-dir.h +++ b/common/flatpak-dir.h @@ -107,6 +107,8 @@ FlatpakDir *flatpak_dir_get (gboolean user); FlatpakDir *flatpak_dir_get_system (void); FlatpakDir *flatpak_dir_get_user (void); gboolean flatpak_dir_is_user (FlatpakDir *self); +void flatpak_dir_set_no_system_helper (FlatpakDir *self, + gboolean no_system_helper); GFile * flatpak_dir_get_path (FlatpakDir *self); GFile * flatpak_dir_get_changed_path (FlatpakDir *self); GFile * flatpak_dir_get_deploy_dir (FlatpakDir *self, diff --git a/doc/reference/flatpak-docs.xml b/doc/reference/flatpak-docs.xml index ce7ae49..d74a6fb 100644 --- a/doc/reference/flatpak-docs.xml +++ b/doc/reference/flatpak-docs.xml @@ -20,6 +20,7 @@ <xi:include href="xml/flatpak-installed-ref.xml"/> <xi:include href="xml/flatpak-remote-ref.xml"/> <xi:include href="xml/flatpak-remote.xml"/> + <xi:include href="xml/flatpak-bundle-ref.xml"/> <xi:include href="xml/flatpak-error.xml"/> <xi:include href="xml/flatpak-version-macros.xml"/> </chapter> diff --git a/doc/reference/flatpak-sections.txt b/doc/reference/flatpak-sections.txt index ebe1bd7..0f117e3 100644 --- a/doc/reference/flatpak-sections.txt +++ b/doc/reference/flatpak-sections.txt @@ -19,12 +19,17 @@ flatpak_installation_list_installed_refs_by_kind flatpak_installation_list_installed_refs_for_update flatpak_installation_list_remote_refs_sync flatpak_installation_list_remotes +flatpak_installation_get_remote_by_name flatpak_installation_fetch_remote_metadata_sync flatpak_installation_fetch_remote_ref_sync flatpak_installation_fetch_remote_size_sync flatpak_installation_load_app_overrides flatpak_installation_update_appstream_sync flatpak_installation_install_bundle +flatpak_installation_drop_caches +flatpak_installation_modify_remote +flatpak_installation_remove_remote +flatpak_get_default_arch FlatpakProgressCallback FlatpakUpdateFlags <SUBSECTION Standard> @@ -45,6 +50,7 @@ flatpak_installed_ref_get_is_current flatpak_installed_ref_get_latest_commit flatpak_installed_ref_get_origin flatpak_installed_ref_load_metadata +flatpak_installed_ref_get_subpaths <SUBSECTION Standard> FlatpakInstalledRefClass FLATPAK_INSTALLED_REF @@ -90,14 +96,23 @@ flatpak_ref_get_type <FILE>flatpak-remote</FILE> <TITLE>FlatpakRemote</TITLE> FlatpakRemote +flatpak_remote_new +flatpak_remote_get_name flatpak_remote_get_appstream_dir flatpak_remote_get_appstream_timestamp flatpak_remote_get_gpg_verify -flatpak_remote_get_name +flatpak_remote_set_gpg_verify +flatpak_remote_set_gpg_key flatpak_remote_get_noenumerate +flatpak_remote_set_noenumerate flatpak_remote_get_prio +flatpak_remote_set_prio flatpak_remote_get_title +flatpak_remote_set_title flatpak_remote_get_url +flatpak_remote_set_url +flatpak_remote_get_disabled +flatpak_remote_set_disabled <SUBSECTION Standard> FlatpakRemoteClass FLATPAK_IS_REMOTE @@ -120,3 +135,21 @@ FLATPAK_ERROR FlatpakError flatpak_error_quark </SECTION> + +<SECTION> +<FILE>flatpak-bundle-ref</FILE> +FlatpakBundleRef +flatpak_bundle_ref_new +flatpak_bundle_ref_get_file +flatpak_bundle_ref_get_metadata +flatpak_bundle_ref_get_appstream +flatpak_bundle_ref_get_icon +flatpak_bundle_ref_get_origin +flatpak_bundle_ref_get_installed_size +<SUBSECTION Standard> +FlatpakBundleRefClass +FLATPAK_TYPE_BUNDLE_REF +FLATPAK_BUNDLE_REF +FLATPAK_IS_BUNDLE_REF +flatpak_bundle_ref_get_type +</SECTION> diff --git a/lib/flatpak-bundle-ref.c b/lib/flatpak-bundle-ref.c index ba3955e..cc5c4ca 100644 --- a/lib/flatpak-bundle-ref.c +++ b/lib/flatpak-bundle-ref.c @@ -131,7 +131,7 @@ flatpak_bundle_ref_init (FlatpakBundleRef *self) /** * flatpak_bundle_ref_get_file: - * @self: a #FlatpakInstallation + * @self: a #FlatpakBundleRef * * Get the file this bundle is stored in. * @@ -147,7 +147,7 @@ flatpak_bundle_ref_get_file (FlatpakBundleRef *self) /** * flatpak_bundle_ref_get_metadata: - * @self: a #FlatpakInstallation + * @self: a #FlatpakBundleRef * * Get the metadata for the app/runtime * @@ -165,7 +165,7 @@ flatpak_bundle_ref_get_metadata (FlatpakBundleRef *self) /** * flatpak_bundle_ref_get_appstream: - * @self: a #FlatpakInstallation + * @self: a #FlatpakBundleRef * * Get the compressed appstream for the app/runtime * @@ -183,7 +183,7 @@ flatpak_bundle_ref_get_appstream (FlatpakBundleRef *self) /** * flatpak_bundle_ref_get_icon: - * @self: a #FlatpakInstallation + * @self: a #FlatpakBundleRef * @size: 64 or 128 * * Get the icon png data for the app/runtime @@ -207,7 +207,7 @@ flatpak_bundle_ref_get_icon (FlatpakBundleRef *self, /** * flatpak_bundle_ref_get_origin: - * @self: a #FlatpakInstallation + * @self: a #FlatpakBundleRef * * Get the origin url stored in the bundle * @@ -221,6 +221,14 @@ flatpak_bundle_ref_get_origin (FlatpakBundleRef *self) return g_strdup (priv->origin); } +/** + * flatpak_bundle_ref_get_installed_size: + * @self: a FlatpakBundleRef + * + * Returns the installed size for the bundle. + * + * Returns: the installed size + */ guint64 flatpak_bundle_ref_get_installed_size (FlatpakBundleRef *self) { @@ -229,7 +237,15 @@ flatpak_bundle_ref_get_installed_size (FlatpakBundleRef *self) return priv->installed_size; } - +/** + * flatpak_bundle_ref_new: + * @file: a #GFile + * @error: (allow-none): return location for an error + * + * Creates a new bundle ref for the given file. + * + * Returns: a new bundle ref. + */ FlatpakBundleRef * flatpak_bundle_ref_new (GFile *file, GError **error) diff --git a/lib/flatpak-installation.c b/lib/flatpak-installation.c index bef2381..5e76b53 100644 --- a/lib/flatpak-installation.c +++ b/lib/flatpak-installation.c @@ -228,6 +228,7 @@ flatpak_installation_get_dir (FlatpakInstallation *self) /** * flatpak_installation_drop_caches: + * @self: a #FlatpakInstallation * @cancellable: (nullable): a #GCancellable * @error: return location for a #GError * @@ -254,6 +255,7 @@ flatpak_installation_drop_caches (FlatpakInstallation *self, { priv->dir_unlocked = clone; g_object_unref (old); + res = TRUE; } G_UNLOCK (dir); @@ -710,6 +712,17 @@ flatpak_installation_list_remotes (FlatpakInstallation *self, return g_steal_pointer (&remotes); } +/** + * flatpak_installation_modify_remote: + * @self: a #FlatpakInstallation + * @remote: the modified #FlatpakRemote + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Saves changes in the @remote object. + * + * Returns: %TRUE if the modifications have been committed successfully + */ gboolean flatpak_installation_modify_remote (FlatpakInstallation *self, FlatpakRemote *remote, @@ -734,6 +747,17 @@ flatpak_installation_modify_remote (FlatpakInstallation *self, return TRUE; } +/** + * flatpak_installation_remove_remote: + * @self: a #FlatpakInstallation + * @name: the name of the remote to remove + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Removes the remote with the given name from the installation. + * + * Returns: %TRUE if the remote has been removed successfully + */ gboolean flatpak_installation_remove_remote (FlatpakInstallation *self, const char *name, diff --git a/lib/flatpak-remote.c b/lib/flatpak-remote.c index 13cb37f..08f2dc3 100644 --- a/lib/flatpak-remote.c +++ b/lib/flatpak-remote.c @@ -371,7 +371,7 @@ flatpak_remote_set_noenumerate (FlatpakRemote *self, } /** - * flatpak_remote_get_disable: + * flatpak_remote_get_disabled: * @self: a #FlatpakRemote * * Returns whether this remote is disabled. diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c index e31239e..3bf21ff 100644 --- a/system-helper/flatpak-system-helper.c +++ b/system-helper/flatpak-system-helper.c @@ -35,6 +35,9 @@ static FlatpakSystemHelper *helper = NULL; static GMainLoop *main_loop = NULL; static guint name_owner_id = 0; +static gboolean on_session_bus = FALSE; +static gboolean no_idle_exit = FALSE; + #define IDLE_TIMEOUT_SECS 10*60 /* This uses a weird Auto prefix to avoid conflicts with later added polkit types. @@ -102,14 +105,24 @@ schedule_idle_callback (void) G_LOCK(idle); - if (idle_timeout_id != 0) - g_source_remove (idle_timeout_id); + if (!no_idle_exit) + { + if (idle_timeout_id != 0) + g_source_remove (idle_timeout_id); - idle_timeout_id = g_timeout_add_seconds (IDLE_TIMEOUT_SECS, idle_timeout_cb, NULL); + idle_timeout_id = g_timeout_add_seconds (IDLE_TIMEOUT_SECS, idle_timeout_cb, NULL); + } G_UNLOCK(idle); } +static FlatpakDir * +dir_get_system (void) +{ + FlatpakDir *system = flatpak_dir_get_system (); + flatpak_dir_set_no_system_helper (system, TRUE); + return system; +} static gboolean handle_deploy (FlatpakSystemHelper *object, @@ -120,7 +133,7 @@ handle_deploy (FlatpakSystemHelper *object, const gchar *arg_origin, const gchar *const *arg_subpaths) { - g_autoptr(FlatpakDir) system = flatpak_dir_get_system (); + g_autoptr(FlatpakDir) system = dir_get_system (); g_autoptr(GFile) path = g_file_new_for_path (arg_repo_path); g_autoptr(GError) error = NULL; g_autoptr(GFile) deploy_dir = NULL; @@ -236,7 +249,7 @@ handle_deploy_appstream (FlatpakSystemHelper *object, const gchar *arg_origin, const gchar *arg_arch) { - g_autoptr(FlatpakDir) system = flatpak_dir_get_system (); + g_autoptr(FlatpakDir) system = dir_get_system (); g_autoptr(GFile) path = g_file_new_for_path (arg_repo_path); g_autoptr(GError) error = NULL; g_autoptr(GMainContext) main_context = NULL; @@ -301,7 +314,7 @@ handle_uninstall (FlatpakSystemHelper *object, guint arg_flags, const gchar *arg_ref) { - g_autoptr(FlatpakDir) system = flatpak_dir_get_system (); + g_autoptr(FlatpakDir) system = dir_get_system (); g_autoptr(GError) error = NULL; g_debug ("Uninstall %u %s", arg_flags, arg_ref); @@ -338,7 +351,7 @@ handle_configure_remote (FlatpakSystemHelper *object, const gchar *arg_config, GVariant *arg_gpg_key) { - g_autoptr(FlatpakDir) system = flatpak_dir_get_system (); + g_autoptr(FlatpakDir) system = dir_get_system (); g_autoptr(GError) error = NULL; g_autoptr(GKeyFile) config = g_key_file_new (); g_autofree char *group = g_strdup_printf ("remote \"%s\"", arg_remote); @@ -435,7 +448,16 @@ flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface, sender = g_dbus_method_invocation_get_sender (invocation); subject = polkit_system_bus_name_new (sender); - if (g_strcmp0 (method_name, "Deploy") == 0) + if (on_session_bus) + { + /* This is test code, make sure it never runs with privileges */ + g_assert (geteuid () != 0); + g_assert (getuid () != 0); + g_assert (getegid () != 0); + g_assert (getgid () != 0); + authorized = TRUE; + } + else if (g_strcmp0 (method_name, "Deploy") == 0) { const char *ref, *origin; guint32 flags; @@ -670,6 +692,8 @@ main (int argc, const GOptionEntry options[] = { { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Enable debug output.", NULL }, + { "session", 0, 0, G_OPTION_ARG_NONE, &on_session_bus, "Run in session, not system scope (for tests).", NULL }, + { "no-idle-exit", 0, 0, G_OPTION_ARG_NONE, &no_idle_exit, "Don't exit when idle.", NULL }, { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "Show program version.", NULL}, { NULL } }; @@ -742,7 +766,7 @@ main (int argc, if (replace) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; - name_owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, + name_owner_id = g_bus_own_name (on_session_bus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM, "org.freedesktop.Flatpak.SystemHelper", flags, on_bus_acquired, diff --git a/system-helper/org.freedesktop.Flatpak.SystemHelper.service.in b/system-helper/org.freedesktop.Flatpak.SystemHelper.service.in index 4e9293a..ed166ee 100644 --- a/system-helper/org.freedesktop.Flatpak.SystemHelper.service.in +++ b/system-helper/org.freedesktop.Flatpak.SystemHelper.service.in @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.freedesktop.Flatpak.SystemHelper -Exec=@libexecdir@/flatpak-system-helper +Exec=@libexecdir@/flatpak-system-helper@extraargs@ SystemdService=flatpak-system-helper.service diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index 4724547..105587c 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -25,7 +25,7 @@ test_doc_portal_LDADD = \ $(NULL) test_doc_portal_SOURCES = tests/test-doc-portal.c $(xdp_dbus_built_sources) -EXTRA_test_doc_portal_DEPENDENCIES = tests/services/org.freedesktop.impl.portal.PermissionStore.service tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service +EXTRA_test_doc_portal_DEPENDENCIES = tests/services/org.freedesktop.impl.portal.PermissionStore.service tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service tests/services/org.freedesktop.Flatpak.SystemHelper.service tests/services/org.freedesktop.portal.Documents.service: document-portal/org.freedesktop.portal.Documents.service.in mkdir -p tests/services @@ -39,6 +39,10 @@ tests/services/org.freedesktop.Flatpak.service: session-helper/org.freedesktop.F mkdir -p tests/services $(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" $< > $@ +tests/services/org.freedesktop.Flatpak.SystemHelper.service: system-helper/org.freedesktop.Flatpak.SystemHelper.service.in + mkdir -p tests/services + $(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" -e "s|\@extraargs\@| --session --no-idle-exit|" $< > $@ + tests/libtest.sh: tests/services/org.freedesktop.impl.portal.PermissionStore.service tests/services/org.freedesktop.portal.Documents.service tests/services/org.freedesktop.Flatpak.service install-test-data-hook: @@ -47,6 +51,7 @@ if ENABLE_INSTALLED_TESTS ln -sf $(dbus_servicedir)/org.freedesktop.Flatpak.service $(DESTDIR)$(installed_testdir)/services/ ln -sf $(dbus_servicedir)/org.freedesktop.portal.Documents.service $(DESTDIR)$(installed_testdir)/services/ ln -sf $(dbus_servicedir)/org.freedesktop.impl.portal.PermissionStore.service $(DESTDIR)$(installed_testdir)/services/ + $(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@extraargs\@| --session --no-idle-exit|" $(top_srcdir)/system-helper/org.freedesktop.Flatpak.SystemHelper.service.in > $(DESTDIR)$(installed_testdir)/services/org.freedesktop.Flatpak.SystemHelper.service endif tests/package_version.txt: Makefile @@ -70,11 +75,21 @@ installed_test_data = \ tests/session.conf.in \ $(NULL) +if ENABLE_INSTALLED_TESTS +installed_test_keyringdir = $(installed_testdir)/test-keyring +installed_test_keyring_DATA = \ + tests/test-keyring/pubring.gpg \ + tests/test-keyring/secring.gpg \ + $(NULL) + +endif + EXTRA_DIST += $(installed_test_SCRIPTS) $(installed_test_data) test_scripts = \ tests/test-basic.sh \ tests/test-run.sh \ + tests/test-run-system.sh \ tests/test-builder.sh \ $(NULL) diff --git a/tests/libtest.sh b/tests/libtest.sh index 0717af2..4180de7 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -69,12 +69,25 @@ fi # We need this to be in /var/tmp because /tmp has no xattr support TEST_DATA_DIR=`mktemp -d /var/tmp/test-flatpak-XXXXXX` +mkdir -p ${TEST_DATA_DIR}/home +mkdir -p ${TEST_DATA_DIR}/system +export FLATPAK_SYSTEM_DIR=${TEST_DATA_DIR}/system +export FLATPAK_SYSTEM_HELPER_ON_SESSION=1 -export XDG_DATA_HOME=${TEST_DATA_DIR}/share +export XDG_DATA_HOME=${TEST_DATA_DIR}/home/share -export USERDIR=${TEST_DATA_DIR}/share/flatpak +export USERDIR=${TEST_DATA_DIR}/home/share/flatpak +export SYSTEMDIR=${TEST_DATA_DIR}/system export ARCH=`flatpak --default-arch` +if [ x${USE_SYSTEMDIR-} == xyes ] ; then + export FL_DIR=${SYSTEMDIR} + export U= +else + export FL_DIR=${USERDIR} + export U="--user" +fi + export FLATPAK="${CMD_PREFIX} flatpak" assert_streq () { @@ -143,24 +156,31 @@ assert_file_empty() { fi } +export FL_GPG_HOMEDIR=$(dirname $0)/test-keyring +export FL_GPG_ID=7B0961FD +export FL_GPGARGS="--gpg-homedir=${FL_GPG_HOMEDIR} --gpg-sign=${FL_GPG_ID}" + setup_repo () { - . $(dirname $0)/make-test-runtime.sh org.test.Platform bash ls cat echo readlink > /dev/null - . $(dirname $0)/make-test-app.sh > /dev/null - flatpak remote-add --user --no-gpg-verify test-repo repo + GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-runtime.sh org.test.Platform bash ls cat echo readlink > /dev/null + GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-app.sh > /dev/null + flatpak remote-add ${U} --gpg-import=${FL_GPG_HOMEDIR}/pubring.gpg test-repo repo } -setup_sdk_repo () { - . $(dirname $0)/make-test-runtime.sh org.test.Sdk bash ls cat echo readlink make mkdir cp touch > /dev/null +make_updated_app () { + GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-app.sh UPDATED > /dev/null } +setup_sdk_repo () { + GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-runtime.sh org.test.Sdk bash ls cat echo readlink make mkdir cp touch > /dev/null +} install_repo () { - ${FLATPAK} --user install test-repo org.test.Platform master - ${FLATPAK} --user install test-repo org.test.Hello master + ${FLATPAK} ${U} install test-repo org.test.Platform master + ${FLATPAK} ${U} install test-repo org.test.Hello master } install_sdk_repo () { - ${FLATPAK} --user install test-repo org.test.Sdk master + ${FLATPAK} ${U} install test-repo org.test.Sdk master } run () { diff --git a/tests/make-test-app.sh b/tests/make-test-app.sh index e0f927e..64b72bc 100755 --- a/tests/make-test-app.sh +++ b/tests/make-test-app.sh @@ -4,13 +4,15 @@ set -e DIR=`mktemp -d` +EXTRA="${1-}" + # Init dir flatpak build-init ${DIR} org.test.Hello org.test.Platform org.test.Platform mkdir -p ${DIR}/files/bin cat > ${DIR}/files/bin/hello.sh <<EOF #!/bin/sh -echo "Hello world, from a sandbox" +echo "Hello world, from a sandbox$EXTRA" EOF chmod a+x ${DIR}/files/bin/hello.sh @@ -48,5 +50,5 @@ EOF cp $(dirname $0)/org.test.Hello.png ${DIR}/files/share/app-info/icons/flatpak/64x64/ flatpak build-finish --command=hello.sh ${DIR} -flatpak build-export repo ${DIR} +flatpak build-export ${GPGARGS-} repo ${DIR} rm -rf ${DIR} diff --git a/tests/make-test-runtime.sh b/tests/make-test-runtime.sh index d2aeb3b..8a3c455 100755 --- a/tests/make-test-runtime.sh +++ b/tests/make-test-runtime.sh @@ -32,5 +32,5 @@ done mkdir -p ${DIR}/usr/lib/locale/ cp -r /usr/lib/locale/C.* ${DIR}/usr/lib/locale/en_US -flatpak build-export --runtime repo ${DIR} +flatpak build-export --runtime ${GPGARGS-} repo ${DIR} rm -rf ${DIR} diff --git a/tests/test-builder.sh b/tests/test-builder.sh index dcbe586..19b44c6 100755 --- a/tests/test-builder.sh +++ b/tests/test-builder.sh @@ -35,7 +35,7 @@ cd $TEST_DATA_DIR/ cp -a $(dirname $0)/test-configure . echo "version1" > app-data cp $(dirname $0)/test.json . -flatpak-builder --repo=$REPO --force-clean appdir test.json > /dev/null +flatpak-builder --repo=$REPO $FL_GPGARGS --force-clean appdir test.json > /dev/null assert_file_has_content appdir/files/share/app-data version1 assert_file_has_content appdir/metadata shared=network; @@ -51,7 +51,7 @@ assert_file_has_content hello_out2 '^Hello world2, from a sandbox$' echo "ok build" -${FLATPAK} --user install test-repo org.test.Hello2 master +${FLATPAK} ${U} install test-repo org.test.Hello2 master run org.test.Hello2 > hello_out3 assert_file_has_content hello_out3 '^Hello world2, from a sandbox$' @@ -61,10 +61,10 @@ assert_file_has_content app_data_1 version1 echo "ok install+run" echo "version2" > app-data -flatpak-builder --repo=$REPO --force-clean appdir test.json > /dev/null +flatpak-builder $FL_GPGARGS --repo=$REPO --force-clean appdir test.json > /dev/null assert_file_has_content appdir/files/share/app-data version2 -${FLATPAK} --user update org.test.Hello2 master +${FLATPAK} ${U} update org.test.Hello2 master run --command=cat org.test.Hello2 /app/share/app-data > app_data_2 assert_file_has_content app_data_2 version2 diff --git a/tests/test-run-system.sh b/tests/test-run-system.sh new file mode 100755 index 0000000..d87f6e9 --- /dev/null +++ b/tests/test-run-system.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# Copyright (C) 2011 Colin Walters <walters@verbum.org> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +export USE_SYSTEMDIR=yes + +. $(dirname $0)/test-run.sh diff --git a/tests/test-run.sh b/tests/test-run.sh index c10912a..e59f278 100755 --- a/tests/test-run.sh +++ b/tests/test-run.sh @@ -21,42 +21,42 @@ set -euo pipefail . $(dirname $0)/libtest.sh -echo "1..5" +echo "1..7" setup_repo install_repo # Verify that app is correctly installed -assert_has_dir $USERDIR/app/org.test.Hello -assert_has_symlink $USERDIR/app/org.test.Hello/current -assert_symlink_has_content $USERDIR/app/org.test.Hello/current ^$ARCH/master$ -assert_has_dir $USERDIR/app/org.test.Hello/$ARCH/master -assert_has_symlink $USERDIR/app/org.test.Hello/$ARCH/master/active -ID=`readlink $USERDIR/app/org.test.Hello/$ARCH/master/active` -assert_has_file $USERDIR/app/org.test.Hello/$ARCH/master/active/deploy -assert_has_file $USERDIR/app/org.test.Hello/$ARCH/master/active/metadata -assert_has_dir $USERDIR/app/org.test.Hello/$ARCH/master/active/files -assert_has_dir $USERDIR/app/org.test.Hello/$ARCH/master/active/export -assert_has_file $USERDIR/exports/share/applications/org.test.Hello.desktop +assert_has_dir $FL_DIR/app/org.test.Hello +assert_has_symlink $FL_DIR/app/org.test.Hello/current +assert_symlink_has_content $FL_DIR/app/org.test.Hello/current ^$ARCH/master$ +assert_has_dir $FL_DIR/app/org.test.Hello/$ARCH/master +assert_has_symlink $FL_DIR/app/org.test.Hello/$ARCH/master/active +ID=`readlink $FL_DIR/app/org.test.Hello/$ARCH/master/active` +assert_has_file $FL_DIR/app/org.test.Hello/$ARCH/master/active/deploy +assert_has_file $FL_DIR/app/org.test.Hello/$ARCH/master/active/metadata +assert_has_dir $FL_DIR/app/org.test.Hello/$ARCH/master/active/files +assert_has_dir $FL_DIR/app/org.test.Hello/$ARCH/master/active/export +assert_has_file $FL_DIR/exports/share/applications/org.test.Hello.desktop # Ensure Exec key is rewritten -assert_file_has_content $USERDIR/exports/share/applications/org.test.Hello.desktop "^Exec=.*/flatpak run --branch=master --arch=$ARCH --command=hello.sh org.test.Hello$" -assert_has_file $USERDIR/exports/share/icons/hicolor/64x64/apps/org.test.Hello.png +assert_file_has_content $FL_DIR/exports/share/applications/org.test.Hello.desktop "^Exec=.*/flatpak run --branch=master --arch=$ARCH --command=hello.sh org.test.Hello$" +assert_has_file $FL_DIR/exports/share/icons/hicolor/64x64/apps/org.test.Hello.png # Ensure triggers ran -assert_has_file $USERDIR/exports/share/applications/mimeinfo.cache -assert_file_has_content $USERDIR/exports/share/applications/mimeinfo.cache x-test/Hello -assert_has_file $USERDIR/exports/share/icons/hicolor/icon-theme.cache -assert_has_file $USERDIR/exports/share/icons/hicolor/index.theme +assert_has_file $FL_DIR/exports/share/applications/mimeinfo.cache +assert_file_has_content $FL_DIR/exports/share/applications/mimeinfo.cache x-test/Hello +assert_has_file $FL_DIR/exports/share/icons/hicolor/icon-theme.cache +assert_has_file $FL_DIR/exports/share/icons/hicolor/index.theme -$FLATPAK list --user | grep org.test.Hello > /dev/null -$FLATPAK list --user -d | grep org.test.Hello | grep test-repo > /dev/null -$FLATPAK list --user -d | grep org.test.Hello | grep current > /dev/null -$FLATPAK list --user -d | grep org.test.Hello | grep ${ID:0:12} > /dev/null +$FLATPAK list ${U} | grep org.test.Hello > /dev/null +$FLATPAK list ${U} -d | grep org.test.Hello | grep test-repo > /dev/null +$FLATPAK list ${U} -d | grep org.test.Hello | grep current > /dev/null +$FLATPAK list ${U} -d | grep org.test.Hello | grep ${ID:0:12} > /dev/null -$FLATPAK info --user org.test.Hello > /dev/null -$FLATPAK info --user org.test.Hello | grep test-repo > /dev/null -$FLATPAK info --user org.test.Hello | grep $ID > /dev/null +$FLATPAK info ${U} org.test.Hello > /dev/null +$FLATPAK info ${U} org.test.Hello | grep test-repo > /dev/null +$FLATPAK info ${U} org.test.Hello | grep $ID > /dev/null echo "ok install" @@ -89,15 +89,39 @@ ARGS="--filesystem=host" run_sh cat $(dirname $0)/package_version.txt > /dev/nul echo "ok namespaces" -$FLATPAK override --user --filesystem=host org.test.Hello +$FLATPAK override ${U} --filesystem=host org.test.Hello run_sh cat $(dirname $0)/package_version.txt &> /dev/null if ARGS="--nofilesystem=host" run_sh cat $(dirname $0)/package_version.txt &> /dev/null; then assert_not_reached "Unexpectedly allowed to access --nofilesystem=host file" fi -$FLATPAK override --user --nofilesystem=host org.test.Hello +$FLATPAK override ${U} --nofilesystem=host org.test.Hello if run_sh cat $(dirname $0)/package_version.txt &> /dev/null; then assert_not_reached "Unexpectedly allowed to access file" fi echo "ok overrides" + +OLD_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello` + +# TODO: For weird reasons this breaks in the system case. Needs debugging +if [ x${USE_SYSTEMDIR-} != xyes ] ; then + ${FLATPAK} ${U} update -v org.test.Hello master + ALSO_OLD_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello` + assert_streq "$OLD_COMMIT" "$ALSO_OLD_COMMIT" +fi + +echo "ok null update" + +make_updated_app + +${FLATPAK} ${U} update org.test.Hello + +NEW_COMMIT=`${FLATPAK} ${U} info --show-commit org.test.Hello` + +assert_not_streq "$OLD_COMMIT" "$NEW_COMMIT" + +run org.test.Hello > hello_out +assert_file_has_content hello_out '^Hello world, from a sandboxUPDATED$' + +echo "ok update" |