]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7245 from annando/unify-constants
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 10 Jun 2019 15:59:40 +0000 (11:59 -0400)
committerGitHub <noreply@github.com>
Mon, 10 Jun 2019 15:59:40 +0000 (11:59 -0400)
Fix delivery counter for poking / unify delivery commands

23 files changed:
composer.json
composer.lock
mod/dfrn_confirm.php
mod/parse_url.php
src/Content/OEmbed.php
src/Core/Config/Cache/ConfigCache.php
src/Core/Config/Configuration.php
src/Core/Search.php
src/Core/Worker.php
src/Factory/DBFactory.php
src/Model/APContact.php
src/Model/Contact.php
src/Module/Magic.php
src/Network/Probe.php
src/Object/Image.php
src/Protocol/ActivityPub.php
src/Protocol/DFRN.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/HTTPSignature.php
src/Util/Network.php
src/Worker/OnePoll.php
tests/src/Core/Config/Cache/ConfigCacheTest.php

index a8b4a20d28fc4463c1c677cef0bae3a60cfe463f..aac5c10bc6e3fa88582ab7563b8661f62cefac33 100644 (file)
@@ -37,6 +37,7 @@
                "mobiledetect/mobiledetectlib": "2.8.*",
                "monolog/monolog": "^1.24",
                "nikic/fast-route": "^1.3",
+               "paragonie/hidden-string": "^1.0",
                "pear/text_languagedetect": "1.*",
                "pragmarx/google2fa": "^5.0",
                "pragmarx/recovery": "^0.1.0",
index 75c10b78f026eaea9b8c83d3a73c828ff90932e7..af51b6dfe7ef7c9ca4ba2de0e4cad4ea3501ae96 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "67821d2270bdf8cdd24e7a047b9544e7",
+    "content-hash": "eb985236d64ed0b0fe1fc2e4ac6616e2",
     "packages": [
         {
             "name": "asika/simple-console",
         },
         {
             "name": "paragonie/constant_time_encoding",
-            "version": "v1.0.4",
+            "version": "v2.2.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/paragonie/constant_time_encoding.git",
-                "reference": "2132f0f293d856026d7d11bd81b9f4a23a1dc1f6"
+                "reference": "55af0dc01992b4d0da7f6372e2eac097bbbaffdb"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/2132f0f293d856026d7d11bd81b9f4a23a1dc1f6",
-                "reference": "2132f0f293d856026d7d11bd81b9f4a23a1dc1f6",
+                "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/55af0dc01992b4d0da7f6372e2eac097bbbaffdb",
+                "reference": "55af0dc01992b4d0da7f6372e2eac097bbbaffdb",
                 "shasum": ""
             },
             "require": {
-                "php": "^5.3|^7"
+                "php": "^7"
             },
             "require-dev": {
-                "paragonie/random_compat": "^1.4|^2",
-                "phpunit/phpunit": "4.*|5.*",
-                "vimeo/psalm": "^0.3|^1"
+                "phpunit/phpunit": "^6|^7",
+                "vimeo/psalm": "^1|^2"
             },
             "type": "library",
             "autoload": {
                 "hex2bin",
                 "rfc4648"
             ],
-            "time": "2018-04-30T17:57:16+00:00"
+            "time": "2019-01-03T20:26:31+00:00"
+        },
+        {
+            "name": "paragonie/hidden-string",
+            "version": "v1.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/paragonie/hidden-string.git",
+                "reference": "0bbb00be0e33b8e1d48fa79ea35cd42d3091a936"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/paragonie/hidden-string/zipball/0bbb00be0e33b8e1d48fa79ea35cd42d3091a936",
+                "reference": "0bbb00be0e33b8e1d48fa79ea35cd42d3091a936",
+                "shasum": ""
+            },
+            "require": {
+                "paragonie/constant_time_encoding": "^2",
+                "paragonie/sodium_compat": "^1.6",
+                "php": "^7"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^6|^7",
+                "vimeo/psalm": "^1"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "ParagonIE\\HiddenString\\": "./src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MPL-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "Paragon Initiative Enterprises",
+                    "email": "info@paragonie.com",
+                    "homepage": "https://paragonie.com"
+                }
+            ],
+            "description": "Encapsulate strings in an object to hide them from stack traces",
+            "homepage": "https://github.com/paragonie/hidden-string",
+            "keywords": [
+                "hidden",
+                "stack trace",
+                "string"
+            ],
+            "time": "2018-05-07T20:28:06+00:00"
         },
         {
             "name": "paragonie/random_compat",
             "version": "v1.6.5",
             "source": {
                 "type": "git",
-                "url": "https://github.com/mikey179/vfsStream.git",
+                "url": "https://github.com/bovigo/vfsStream.git",
                 "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
+                "url": "https://api.github.com/repos/bovigo/vfsStream/zipball/d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
                 "reference": "d5fec95f541d4d71c4823bb5e30cf9b9e5b96145",
                 "shasum": ""
             },
                 }
             ],
             "description": "Provides the functionality to compare PHP values for equality",
-            "homepage": "http://www.github.com/sebastianbergmann/comparator",
+            "homepage": "https://github.com/sebastianbergmann/comparator",
             "keywords": [
                 "comparator",
                 "compare",
                 }
             ],
             "description": "Provides functionality to handle HHVM/PHP environments",
-            "homepage": "http://www.github.com/sebastianbergmann/environment",
+            "homepage": "https://github.com/sebastianbergmann/environment",
             "keywords": [
                 "Xdebug",
                 "environment",
                 }
             ],
             "description": "Provides the functionality to export PHP variables for visualization",
-            "homepage": "http://www.github.com/sebastianbergmann/exporter",
+            "homepage": "https://github.com/sebastianbergmann/exporter",
             "keywords": [
                 "export",
                 "exporter"
                 }
             ],
             "description": "Snapshotting of global state",
-            "homepage": "http://www.github.com/sebastianbergmann/global-state",
+            "homepage": "https://github.com/sebastianbergmann/global-state",
             "keywords": [
                 "global state"
             ],
                 }
             ],
             "description": "Provides functionality to recursively process PHP variables",
-            "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
+            "homepage": "https://github.com/sebastianbergmann/recursion-context",
             "time": "2016-11-19T07:33:16+00:00"
         },
         {
                 },
                 {
                     "name": "Gert de Pagter",
-                    "email": "backendtea@gmail.com"
+                    "email": "BackEndTea@gmail.com"
                 }
             ],
             "description": "Symfony polyfill for ctype functions",
index 7b1171ba41b9a5571ae6f7ddc4e94271fcf05efc..7da872f0d06a68aeeaf0e29b29cfee84d1e6444e 100644 (file)
@@ -209,7 +209,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                 *
                 */
 
-               $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
+               $res = Network::post($dfrn_confirm, $params, null, 120)->getBody();
 
                Logger::log(' Confirm: received data: ' . $res, Logger::DATA);
 
index 7631a5a710b62d07d0f349b2b3b17914debb81a6..6b393932ebc8aa73e176670d6889329a70320fb7 100644 (file)
@@ -70,9 +70,8 @@ function parse_url_content(App $a)
 
        // Check if the URL is an image, video or audio file. If so format
        // the URL with the corresponding BBCode media tag
-       $redirects = 0;
        // Fetch the header of the URL
-       $curlResponse = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]);
+       $curlResponse = Network::curl($url, false, ['novalidate' => true, 'nobody' => true]);
 
        if ($curlResponse->isSuccess()) {
                // Convert the header fields into an array
index 7190f1ce0ed39cc8b8433b1497947074e566cd6e..94e95e5f51d234e04b3be242159c4b68cc894158 100644 (file)
@@ -83,8 +83,7 @@ class OEmbed
 
                        if (!in_array($ext, $noexts)) {
                                // try oembed autodiscovery
-                               $redirects = 0;
-                               $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, 'text/*');
+                               $html_text = Network::fetchUrl($embedurl, false, 15, 'text/*');
                                if ($html_text) {
                                        $dom = @DOMDocument::loadHTML($html_text);
                                        if ($dom) {
index 3314e184f3519cf5f4a7ee388e37da8ce949fc41..441cdee811cc550c3e0bb748c8fdb26887b0dc59 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Friendica\Core\Config\Cache;
 
+use ParagonIE\HiddenString\HiddenString;
+
 /**
  * The Friendica config cache for the application
  * Initial, all *.config.php files are loaded into this cache with the
@@ -14,11 +16,18 @@ class ConfigCache implements IConfigCache, IPConfigCache
         */
        private $config;
 
+       /**
+        * @var bool
+        */
+       private $hidePasswordOutput;
+
        /**
         * @param array $config    A initial config array
+        * @param bool  $hidePasswordOutput True, if cache variables should take extra care of password values
         */
-       public function __construct(array $config = [])
+       public function __construct(array $config = [], $hidePasswordOutput = true)
        {
+               $this->hidePasswordOutput = $hidePasswordOutput;
                $this->load($config);
        }
 
@@ -84,8 +93,13 @@ class ConfigCache implements IConfigCache, IPConfigCache
                        $this->config[$cat] = [];
                }
 
-               $this->config[$cat][$key] = $value;
-
+               if ($this->hidePasswordOutput &&
+                   $key == 'password' &&
+                   !empty($value) && is_string($value)) {
+                       $this->config[$cat][$key] = new HiddenString((string) $value);
+               } else {
+                       $this->config[$cat][$key] = $value;
+               }
                return true;
        }
 
index 532ed982a9d46498d3de738e741f58db33b26cbc..18191d0429c45bfd2fb5fc9f860fb71eaca2b008 100644 (file)
@@ -88,7 +88,7 @@ class Configuration
 
                        if (isset($dbvalue)) {
                                $this->configCache->set($cat, $key, $dbvalue);
-                               return $dbvalue;
+                               unset($dbvalue);
                        }
                }
 
index 48231f08247a94c1206e8c8f62a774dbc8253f53..e26cc0edc3a55792b682ad397cac11e4d87fafb7 100644 (file)
@@ -107,8 +107,7 @@ class Search extends BaseObject
                        $searchUrl .= '&page=' . $page;
                }
 
-               $red        = 0;
-               $resultJson = Network::fetchUrl($searchUrl, false, $red, 0, 'application/json');
+               $resultJson = Network::fetchUrl($searchUrl, false, 0, 'application/json');
 
                $results = json_decode($resultJson, true);
 
index d7e5479267b4b87589084046ed10bfd48f266390..8fdd60c2a74db95549ec4d3766b631b3f1020358 100644 (file)
@@ -983,7 +983,7 @@ class Worker
                }
 
                $url = System::baseUrl()."/worker";
-               Network::fetchUrl($url, false, $redirects, 1);
+               Network::fetchUrl($url, false, 1);
        }
 
        /**
index 1c01f733192d6604940415c77b7ddf394d358e22..7caa63ec46755d8e74abdb11736fc9d784be9171 100644 (file)
@@ -6,6 +6,7 @@ use Friendica\Core\Config\Cache;
 use Friendica\Database;
 use Friendica\Util\Logger\VoidLogger;
 use Friendica\Util\Profiler;
+use ParagonIE\HiddenString\HiddenString;
 
 class DBFactory
 {
@@ -45,7 +46,7 @@ class DBFactory
                        } else {
                                $db_user = $server['MYSQL_USER'];
                        }
-                       $db_pass = (string) $server['MYSQL_PASSWORD'];
+                       $db_pass = new HiddenString((string) $server['MYSQL_PASSWORD']);
                        $db_data = $server['MYSQL_DATABASE'];
                }
 
index cf1f9b72313c44baee97083b4b91a3b76255017e..67c714f9afd29d00a211295a0ec5f78c0a0a6838 100644 (file)
@@ -34,7 +34,7 @@ class APContact extends BaseObject
 
                $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
 
-               $curlResult = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']);
+               $curlResult = Network::curl($webfinger, false, ['accept_content' => 'application/jrd+json,application/json']);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
                        return false;
                }
index a0bbdd10499f43abbf6138d976c7a145e6d66402..7e1d8c2ba5d9a174534df794fd619ff454dcb4d4 100644 (file)
@@ -2157,7 +2157,8 @@ class Contact extends BaseObject
 
                if (!empty($contact)) {
             // Contact is blocked at user-level
-                   if (self::isBlockedByUser($contact['id'], $importer['id'])) {
+                   if (!empty($contact['id']) && !empty($importer['id']) &&
+                       self::isBlockedByUser($contact['id'], $importer['id'])) {
                        return false;
             }
 
index 491ed31cbd4a4bd0c24036ea45a398325d078251..441fe7f157a33c61609744422dd94385a2cbb3ae 100644 (file)
@@ -85,7 +85,7 @@ class Magic extends BaseModule
                                );
 
                                // Try to get an authentication token from the other instance.
-                               $curlResult = Network::curl($basepath . '/owa', false, $redirects, ['headers' => $headers]);
+                               $curlResult = Network::curl($basepath . '/owa', false, ['headers' => $headers]);
 
                                if ($curlResult->isSuccess()) {
                                        $j = json_decode($curlResult->getBody(), true);
index b0d2630103beaed42328d4aa61cee75a08a3d57f..00c38a4c12c16b383234beb6583bcea71c532c80 100644 (file)
@@ -109,12 +109,11 @@ class Probe
                $url = "http://".$host."/.well-known/host-meta";
 
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
-               $redirects = 0;
 
                Logger::log("Probing for ".$host, Logger::DEBUG);
                $xrd = null;
 
-               $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+               $curlResult = Network::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                if ($curlResult->isSuccess()) {
                        $xml = $curlResult->getBody();
                        $xrd = XML::parseString($xml, false);
@@ -122,7 +121,7 @@ class Probe
                }
 
                if (!is_object($xrd)) {
-                       $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+                       $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                        if ($curlResult->isTimeout()) {
                                Logger::log("Probing timeout for " . $url, Logger::DEBUG);
                                self::$istimeout = true;
@@ -738,9 +737,8 @@ class Probe
        private static function webfinger($url, $type)
        {
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
-               $redirects = 0;
 
-               $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
+               $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
                if ($curlResult->isTimeout()) {
                        self::$istimeout = true;
                        return false;
index 67413e3c0d1e7c5f13d7ae07287f4827ad9c4973..803aa08b38f58b7e28da83ce0506769aea38f766 100644 (file)
@@ -781,7 +781,7 @@ class Image
                $data = Cache::get($url);
 
                if (is_null($data) || !$data || !is_array($data)) {
-                       $img_str = Network::fetchUrl($url, true, $redirects, 4);
+                       $img_str = Network::fetchUrl($url, true, 4);
 
                        if (!$img_str) {
                                return false;
index fa63c44d574bcb9b8f2f6af54707f3cd721f6229..8caf7ac64c97bb8bd88510d8a93f414a03459030 100644 (file)
@@ -74,7 +74,7 @@ class ActivityPub
                        return HTTPSignature::fetch($url, $uid);
                }
 
-               $curlResult = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']);
+               $curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
                        return false;
                }
index fe2a608ec6fd0358fd94757e08ae0f6e471dfe81..ec4557e8221a70f833b090d2da98f32f8cb78b2b 100644 (file)
@@ -2216,11 +2216,10 @@ class DFRN
        {
                Logger::log("Process verb ".$item["verb"]." and object-type ".$item["object-type"]." for entrytype ".$entrytype, Logger::DEBUG);
 
-               if (($entrytype == DFRN::TOP_LEVEL)) {
+               if (($entrytype == DFRN::TOP_LEVEL) && !empty($importer['id'])) {
                        // The filling of the the "contact" variable is done for legcy reasons
                        // The functions below are partly used by ostatus.php as well - where we have this variable
-                       $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($importer["id"]));
-                       $contact = $r[0];
+                       $contact = Contact::select([], ['id' => $importer['id']]);
 
                        // Big question: Do we need these functions? They were part of the "consume_feed" function.
                        // This function once was responsible for DFRN and OStatus.
index 81e5c19db8cc42d73eaf2c5e7adc2f2f74c2cb53..9fa0ff43af73e9120122178142dba54257ee03e4 100644 (file)
@@ -738,7 +738,7 @@ class OStatus
 
                self::$conv_list[$conversation] = true;
 
-               $curlResult = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
@@ -931,7 +931,7 @@ class OStatus
                }
 
                $stored = false;
-               $curlResult = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
index 5345cb22fce2ae182c6f155ab93e518138c08790..60bb844226038c951a01d50f8709e363c2fbc0e7 100644 (file)
@@ -1004,7 +1004,7 @@ class PortableContact
                $server_url = str_replace("http://", "https://", $server_url);
 
                // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
-               $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+               $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
 
                // Quit if there is a timeout.
                // But we want to make sure to only quit if we are mostly sure that this server url fits.
@@ -1021,7 +1021,7 @@ class PortableContact
                        $server_url = str_replace("https://", "http://", $server_url);
 
                        // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
-                       $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+                       $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
 
                        // Quit if there is a timeout
                        if ($curlResult->isTimeout()) {
@@ -1624,7 +1624,7 @@ class PortableContact
                        if (!empty($accesstoken)) {
                                $api = 'https://instances.social/api/1.0/instances/list?count=0';
                                $header = ['Authorization: Bearer '.$accesstoken];
-                               $curlResult = Network::curl($api, false, $redirects, ['headers' => $header]);
+                               $curlResult = Network::curl($api, false, ['headers' => $header]);
 
                                if ($curlResult->isSuccess()) {
                                        $servers = json_decode($curlResult->getBody(), true);
index e002d5981cb54f3b78961adc05057df49db0328d..8a058c3b5c7e45d15bd4737daf29dc41b76b5890 100644 (file)
@@ -455,7 +455,7 @@ class HTTPSignature
                $curl_opts = $opts;
                $curl_opts['header'] = $headers;
 
-               $curlResult = Network::curl($request, false, $redirects, $curl_opts);
+               $curlResult = Network::curl($request, false, $curl_opts);
                $return_code = $curlResult->getReturnCode();
 
                Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG);
index e4e9c5af5bb5a75673017425b6cc298057fa74ac..b1d072d7e93a906a5190b2847e2813200c0ec9ba 100644 (file)
@@ -23,19 +23,19 @@ class Network
         *
         * @brief Curl wrapper
         * @param string  $url            URL to fetch
-        * @param boolean $binary         default false
+        * @param bool    $binary         default false
         *                                TRUE if asked to return binary results (file download)
-        * @param integer $redirects      The recursion counter for internal use - default 0
-        * @param integer $timeout        Timeout in seconds, default system config value or 60 seconds
+        * @param int     $timeout        Timeout in seconds, default system config value or 60 seconds
         * @param string  $accept_content supply Accept: header with 'accept_content' as the value
         * @param string  $cookiejar      Path to cookie jar file
+        * @param int     $redirects      The recursion counter for internal use - default 0
         *
         * @return string The fetched content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = '')
+       public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
        {
-               $ret = self::fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar);
+               $ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects);
 
                return $ret->getBody();
        }
@@ -48,26 +48,27 @@ class Network
         *
         * @brief Curl wrapper with array of return values.
         * @param string  $url            URL to fetch
-        * @param boolean $binary         default false
+        * @param bool    $binary         default false
         *                                TRUE if asked to return binary results (file download)
-        * @param integer $redirects      The recursion counter for internal use - default 0
-        * @param integer $timeout        Timeout in seconds, default system config value or 60 seconds
+        * @param int     $timeout        Timeout in seconds, default system config value or 60 seconds
         * @param string  $accept_content supply Accept: header with 'accept_content' as the value
         * @param string  $cookiejar      Path to cookie jar file
+        * @param int     $redirects      The recursion counter for internal use - default 0
         *
         * @return CurlResult With all relevant information, 'body' contains the actual fetched content.
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchUrlFull($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = '')
+       public static function fetchUrlFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
        {
                return self::curl(
                        $url,
                        $binary,
-                       $redirects,
-                       ['timeout'=>$timeout,
-                       'accept_content'=>$accept_content,
-                       'cookiejar'=>$cookiejar
-                       ]
+                       [
+                               'timeout'        => $timeout,
+                               'accept_content' => $accept_content,
+                               'cookiejar'      => $cookiejar
+                       ],
+                       $redirects
                );
        }
 
@@ -75,9 +76,8 @@ class Network
         * @brief fetches an URL.
         *
         * @param string  $url       URL to fetch
-        * @param boolean $binary    default false
+        * @param bool    $binary    default false
         *                           TRUE if asked to return binary results (file download)
-        * @param int     $redirects The recursion counter for internal use - default 0
         * @param array   $opts      (optional parameters) assoziative array with:
         *                           'accept_content' => supply Accept: header with 'accept_content' as the value
         *                           'timeout' => int Timeout in seconds, default system config value or 60 seconds
@@ -86,11 +86,12 @@ class Network
         *                           'nobody' => only return the header
         *                           'cookiejar' => path to cookie jar file
         *                           'header' => header array
+        * @param int     $redirects The recursion counter for internal use - default 0
         *
         * @return CurlResult
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function curl($url, $binary = false, &$redirects = 0, $opts = [])
+       public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
        {
                $stamp1 = microtime(true);
 
@@ -227,7 +228,7 @@ class Network
                        $redirects++;
                        Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
                        @curl_close($ch);
-                       return self::curl($curlResponse->getRedirectUrl(), $binary, $redirects, $opts);
+                       return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects);
                }
 
                @curl_close($ch);
@@ -243,13 +244,13 @@ class Network
         * @param string  $url       URL to post
         * @param mixed   $params    array of POST variables
         * @param string  $headers   HTTP headers
-        * @param integer $redirects Recursion counter for internal use - default = 0
-        * @param integer $timeout   The timeout in seconds, default system config value or 60 seconds
+        * @param int     $redirects Recursion counter for internal use - default = 0
+        * @param int     $timeout   The timeout in seconds, default system config value or 60 seconds
         *
         * @return CurlResult The content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function post($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
+       public static function post(string $url, $params, string $headers = null, int $timeout = 0, int &$redirects = 0)
        {
                $stamp1 = microtime(true);
 
@@ -351,7 +352,7 @@ class Network
         * @return string|boolean The actual working URL, false else
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isUrlValid($url)
+       public static function isUrlValid(string $url)
        {
                if (Config::get('system', 'disable_url_validation')) {
                        return $url;
@@ -381,9 +382,8 @@ class Network
         *
         * @param string $addr The email address
         * @return boolean True if it's a valid email address, false if it's not
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isEmailDomainValid($addr)
+       public static function isEmailDomainValid(string $addr)
        {
                if (Config::get('system', 'disable_email_validation')) {
                        return true;
@@ -413,9 +413,8 @@ class Network
         *
         * @param string $url URL which get tested
         * @return boolean True if url is allowed otherwise return false
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isUrlAllowed($url)
+       public static function isUrlAllowed(string $url)
        {
                $h = @parse_url($url);
 
@@ -460,7 +459,7 @@ class Network
         *
         * @return boolean
         */
-       public static function isUrlBlocked($url)
+       public static function isUrlBlocked(string $url)
        {
                $host = @parse_url($url, PHP_URL_HOST);
                if (!$host) {
@@ -491,7 +490,7 @@ class Network
         *                       or if allowed list is not configured
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function isEmailDomainAllowed($email)
+       public static function isEmailDomainAllowed(string $email)
        {
                $domain = strtolower(substr($email, strpos($email, '@') + 1));
                if (!$domain) {
@@ -516,7 +515,7 @@ class Network
         * @param array  $domain_list
         * @return boolean
         */
-       public static function isDomainAllowed($domain, array $domain_list)
+       public static function isDomainAllowed(string $domain, array $domain_list)
        {
                $found = false;
 
@@ -531,7 +530,7 @@ class Network
                return $found;
        }
 
-       public static function lookupAvatarByEmail($email)
+       public static function lookupAvatarByEmail(string $email)
        {
                $avatar['size'] = 300;
                $avatar['email'] = $email;
@@ -554,7 +553,7 @@ class Network
         * @param string $url Any user-submitted URL that may contain tracking params
         * @return string The same URL stripped of tracking parameters
         */
-       public static function stripTrackingQueryParams($url)
+       public static function stripTrackingQueryParams(string $url)
        {
                $urldata = parse_url($url);
                if (!empty($urldata["query"])) {
@@ -613,7 +612,7 @@ class Network
         * @return string A canonical URL
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function finalUrl($url, $depth = 1, $fetchbody = false)
+       public static function finalUrl(string $url, int $depth = 1, bool $fetchbody = false)
        {
                $a = \get_app();
 
@@ -724,7 +723,7 @@ class Network
         * @param string $url2
         * @return string The matching part
         */
-       public static function getUrlMatch($url1, $url2)
+       public static function getUrlMatch(string $url1, string $url2)
        {
                if (($url1 == "") || ($url2 == "")) {
                        return "";
@@ -812,7 +811,7 @@ class Network
         *
         * @return string The glued URL
         */
-       public static function unparseURL($parsed)
+       public static function unparseURL(array $parsed)
        {
                $get = function ($key) use ($parsed) {
                        return isset($parsed[$key]) ? $parsed[$key] : null;
@@ -844,7 +843,7 @@ class Network
         *
         * @return string switched URL
         */
-       public static function switchScheme($url)
+       public static function switchScheme(string $url)
        {
                $scheme = parse_url($url, PHP_URL_SCHEME);
                if (empty($scheme)) {
index 8f494af53a9afc4130251c0603f06bb9dc52d0ff..a605ee92ed593b4bde77e8b3b4a68da4eccfcd36 100644 (file)
@@ -371,7 +371,7 @@ class OnePoll
                        }
 
                        $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
-                       $curlResult = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]);
+                       $curlResult = Network::curl($contact['poll'], false, ['cookiejar' => $cookiejar]);
                        unlink($cookiejar);
 
                        if ($curlResult->isTimeout()) {
index e6ac8255e9f7b3b454aced052381a62e71a44c04..f8f81f9ee721c8193bfbe656d3ad9279efb2bdbf 100644 (file)
@@ -275,4 +275,77 @@ class ConfigCacheTest extends MockedTest
 
                $this->assertEmpty($configCache->keyDiff($diffConfig));
        }
+
+       /**
+        * Test the default hiding of passwords inside the cache
+        */
+       public function testPasswordHide()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ],
+               ]);
+
+               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
+               $this->assertNotEquals('supersecure', print_r($configCache->get('database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
+       }
+
+       /**
+        * Test disabling the hiding of passwords inside the cache
+        */
+       public function testPasswordShow()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ],
+               ], false);
+
+               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
+               $this->assertEquals('supersecure', print_r($configCache->get('database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
+       }
+
+       /**
+        * Test a empty password
+        */
+       public function testEmptyPassword()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => '',
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertEmpty($configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+       }
+
+       public function testWrongTypePassword()
+       {
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => new \stdClass(),
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertNotEmpty($configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+
+               $configCache = new ConfigCache([
+                       'database' => [
+                               'password' => 23,
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertEquals(23, $configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+       }
 }