testing/tests/download: test case for git refs
authorRicardo Martincoski <ricardo.martincoski@datacom.ind.br>
Sat, 12 May 2018 02:58:28 +0000 (23:58 -0300)
committerArnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Mon, 4 Feb 2019 19:44:29 +0000 (20:44 +0100)
All upcoming tests for git refs will rely on the return code of make to
determine whether a git ref can be downloaded or not and also to
determine whether the downloaded content is correct (all of this taking
advantage of the check-hash mechanism already in place for git
packages).
So to avoid false results i.e. in the case the check-hash mechanism
become broken in the master branch, add some sanity checks before the
actual test of download git refs.

Add the minimum test case for git refs containing only sanity checks.
Reuse the commit in the static repo.
Add a br2-external with two packages to check that:
 - trying to download an invalid sha1 generates an error;
 - downloading a valid sha1 that contains unexpected content generates
   an error.

In order to ease the maintenance and review, each upcoming patch adding
checks to this test case will add at same time the commits to the static
repo, the equivalent packages to the br2-external and code to the test
case.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@datacom.ind.br>
Cc: Arnout Vandecappelle <arnout@mind.be>
Tested-by: Matthew Weber <matthew.weber@rockwellcollins.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
.gitlab-ci.yml
support/testing/tests/download/br2-external/git-refs/Config.in [new file with mode: 0644]
support/testing/tests/download/br2-external/git-refs/external.desc [new file with mode: 0644]
support/testing/tests/download/br2-external/git-refs/external.mk [new file with mode: 0644]
support/testing/tests/download/br2-external/git-refs/package/git-wrong-content/git-wrong-content.hash [new file with mode: 0644]
support/testing/tests/download/br2-external/git-refs/package/git-wrong-content/git-wrong-content.mk [new file with mode: 0644]
support/testing/tests/download/br2-external/git-refs/package/git-wrong-sha1/git-wrong-sha1.mk [new file with mode: 0644]
support/testing/tests/download/test_git.py

index 6a5a67959498b8fcfef6b3a7c53b97c38d50b4bc..f05b9d041e855ca8364e48291a5664f7b02668c5 100644 (file)
@@ -292,6 +292,7 @@ tests.core.test_timezone.TestGlibcAllTimezone: *runtime_test
 tests.core.test_timezone.TestGlibcNonDefaultLimitedTimezone: *runtime_test
 tests.core.test_timezone.TestNoTimezone: *runtime_test
 tests.download.test_git.TestGitHash: *runtime_test
+tests.download.test_git.TestGitRefs: *runtime_test
 tests.fs.test_ext.TestExt2: *runtime_test
 tests.fs.test_ext.TestExt2r1: *runtime_test
 tests.fs.test_ext.TestExt3: *runtime_test
diff --git a/support/testing/tests/download/br2-external/git-refs/Config.in b/support/testing/tests/download/br2-external/git-refs/Config.in
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/support/testing/tests/download/br2-external/git-refs/external.desc b/support/testing/tests/download/br2-external/git-refs/external.desc
new file mode 100644 (file)
index 0000000..69f40d4
--- /dev/null
@@ -0,0 +1 @@
+name: GIT_REFS
diff --git a/support/testing/tests/download/br2-external/git-refs/external.mk b/support/testing/tests/download/br2-external/git-refs/external.mk
new file mode 100644 (file)
index 0000000..ab38c27
--- /dev/null
@@ -0,0 +1,4 @@
+include $(sort $(wildcard $(BR2_EXTERNAL_GIT_REFS_PATH)/package/*/*.mk))
+
+# Get the git server port number from the test infra
+GITREMOTE_PORT_NUMBER ?= 9418
diff --git a/support/testing/tests/download/br2-external/git-refs/package/git-wrong-content/git-wrong-content.hash b/support/testing/tests/download/br2-external/git-refs/package/git-wrong-content/git-wrong-content.hash
new file mode 100644 (file)
index 0000000..47b2b8b
--- /dev/null
@@ -0,0 +1,2 @@
+ sha256  04715901977503d1df650e0959f4d31d8e7b105e2ac99a2182e0652b8f13baa1  git-wrong-content-a238b1dfcd825d47d834af3c5223417c8411d90d.tar.gz
+ sha256  0000000000000000000000000000000000000000000000000000000000000000  file
diff --git a/support/testing/tests/download/br2-external/git-refs/package/git-wrong-content/git-wrong-content.mk b/support/testing/tests/download/br2-external/git-refs/package/git-wrong-content/git-wrong-content.mk
new file mode 100644 (file)
index 0000000..786224d
--- /dev/null
@@ -0,0 +1,11 @@
+################################################################################
+#
+# git-wrong-content
+#
+################################################################################
+
+GIT_WRONG_CONTENT_VERSION = a238b1dfcd825d47d834af3c5223417c8411d90d
+GIT_WRONG_CONTENT_SITE = git://localhost:$(GITREMOTE_PORT_NUMBER)/repo.git
+GIT_WRONG_CONTENT_LICENSE_FILES = file
+
+$(eval $(generic-package))
diff --git a/support/testing/tests/download/br2-external/git-refs/package/git-wrong-sha1/git-wrong-sha1.mk b/support/testing/tests/download/br2-external/git-refs/package/git-wrong-sha1/git-wrong-sha1.mk
new file mode 100644 (file)
index 0000000..f9d0d22
--- /dev/null
@@ -0,0 +1,11 @@
+################################################################################
+#
+# git-wrong-sha1
+#
+################################################################################
+
+GIT_WRONG_SHA1_VERSION = 0000000000000000000000000000000000000000
+GIT_WRONG_SHA1_SITE = git://localhost:$(GITREMOTE_PORT_NUMBER)/repo.git
+GIT_WRONG_SHA1_LICENSE_FILES = file
+
+$(eval $(generic-package))
index 156784dc9c035e80fdb2e46ab5d1163eea8a3b37..64b060ba303d38543c0877350a10f856305d355e 100644 (file)
@@ -33,6 +33,15 @@ class GitTestBase(infra.basetest.BRTest):
                       "{}-source".format(package)],
                      env)
 
+    def check_download(self, package):
+        # store downloaded tarball inside the output dir so the test infra
+        # cleans it up at the end
+        env = {"BR2_DL_DIR": os.path.join(self.builddir, "dl"),
+               "GITREMOTE_PORT_NUMBER": str(self.gitremote.port)}
+        self.b.build(["{}-dirclean".format(package),
+                      "{}-legal-info".format(package)],
+                     env)
+
 
 class TestGitHash(GitTestBase):
     br2_external = [infra.filepath("tests/download/br2-external/git-hash")]
@@ -42,3 +51,13 @@ class TestGitHash(GitTestBase):
             self.check_hash("bad")
         self.check_hash("good")
         self.check_hash("nohash")
+
+
+class TestGitRefs(GitTestBase):
+    br2_external = [infra.filepath("tests/download/br2-external/git-refs")]
+
+    def test_run(self):
+        with self.assertRaises(SystemError):
+            self.check_download("git-wrong-content")
+        with self.assertRaises(SystemError):
+            self.check_download("git-wrong-sha1")