From aa43cf320c5651f88867555adb2a93b556bbd003 Mon Sep 17 00:00:00 2001
From: Guy Halse <guy@tenet.ac.za>
Date: Mon, 7 Jan 2019 12:09:49 +0200
Subject: [PATCH] Test signatures with a certificate file too

Use of fingerprints is deprecated elsewhere in the code, so we should
assume that to be the case here. Improves coverage in any event.
---
 tests/modules/metarefresh/lib/MetaLoaderTest.php | 13 ++++++++++---
 tests/modules/metarefresh/mdx.pem                | 12 ++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 tests/modules/metarefresh/mdx.pem

diff --git a/tests/modules/metarefresh/lib/MetaLoaderTest.php b/tests/modules/metarefresh/lib/MetaLoaderTest.php
index 9f2d5de05..c0cfe5b68 100644
--- a/tests/modules/metarefresh/lib/MetaLoaderTest.php
+++ b/tests/modules/metarefresh/lib/MetaLoaderTest.php
@@ -83,23 +83,30 @@ class MetaLoaderTest extends TestCase
         );
     }
 
-    public function testSignatureVerificationPass()
+    public function testSignatureVerificationFingerprintPass()
     {
         $this->metaloader->loadSource(array_merge($this->source, [ 'validateFingerprint' => '85:11:00:FF:34:55:BC:20:C0:20:5D:46:9B:2F:23:8F:41:09:68:F2' ]));
         $this->metaloader->dumpMetadataStdOut();
         $this->expectOutputRegex('/UTEbMBkGA1UECgwSRXhhbXBsZSBVbml2ZXJzaXR5MRgwFgYDVQQDDA9pZHAuZXhh/');
     }
 
-    public function testSignatureVerificationFailure()
+    public function testSignatureVerificationFingerprintFailure()
     {
         $this->metaloader->loadSource(array_merge($this->source, [ 'validateFingerprint' => 'DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF' ]));
         $this->metaloader->dumpMetadataStdOut();
         $this->expectOutputString('');
     }
 
+    public function testSignatureVerificationCertificatePass()
+    {
+        $this->metaloader->loadSource(array_merge($this->source, [ 'certificates' => [ dirname(dirname(__FILE__)) . '/mdx.pem' ] ]));
+        $this->metaloader->dumpMetadataStdOut();
+        $this->expectOutputRegex('/UTEbMBkGA1UECgwSRXhhbXBsZSBVbml2ZXJzaXR5MRgwFgYDVQQDDA9pZHAuZXhh/');
+    }
+
     public function testWriteMetadataFiles()
     {
-        $this->tmpdir = tempnam(sys_get_temp_dir(), 'SSP:tests:metarefresh');
+        $this->tmpdir = tempnam(sys_get_temp_dir(), 'SSP:tests:metarefresh:');
         @unlink($this->tmpdir); /* work around post 4.0.3 behaviour */
         $this->metaloader->loadSource($this->source);
         $this->metaloader->writeMetadataFiles($this->tmpdir);
diff --git a/tests/modules/metarefresh/mdx.pem b/tests/modules/metarefresh/mdx.pem
new file mode 100644
index 000000000..e5049b023
--- /dev/null
+++ b/tests/modules/metarefresh/mdx.pem
@@ -0,0 +1,12 @@
+-----BEGIN CERTIFICATE-----
+MIIBrTCCARYCCQCS5gsoFmLx7DANBgkqhkiG9w0BAQsFADAbMQswCQYDVQQGEwJB
+UTEMMAoGA1UEAwwDTURYMB4XDTE5MDEwNzA2NDMwMFoXDTM3MDMyNTA2NDMwMFow
+GzELMAkGA1UEBhMCQVExDDAKBgNVBAMMA01EWDCBnzANBgkqhkiG9w0BAQEFAAOB
+jQAwgYkCgYEAwXXyCkAJOkpece1pe36O9sURMO8RA7guGxdGVmvOfPP/9KYQ3FCA
+vjcZQVvkYP006Cgfzy8eSSrXppbINI/TkxtExIfCRReGwAJQQjesOWVvKECRg+zk
+s0VZomIHVzxOoZYDofan1H2q+Pbght5W/GsfRSgBI7RnpgAYATXg/W0CAwEAATAN
+BgkqhkiG9w0BAQsFAAOBgQBmNI2M5QTEKpbrhGqozelCFK3pZfMOa1EjkeZY4NjI
+D3yjdbWi9+9LDOuehuB1LGNvTqxpwikxS9di2h4cnzHGX9adh/DUOVWmCI3FiLF+
+po/upTEJzuRUzkn1YHLdeDuWmX/29ayZ2rPxucw8voVVDLOMetTKFMSWGxBeQ8cu
+Gw==
+-----END CERTIFICATE-----
-- 
GitLab