Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

cache resource value: secure quoted html output #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Foomo/Jobs/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function runAJob(AbstractJob $job) {
$locked = false;
$pid = getmypid();
if ($job->getLock()) {
$locked = \Foomo\Lock::lock($jobId, $blocking = false);
$locked = \Foomo\Lock::lockResource($jobId, $blocking = false);
if (!$locked) {
$lockData = \Foomo\Lock::getLockInfo($job->getId());
if ($lockData['lock_age'] < $job->getMaxExecutionTime()) {
Expand All @@ -82,7 +82,7 @@ public static function runAJob(AbstractJob $job) {
Utils::updateStatusJobDone($jobId, $pid, $locked);
if ($job->getLock()) {
// clean up
\Foomo\Lock::release($job->getId());
\Foomo\Lock::releaseResource($job->getId());
Utils::updateStatusJobDone($jobId, $pid, false);
self::$callback = false;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Foomo/MVC.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public static function getBaseUrl($baseURL=null, $force=false)
} else if (is_null($baseURL)) {
if(strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0 || !self::$hideScript) {
return $_SERVER['SCRIPT_NAME'];
} else if(strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0 && self::$hideScript) {
return dirname($_SERVER['SCRIPT_NAME']);
// } else if(strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0 && self::$hideScript) {
// return dirname($_SERVER['SCRIPT_NAME']);
} else {
return '';
}
Expand Down Expand Up @@ -459,4 +459,4 @@ public static function redirect($action, $parameters = array())
header('Location: ' . self::getCurrentURLHandler()->renderMethodURL($action, $parameters));
exit;
}
}
}
10 changes: 5 additions & 5 deletions tests/Foomo/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public function tearDown() {
public function testGetLock() {
$lockName1 = 'testLock1';
$lockName2 = 'testLock2';
$lockObtained = \Foomo\Lock::lock($lockName1, $blocking = true);
$lockObtained = \Foomo\Lock::lockResource($lockName1, $blocking = true);
$this->assertTrue($lockObtained, 'should be able to obtain first lock');

//issue another process
$sucess = file_get_contents(\Foomo\Utils::getServerUrl() . '/foomo/lock.php?lockName=' . $lockName1);

$this->assertFalse($sucess != 'false', 'should not be able to obtain second lock');

$lockReleased = \Foomo\Lock::release($lockName1);
$lockReleased = \Foomo\Lock::releaseResource($lockName1);
$this->assertTrue($lockReleased);

// after the release it should work
Expand All @@ -57,7 +57,7 @@ public function testGetLock() {

public function testLockAge() {
$lockName1 = 'testLock1';
$lockObtained = \Foomo\Lock::lock($lockName1, $blocking = false);
$lockObtained = \Foomo\Lock::lockResource($lockName1, $blocking = false);
sleep(3);
$lockInfo = \Foomo\Lock::getLockInfo($lockName1);
$this->assertEquals(3, $lockInfo['lock_age']);
Expand All @@ -66,15 +66,15 @@ public function testLockAge() {
public function testGetInfo() {
//get a lock from this process
$lockName1 = 'testLock1';
$lockObtained = \Foomo\Lock::lock($lockName1, $blocking = true);
$lockObtained = \Foomo\Lock::lockResource($lockName1, $blocking = true);
$this->assertTrue($lockObtained, 'should be able to obtain first lock');
$info = \Foomo\Lock::getLockInfo($lockName1);
$this->assertTrue($info['is_locked'], 'should be locked after lock call');
$this->assertTrue($info['caller_is_owner'], 'should owned by us');
$this->assertLessThanOrEqual(5, $info['lock_age']);

//release and lock from another process
\Foomo\Lock::release($lockName1);
\Foomo\Lock::releaseResource($lockName1);

//start second process but do not wait for return!

Expand Down
6 changes: 3 additions & 3 deletions tests/Foomo/lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
}

if ($sleep == 0) {
$lockObtained = \Foomo\Lock::lock($lockName, $blocking = false);
$lockObtained = \Foomo\Lock::lockResource($lockName, $blocking = false);
echo $lockObtained ? 'true' : 'false';
exit;
} else {

$lockObtained = \Foomo\Lock::lock($lockName, $blocking = false, 'description');
$lockObtained = \Foomo\Lock::lockResource($lockName, $blocking = false, 'description');
//trigger_error('lock obtained ' . ($lockObtained ? 'true' : 'false'));
echo $lockObtained ? 'true' : 'false';
$info = \Foomo\Lock::getLockInfo($lockName);
Expand All @@ -21,7 +21,7 @@


sleep($sleep);
$release = \Foomo\Lock::release($lockName);
$release = \Foomo\Lock::releaseResource($lockName);
trigger_error('lock released ' . ($release ? 'true' : 'false'));

exit;
Expand Down
3 changes: 1 addition & 2 deletions views/Foomo/Cache/Frontend/partials/resourcesList.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<?
foreach ($resources as $resource):
$valid = ($resource->status == \Foomo\Cache\CacheResource::STATUS_VALID) || ($resource->expirationTime < \time());
Expand Down Expand Up @@ -93,7 +92,7 @@

<h2>Value</h2>
<div class="greyBox">
<?= var_dump($resource->value) ?>
<?= htmlspecialchars(var_export($resource->value, true), ENT_QUOTES) ?>
</div>

</div>
Expand Down