This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Fix/latest versions security #88
Open
etobi
wants to merge
5
commits into
master
Choose a base branch
from
fix/latestVersionsSecurity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eedcc27
Applied patch from https://forge.typo3.org/issues/58828#change-321465…
2391b60
Merge branch 'master' of https://github.com/jvanderkroon/caretaker in…
etobi 78c1351
[TASK] refactor latest version calc and add basic tests
etobi 43ec857
[TASK] fix code style
etobi fb0625b
[TASK] remove double assignment
etobi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ class tx_caretaker_LatestVersionsHelper | |
protected static $releaseJsonFeed = 'https://get.typo3.org/json'; | ||
|
||
/** | ||
* @throws Exception | ||
* @return bool | ||
*/ | ||
public static function updateLatestTypo3VersionRegistry() | ||
|
@@ -60,24 +61,18 @@ public static function updateLatestTypo3VersionRegistry() | |
|
||
if (!is_array($releases)) { | ||
throw new Exception( | ||
'It seems like ' . self::$releaseJsonFeed . | ||
' did not return the json string for the TYPO3 releases. Maybe it has been moved!?' | ||
'It seems like ' . self::$releaseJsonFeed . | ||
' did not return the json string for the TYPO3 releases. Maybe it has been moved!?' | ||
); | ||
} | ||
|
||
$max = array(); | ||
$stable = array(); | ||
foreach ($releases as $major => $details) { | ||
if (is_array($details) && !empty($details['latest'])) { | ||
$max[$major] = $details['latest']; | ||
} | ||
$latestVersions = self::getLatestFromReleases($releases); | ||
|
||
if (is_array($details) && !empty($details['stable'])) { | ||
$stable[$major] = $details['stable']; | ||
} | ||
} | ||
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Registry')->set('tx_caretaker', 'TYPO3versions', $max); | ||
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Registry')->set('tx_caretaker', 'TYPO3versionsStable', $stable); | ||
/** @var \TYPO3\CMS\Core\Registry $registry */ | ||
$registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Registry'); | ||
$registry->set('tx_caretaker', 'TYPO3versions', $latestVersions['max']); | ||
$registry->set('tx_caretaker', 'TYPO3versionsStable', $latestVersions['stable']); | ||
$registry->set('tx_caretaker', 'TYPO3versionsSecurity', $latestVersions['security']); | ||
|
||
return true; | ||
} | ||
|
@@ -113,4 +108,38 @@ protected static function curlRequest($requestUrl = false) | |
|
||
return $response; | ||
} | ||
|
||
/** | ||
* @param array $releases | ||
* @return array | ||
*/ | ||
public static function getLatestFromReleases($releases) | ||
{ | ||
$max = array(); | ||
$stable = array(); | ||
$security = array(); | ||
foreach ($releases as $major => $details) { | ||
if (is_array($details) && !empty($details['latest'])) { | ||
$max[$major] = $details['latest']; | ||
} | ||
|
||
if (is_array($details) && !empty($details['stable'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!empty($details['stable'])) is sufficient here |
||
$stable[$major] = $details['stable']; | ||
} | ||
if (is_array($details) && is_array($details['releases'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!empty($details['releases'])) is sufficient here |
||
foreach ($details['releases'] as $version => $versionDetails) { | ||
$security[$major] = $version; | ||
if ($versionDetails['type'] === 'security') { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return array( | ||
'max' => $max, | ||
'stable' => $stable, | ||
'security' => $security, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"3": { | ||
"releases": { | ||
"3.0.2": { | ||
"version": "3.0.2", | ||
"type": "regular" | ||
}, | ||
"3.0.1": { | ||
"version": "3.0.1", | ||
"type": "regular" | ||
}, | ||
"3.0.0": { | ||
"version": "3.0.0", | ||
"type": "release" | ||
} | ||
}, | ||
"latest": "3.0.2", | ||
"stable": "3.0.1", | ||
"active": true | ||
}, | ||
"2": { | ||
"releases": { | ||
"2.1.2": { | ||
"version": "2.1.2", | ||
"type": "regular" | ||
}, | ||
"2.1.1": { | ||
"version": "2.1.1", | ||
"type": "security" | ||
}, | ||
"2.1.0": { | ||
"version": "2.1.0", | ||
"type": "release" | ||
}, | ||
"2.0.2": { | ||
"version": "2.0.2", | ||
"type": "regular" | ||
}, | ||
"2.0.1": { | ||
"version": "2.0.1", | ||
"type": "security" | ||
}, | ||
"2.0.0": { | ||
"version": "2.0.0", | ||
"type": "release" | ||
} | ||
}, | ||
"latest": "2.1.2", | ||
"stable": "2.1.2", | ||
"active": true | ||
}, | ||
"1": { | ||
"releases": { | ||
"1.1.2": { | ||
"version": "1.1.2", | ||
"type": "regular" | ||
}, | ||
"1.1.1": { | ||
"version": "1.1.1", | ||
"type": "security" | ||
}, | ||
"1.1.0": { | ||
"version": "1.1.0", | ||
"type": "release" | ||
}, | ||
"1.0.2": { | ||
"version": "1.0.2", | ||
"type": "regular" | ||
}, | ||
"1.0.1": { | ||
"version": "1.0.1", | ||
"type": "security" | ||
}, | ||
"1.0.0": { | ||
"version": "1.0.0", | ||
"type": "release" | ||
} | ||
}, | ||
"latest": "1.1.2", | ||
"stable": "1.1.2", | ||
"active": true | ||
}, | ||
|
||
"latest_stable": "2.1.2", | ||
"latest_old_stable": "1.1.2", | ||
"latest_lts": "2.1.2", | ||
"latest_old_lts": "1.1.2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
namespace Caretaker\Caretaker\Tests\Unit; | ||
|
||
use TYPO3\CMS\Core\Tests\UnitTestCase; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* | ||
* (c) 2009-2011 by n@work GmbH and networkteam GmbH | ||
* | ||
* All rights reserved | ||
* | ||
* This script is part of the Caretaker project. The Caretaker project | ||
* is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
***************************************************************/ | ||
|
||
/** | ||
* This is a file of the caretaker project. | ||
* http://forge.typo3.org/projects/show/extension-caretaker | ||
* | ||
* Project sponsored by: | ||
* n@work GmbH - http://www.work.de | ||
* networkteam GmbH - http://www.networkteam.com/ | ||
*/ | ||
class LatestVersionsHelperTest extends UnitTestCase | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $releases; | ||
|
||
public function setup() | ||
{ | ||
$json = file_get_contents(GeneralUtility::getFileAbsFileName('EXT:caretaker/Tests/Unit/Fixtures/versions.json')); | ||
$this->releases = json_decode($json, true); | ||
} | ||
|
||
public function testLatest() | ||
{ | ||
$latest = \tx_caretaker_LatestVersionsHelper::getLatestFromReleases($this->releases); | ||
|
||
$this->assertEquals('3.0.2', $latest['max']['3'], 'v3: latest release'); | ||
$this->assertEquals('3.0.1', $latest['stable']['3'], 'v3: stable release'); | ||
$this->assertEquals('3.0.0', $latest['security']['3'], 'v3: no security release falls back to the first release'); | ||
|
||
$this->assertEquals('2.1.2', $latest['max']['2'], 'v2: latest release'); | ||
$this->assertEquals('2.1.2', $latest['stable']['2'], 'v2: stable release'); | ||
$this->assertEquals('2.1.1', $latest['security']['2'], 'v2: security release'); | ||
|
||
$this->assertEquals('1.1.2', $latest['max']['1'], 'v1: latest release'); | ||
$this->assertEquals('1.1.2', $latest['stable']['1'], 'v1: stable release'); | ||
$this->assertEquals('1.1.1', $latest['security']['1'], 'v1: security release'); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!empty($details['latest'])) is sufficient here