repo: Add OSTREE_REPO_TEST_ERROR=invalid-cache env var
authorDan Nicholson <nicholson@endlessm.com>
Fri, 10 Aug 2018 16:53:50 +0000 (11:53 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 14 Aug 2018 13:38:11 +0000 (13:38 +0000)
Add an invalid-cache test error flag to ensure that the code that checks
for and recovers from a corrupted summary cache is hit. This helps make
sure that the recovery path is actually used without resorting to
G_MESSAGES_DEBUG.

Closes: #1698
Approved by: cgwalters

src/libostree/ostree-repo-private.h
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.c
tests/test-pull-summary-sigs.sh

index 4e5043268552f39056c11ba4b4312723f7e7e811..99eaf49401812298d0a478bddd7940e81e1784ae 100644 (file)
@@ -61,7 +61,8 @@ G_BEGIN_DECLS
 #define OSTREE_COMMIT_TIMESTAMP "ostree.commit.timestamp"
 
 typedef enum {
-  OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0)
+  OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0),
+  OSTREE_REPO_TEST_ERROR_INVALID_CACHE = (1 << 1),
 } OstreeRepoTestErrorFlags;
 
 struct OstreeRepoCommitModifier {
index f692874d443f32adf7636d23f49b1ca00c078634..ed61c97e80c43e449c1acae99dfbc431204c72fb 100644 (file)
@@ -4037,10 +4037,20 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
             if (summary_from_cache)
               {
                 /* The cached summary doesn't match, fetch a new one and verify again */
+                if ((self->test_error_flags & OSTREE_REPO_TEST_ERROR_INVALID_CACHE) > 0)
+                  {
+                    g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                                 "Remote %s cached summary invalid and "
+                                 "OSTREE_REPO_TEST_ERROR_INVALID_CACHE specified",
+                                 pull_data->remote_name);
+                    goto out;
+                  }
+                else
+                  g_debug ("Remote %s cached summary invalid, pulling new version",
+                           pull_data->remote_name);
+
                 summary_from_cache = FALSE;
                 g_clear_pointer (&bytes_summary, (GDestroyNotify)g_bytes_unref);
-                g_debug ("Remote %s cached summary invalid, pulling new version",
-                         pull_data->remote_name);
                 if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher,
                                                                  pull_data->meta_mirrorlist,
                                                                  "summary",
index 922e8a663dd70319b6f607163d289cacaf7c23da..4bea0f10a573b2aab9b4d6e412b79efc5805a82c 100644 (file)
@@ -1187,6 +1187,7 @@ ostree_repo_init (OstreeRepo *self)
   static gsize gpgme_initialized;
   const GDebugKey test_error_keys[] = {
     { "pre-commit", OSTREE_REPO_TEST_ERROR_PRE_COMMIT },
+    { "invalid-cache", OSTREE_REPO_TEST_ERROR_INVALID_CACHE },
   };
 
   if (g_once_init_enter (&gpgme_initialized))
index 4b71b506662d9f6a17f55869b763ccf5f86020e6..dee186b5b756589642a9005830d191d340a22b57 100755 (executable)
@@ -245,7 +245,19 @@ cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summ
 # cache before validating the signature. That would mean the cache would
 # have mismatched summary and signature and ostree would remain
 # deadlocked there until the remote published a new signature.
+#
+# First pull with OSTREE_REPO_TEST_ERROR=invalid-cache to see the
+# invalid cache is detected. Then pull again to check if it can be
+# recovered from.
 cp ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 repo/tmp/cache/summaries/origin
+if OSTREE_REPO_TEST_ERROR=invalid-cache ${OSTREE} --repo=repo pull origin main 2>err.txt; then
+    assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_INVALID_CACHE"
+fi
+assert_file_has_content err.txt "OSTREE_REPO_TEST_ERROR_INVALID_CACHE"
+assert_has_file repo/tmp/cache/summaries/origin
+assert_has_file repo/tmp/cache/summaries/origin.sig
+cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.2 >&2
+cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.1 >&2
 ${OSTREE} --repo=repo pull origin main
 assert_has_file repo/tmp/cache/summaries/origin
 assert_has_file repo/tmp/cache/summaries/origin.sig