Completed
Push — master ( 622c37...dca855 )
by Christian
04:12
created

SelfTestFileOwnerMatches::doTest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\SelfTest\Generic;
22
23
use Symfony\Component\HttpFoundation\Request;
24
use Tenside\Core\SelfTest\AbstractSelfTest;
25
26
/**
27
 * This class tests that the file owner matches the user executing php.
28
 */
29
class SelfTestFileOwnerMatches extends AbstractSelfTest
30
{
31
    /**
32
     * Check that we are being called via HTTPS in favor of HTTP.
33
     *
34
     * @return void
35
     */
36
    protected function doTest()
37
    {
38
        $this->setMessage('Check that the file owner matches the user executing php');
39
40
        $request = Request::createFromGlobals();
41
42
        $owning  = fileowner($request->server->get('SCRIPT_FILENAME'));
43
        $running = getmyuid();
44
45
        if ($owning === $running) {
46
            $this->markSuccess();
47
48
            return;
49
        }
50
51
        $this->markWarning('Script is owned by uid ' . $owning . ' whereas it is being executed by uid ' . $running);
52
    }
53
}
54