From ecd2d88b09b000835c91f1ef8982ce14b5dbbc8b Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Aug 2020 17:05:49 +0000 Subject: [PATCH] Don't let the tests fail. The test user doesn't have a private key --- src/Util/HTTPSignature.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 89da59ba26..bbd5cd9b15 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -413,26 +413,28 @@ class HTTPSignature */ public static function fetchRaw($request, $uid = 0, $binary = false, $opts = []) { + $headers = []; + if (!empty($uid)) { $owner = User::getOwnerDataById($uid); if (!$owner) { return; } - // Header data that is about to be signed. - $host = parse_url($request, PHP_URL_HOST); - $path = parse_url($request, PHP_URL_PATH); - $date = DateTimeFormat::utcNow(DateTimeFormat::HTTP); + if (!empty($owner['uprvkey'])) { + // Header data that is about to be signed. + $host = parse_url($request, PHP_URL_HOST); + $path = parse_url($request, PHP_URL_PATH); + $date = DateTimeFormat::utcNow(DateTimeFormat::HTTP); - $headers = ['Date: ' . $date, 'Host: ' . $host]; + $headers = ['Date: ' . $date, 'Host: ' . $host]; - $signed_data = "(request-target): get " . $path . "\ndate: ". $date . "\nhost: " . $host; + $signed_data = "(request-target): get " . $path . "\ndate: ". $date . "\nhost: " . $host; - $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256')); + $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256')); - $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date host",signature="' . $signature . '"'; - } else { - $headers = []; + $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date host",signature="' . $signature . '"'; + } } if (!empty($opts['accept_content'])) { -- 2.39.5