* [MOD] Deprecate PHP versions below 7.2 since they are no longer supported by PHP and Travis CI tests are not performed for them. https://www.php.net/supported-versions.php

* [MOD] Improve internal config handling. No more properties visibility tweaks.
* [MOD] Updated dependencies.

Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
Rubén D
2020-12-07 19:37:00 +01:00
parent ad90b707bf
commit 896d9fd3ad
20 changed files with 1640 additions and 953 deletions

View File

@@ -1,14 +1,13 @@
dist: xenial
dist: bionic
language: php
sudo: false
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
branches:
only:

View File

@@ -63,7 +63,7 @@ final class BootstrapController extends SimpleControllerBase
'app_root' => Bootstrap::$WEBURI,
'max_file_size' => $this->configData->getFilesAllowedSize(),
'check_updates' => $checkStatus && $this->configData->isCheckUpdates(),
'check_notices' => $checkStatus && $this->configData->isChecknotices(),
'check_notices' => $checkStatus && $this->configData->isCheckNotices(),
'check_notifications' => $this->getNotificationsEnabled(),
'timezone' => date_default_timezone_get(),
'debug' => DEBUG || $this->configData->isDebug(),

View File

@@ -198,7 +198,7 @@ use SP\Mvc\View\Template;
for="check_notices_enabled">
<input type="checkbox" id="check_notices_enabled"
class="mdl-switch__input"
name="check_notices_enabled" <?php echo $configData->isChecknotices() ? 'checked' : ''; ?>/>
name="check_notices_enabled" <?php echo $configData->isCheckNotices() ? 'checked' : ''; ?>/>
</label>
</div>

View File

@@ -19,7 +19,7 @@
},
"require": {
"roave/security-advisories": "dev-master",
"php": "~7.0 || ~7.1 || ~7.2 || ~7.3",
"php": "~7.2 || ~7.3 || ~7.4",
"defuse/php-encryption": "^2.1",
"phpmailer/phpmailer": "^6.0",
"ademarre/binary-to-text-php": "dev-master",

1714
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -150,7 +150,7 @@ final class Config
/**
* @return bool
*/
private function isCacheExpired()
private function isCacheExpired(): bool
{
try {
return $this->fileCache->isExpiredDate($this->fileStorage->getFileHandler()->getFileTime());
@@ -165,7 +165,7 @@ final class Config
* @return ConfigData
* @throws FileException
*/
public function loadConfigFromFile()
public function loadConfigFromFile(): ConfigData
{
return $this->configMapper($this->fileStorage->load('config')->getItems());
}
@@ -177,7 +177,7 @@ final class Config
*
* @return ConfigData
*/
private function configMapper(array $items)
private function configMapper(array $items): ConfigData
{
$configData = new ConfigData();
@@ -202,7 +202,7 @@ final class Config
* @return Config
* @throws FileException
*/
public function saveConfig(ConfigData $configData, $backup = true)
public function saveConfig(ConfigData $configData, $backup = true): Config
{
if ($backup) {
$this->dic->get(ConfigBackupService::class)
@@ -226,7 +226,7 @@ final class Config
/**
* @return int
*/
public static function getTimeUpdated()
public static function getTimeUpdated(): int
{
return self::$timeUpdated;
}
@@ -238,7 +238,7 @@ final class Config
*
* @return Config
*/
public function updateConfig(ConfigData $configData)
public function updateConfig(ConfigData $configData): Config
{
$configData->setConfigDate(time());
$configData->setConfigSaver($this->context->getUserData()->getLogin());
@@ -258,7 +258,7 @@ final class Config
*
* @return ConfigData
*/
public function loadConfig($reload = false)
public function loadConfig($reload = false): ConfigData
{
try {
$configData = $this->fileCache->load();
@@ -284,7 +284,7 @@ final class Config
/**
* @return ConfigData
*/
public function getConfigData()
public function getConfigData(): ConfigData
{
return clone $this->configData;
}
@@ -294,7 +294,7 @@ final class Config
* @throws FileException
* @throws EnvironmentIsBrokenException
*/
public function generateUpgradeKey()
public function generateUpgradeKey(): Config
{
if (empty($this->configData->getUpgradeKey())) {
logger('Generating upgrade key');

File diff suppressed because it is too large Load Diff

View File

@@ -63,7 +63,7 @@ final class ConfigUtil
*
* @return array
*/
public static function mailAddressesAdapter($mailAddresses)
public static function mailAddressesAdapter(string $mailAddresses): array
{
if (empty($mailAddresses)) {
return [];

View File

@@ -293,7 +293,7 @@ final class Request
*
* @return array|null
*/
public function analyzeArray(string $param, callable $mapper = null, $default = null)
public function analyzeArray(string $param, callable $mapper = null, $default = null): ?array
{
$requestValue = $this->params->get($param);
@@ -334,12 +334,12 @@ final class Request
}
/**
* @param string $param
* @param int $default
* @param string $param
* @param int|null $default
*
* @return int
*/
public function analyzeInt(string $param, int $default = null)
public function analyzeInt(string $param, int $default = null): ?int
{
if (!$this->params->exists($param)) {
return $default;
@@ -364,7 +364,7 @@ final class Request
*
* @return bool
*/
public function analyzeBool(string $param, bool $default = null)
public function analyzeBool(string $param, bool $default = null): bool
{
if (!$this->params->exists($param)) {
return (bool)$default;

View File

@@ -281,7 +281,7 @@ final class LdapParams
/**
* @return int
*/
public function getType()
public function getType(): int
{
return $this->type;
}

View File

@@ -54,6 +54,8 @@ defined('APP_ROOT') || die();
*/
final class FileBackupService extends Service
{
private const BACKUP_EXCLUDE_REGEX = '#^(?!.*(backup|cache|temp|vendor|tests))(.*)$#i';
/**
* @var ConfigData
*/
@@ -351,7 +353,7 @@ final class FileBackupService extends Service
* @throws CheckException
* @throws FileException
*/
private function backupApp()
private function backupApp(): bool
{
$this->eventDispatcher->notifyEvent('run.backup.process',
new Event($this, EventMessage::factory()
@@ -359,7 +361,8 @@ final class FileBackupService extends Service
);
$archive = new ArchiveHandler($this->backupFileApp, $this->extensionChecker);
$archive->compressDirectory(APP_ROOT, '#^(?!(.*backup))(.*)$#i');
$archive->compressDirectory(APP_ROOT, self::BACKUP_EXCLUDE_REGEX);
return true;
}

View File

@@ -75,7 +75,7 @@ final class XmlHandler implements XmlFileStorageInterface
* @throws FileException
* @throws RuntimeException
*/
public function load($node = 'root')
public function load($node = 'root'): XmlFileStorageInterface
{
$this->fileHandler->checkIsReadable();
$this->fileHandler->getFileSize(true);
@@ -110,7 +110,7 @@ final class XmlHandler implements XmlFileStorageInterface
*
* @return array
*/
protected function readChildNodes(DOMNodeList $nodeList)
protected function readChildNodes(DOMNodeList $nodeList): array
{
$nodes = [];
@@ -132,9 +132,14 @@ final class XmlHandler implements XmlFileStorageInterface
$nodes[$node->nodeName] = $this->readChildNodes($node->childNodes);
}
} else {
$val = is_numeric($node->nodeValue)
&& strpos($node->nodeValue, '.') === false
? (int)$node->nodeValue : $node->nodeValue;
$val = null;
if (is_numeric($node->nodeValue)
&& strpos($node->nodeValue, '.') === false) {
$val = (int)$node->nodeValue;
} else if (!empty($node->nodeValue)) {
$val = $node->nodeValue;
}
if ($node->nodeName === 'item') {
$nodes[] = $val;
@@ -170,7 +175,7 @@ final class XmlHandler implements XmlFileStorageInterface
* @throws FileException
* @throws RuntimeException
*/
public function save($data, $node = 'root')
public function save($data, $node = 'root'): XmlFileStorageInterface
{
$this->fileHandler->checkIsWritable();

View File

@@ -48,7 +48,7 @@ final class Checks
*/
public static function checkPhpVersion()
{
return version_compare(PHP_VERSION, '7.0', '>=')
&& version_compare(PHP_VERSION, '7.4', '<');
return version_compare(PHP_VERSION, '7.2', '>=')
&& version_compare(PHP_VERSION, '7.4', '<=');
}
}

View File

@@ -120,7 +120,7 @@ final class Util
* @author Samuel Levy <sam+nospam@samuellevy.com>
*
*/
public static function boolval($in, $strict = false)
public static function boolval($in, $strict = false): bool
{
$in = is_string($in) ? strtolower($in) : $in;

View File

@@ -83,7 +83,7 @@ class ConfigTest extends TestCase
* @throws DependencyException
* @throws NotFoundException
*/
public function testLoadClass()
public function testLoadClass(): Config
{
$config = self::$dic->get(Config::class);
@@ -102,7 +102,7 @@ class ConfigTest extends TestCase
*
* @throws FileException
*/
public function testSaveConfig($config)
public function testSaveConfig(Config $config)
{
$config->saveConfig($config->getConfigData(), false);
@@ -116,9 +116,8 @@ class ConfigTest extends TestCase
* @depends testLoadClass
*
* @param Config $config
*
*/
public function testLoadConfig($config)
public function testLoadConfig(Config $config)
{
$this->assertInstanceOf(ConfigData::class, $config->loadConfig());
}
@@ -130,7 +129,7 @@ class ConfigTest extends TestCase
*
* @param Config $config
*/
public function testUpdateConfig($config)
public function testUpdateConfig(Config $config)
{
$config->updateConfig($config->getConfigData());
@@ -147,7 +146,7 @@ class ConfigTest extends TestCase
* @throws EnvironmentIsBrokenException
* @throws FileException
*/
public function testGenerateUpgradeKey($config)
public function testGenerateUpgradeKey(Config $config)
{
$config->generateUpgradeKey();

View File

@@ -101,8 +101,10 @@ class ConfigBackupServiceTest extends TestCase
$this->assertEquals($configData->getConfigVersion(), $data->getConfigVersion());
$config = $dic->get(Config::class);
$this->assertEquals($data->getConfigHash(), $config->loadConfigFromFile()->getConfigHash());
$config = $dic->get(Config::class)->loadConfigFromFile();
$this->assertEquals($config->getConfigVersion(), $data->getConfigVersion());
$this->assertGreaterThanOrEqual($config->getConfigDate(), $data->getConfigDate());
}
}

View File

@@ -28,6 +28,7 @@ use DI\Container;
use DI\DependencyException;
use DI\NotFoundException;
use SP\Core\Context\ContextException;
use SP\Core\Exceptions\SPException;
use SP\Services\Import\FileImport;
use SP\Services\Import\ImportException;
use SP\Services\Import\ImportParams;
@@ -68,6 +69,7 @@ class XmlImportTest extends DatabaseTestCase
/**
* @throws ImportException
* @throws FileException
* @throws SPException
*/
public function testDoImport()
{

View File

@@ -123,6 +123,8 @@ function setupContext()
$userData = new UserLoginResponse();
$userData->setId(1);
$userData->setLogin('Admin');
$userData->setUserGroupName('Admins');
$userData->setUserGroupId(1);
$userData->setIsAdminApp(1);
$userData->setLastUpdate(time());

View File

@@ -1,9 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<attributes>
<configDate>1584025638</configDate>
<configHash>501c9ad829417b77a3168bab78003294422f74ee</configHash>
<configSaver>sysPass</configSaver>
<export_hash>321933b882ccd226f99b1fee8c247740afa6b578</export_hash>
</attributes>
<accountCount>12</accountCount>
<accountExpireEnabled></accountExpireEnabled>
<accountExpireTime>10368000</accountExpireTime>
<accountFullGroupAccess></accountFullGroupAccess>
<accountLink>1</accountLink>
<accountPassToImage></accountPassToImage>
<appVersion></appVersion>
<applicationUrl></applicationUrl>
<authBasicAutoLoginEnabled>1</authBasicAutoLoginEnabled>
<authBasicDomain></authBasicDomain>
<authBasicEnabled>1</authBasicEnabled>
<checkNotices></checkNotices>
<checkUpdates></checkUpdates>
<configDate>1607363733</configDate>
<configHash>0384920872756be7d264ec32433e78cef0180442</configHash>
<configSaver>Admin</configSaver>
<configVersion></configVersion>
<databaseVersion></databaseVersion>
<dbHost></dbHost>
<dbName></dbName>
<dbPass></dbPass>
<dbPort>3306</dbPort>
<dbSocket></dbSocket>
<dbUser></dbUser>
<debug></debug>
<demoEnabled></demoEnabled>
<dokuwikiEnabled></dokuwikiEnabled>
<dokuwikiNamespace></dokuwikiNamespace>
<dokuwikiPass></dokuwikiPass>
<dokuwikiUrl></dokuwikiUrl>
<dokuwikiUrlBase></dokuwikiUrlBase>
<dokuwikiUser></dokuwikiUser>
<encryptSession></encryptSession>
<export_hash>46aa537c917e043aa59e60d91e7f69aecbf727c7</export_hash>
<filesAllowedMime/>
<filesAllowedSize>1024</filesAllowedSize>
<filesEnabled>1</filesEnabled>
<globalSearch>1</globalSearch>
<httpsEnabled></httpsEnabled>
<installed></installed>
<ldapBase></ldapBase>
<ldapBindPass></ldapBindPass>
<ldapBindUser></ldapBindUser>
<ldapDefaultGroup>2</ldapDefaultGroup>
<ldapDefaultProfile>2</ldapDefaultProfile>
<ldapEnabled></ldapEnabled>
<ldapGroup></ldapGroup>
<ldapServer></ldapServer>
<ldapTlsEnabled>0</ldapTlsEnabled>
<ldapType>0</ldapType>
<logEnabled>1</logEnabled>
<logEvents/>
<mailAuthenabled></mailAuthenabled>
<mailEnabled></mailEnabled>
<mailEvents/>
<mailFrom></mailFrom>
<mailPass></mailPass>
<mailPort>25</mailPort>
<mailRecipients/>
<mailRequestsEnabled></mailRequestsEnabled>
<mailSecurity></mailSecurity>
<mailServer></mailServer>
<mailUser></mailUser>
<maintenance></maintenance>
<passwordSalt>fd1058ca0bbaf967d08184ed22ee2c8d5675ca0c9d569c1f237f23fefadf</passwordSalt>
<proxyEnabled></proxyEnabled>
<proxyPass></proxyPass>
<proxyPort>8080</proxyPort>
<proxyServer></proxyServer>
<proxyUser></proxyUser>
<publinksEnabled></publinksEnabled>
<publinksImageEnabled></publinksImageEnabled>
<publinksMaxTime>600</publinksMaxTime>
<publinksMaxViews>3</publinksMaxViews>
<resultsAsCards></resultsAsCards>
<sessionTimeout>300</sessionTimeout>
<siteLang></siteLang>
<siteTheme>material-blue</siteTheme>
<ssoDefaultGroup>3</ssoDefaultGroup>
<ssoDefaultProfile>3</ssoDefaultProfile>
<syslogEnabled></syslogEnabled>
<syslogPort>514</syslogPort>
<syslogRemoteEnabled></syslogRemoteEnabled>
<syslogServer></syslogServer>
<upgradeKey></upgradeKey>
<wikiEnabled></wikiEnabled>
<wikiFilter/>
<wikiPageurl></wikiPageurl>
<wikiSearchurl></wikiSearchurl>
</config>

View File

@@ -1,6 +1,6 @@
#!/bin/bash
DB_HOST=$(docker inspect syspass-db-test --format {{.NetworkSettings.Networks.bridge.IPAddress}})
DB_HOST=$(docker inspect build_db-test_1 --format {{.NetworkSettings.Networks.bridge.IPAddress}})
if [[ -z "${DB_HOST}" ]]; then
echo "Unknown host"