owncloud /
chat
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | /** |
||
| 3 | * Copyright (c) 2014, Tobia De Koninck hey--at--ledfan.be |
||
| 4 | * This file is licensed under the AGPL version 3 or later. |
||
| 5 | * See the COPYING file. |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace OCA\Chat\OCH\Commands; |
||
| 9 | |||
| 10 | include_once(__DIR__ . '/../../../autoloader.php'); |
||
| 11 | include_once(__DIR__ . '/../../../vendor/Pimple/Pimple.php'); |
||
| 12 | |||
| 13 | |||
| 14 | use OCA\Chat\App\Chat; |
||
| 15 | use OCA\Chat\OCH\Db\UserOnline; |
||
| 16 | |||
| 17 | class GreetTest extends \PHPUnit_Framework_TestCase { |
||
| 18 | |||
| 19 | public static $userOnline; |
||
| 20 | |||
| 21 | public function setUp(){ |
||
| 22 | $app = new Chat(); |
||
|
0 ignored issues
–
show
|
|||
| 23 | $this->container = $app->getContainer(); |
||
|
0 ignored issues
–
show
The property
container does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
The method
getContainer() does not seem to exist on object<OCA\Chat\App\Chat>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 24 | $this->container['API'] = $this->getMockBuilder('\OCA\Chat\Core\API') |
||
| 25 | ->disableOriginalConstructor() |
||
| 26 | ->getMock(); |
||
| 27 | $this->container['API']->expects($this->any()) |
||
| 28 | ->method('log') |
||
| 29 | ->will($this->returnValue(null)); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Testcase: if there is a PDOException in the datamapper a DBException must be thrown |
||
| 34 | * with the same message as in the PDOException |
||
| 35 | */ |
||
| 36 | public function testDBFailure(){ |
||
| 37 | $this->setExpectedException('\OCA\Chat\Db\DBException', 'Something went wrong with the DB!'); |
||
| 38 | // config |
||
| 39 | $this->container['API']->expects($this->any()) |
||
| 40 | ->method('prepareQuery') |
||
| 41 | ->will($this->throwException(new \PDOException('Something went wrong with the DB!'))); |
||
| 42 | |||
| 43 | // logic |
||
| 44 | $greet = new Greet($this->container); |
||
|
0 ignored issues
–
show
|
|||
| 45 | $greet->setRequestData(array( |
||
| 46 | 'user' => array ( |
||
| 47 | 'id' => 'admin', |
||
| 48 | 'online' => false, |
||
| 49 | 'displayname' => 'admin', |
||
| 50 | 'backends' => array ( |
||
| 51 | 'och' => array ( |
||
| 52 | 'id' => NULL, |
||
| 53 | 'displayname' => 'ownCloud Handle', |
||
| 54 | 'protocol' => 'x-owncloud-handle', |
||
| 55 | 'namespace' => 'och', |
||
| 56 | 'value' => 'admin', |
||
| 57 | ), |
||
| 58 | ), |
||
| 59 | 'address_book_id' => 'admin', |
||
| 60 | 'address_book_backend' => 'localusers', |
||
| 61 | ), |
||
| 62 | 'session_id' => 'c08809598b01894c468873fab54291aa', |
||
| 63 | 'timestamp' => 1397328934.658, |
||
| 64 | )); |
||
| 65 | $result = $greet->execute(); |
||
|
0 ignored issues
–
show
$result is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 66 | } |
||
| 67 | |||
| 68 | public function testGeneratedSessionId(){ |
||
| 69 | $this->container['UserOnlineMapper'] = $this->getMockBuilder('\OCA\Chat\OCH\Db\UserOnlineMapper') |
||
| 70 | ->disableOriginalConstructor() |
||
| 71 | ->getMock(); |
||
| 72 | $this->container['UserOnlineMapper']->expects($this->any()) |
||
| 73 | ->method('insert') |
||
| 74 | ->will($this->returnValue(true)); |
||
| 75 | |||
| 76 | $time = time(); |
||
| 77 | $greet = new Greet($this->container); |
||
|
0 ignored issues
–
show
$this->container is of type array<string,?,{"UserOnlineMapper":"?"}>, but the function expects a object<OCA\Chat\OCH\Db\PushMessageMapper>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 78 | $greet->setRequestData(array( |
||
| 79 | 'timestamp' => $time, |
||
| 80 | 'user' => array ( |
||
| 81 | 'id' => 'admin', |
||
| 82 | 'online' => false, |
||
| 83 | 'displayname' => 'admin', |
||
| 84 | 'backends' => array ( |
||
| 85 | 'och' => array ( |
||
| 86 | 'id' => NULL, |
||
| 87 | 'displayname' => 'ownCloud Handle', |
||
| 88 | 'protocol' => 'x-owncloud-handle', |
||
| 89 | 'namespace' => 'och', |
||
| 90 | 'value' => 'admin', |
||
| 91 | ), |
||
| 92 | ), |
||
| 93 | 'address_book_id' => 'admin', |
||
| 94 | 'address_book_backend' => 'localusers', |
||
| 95 | ), |
||
| 96 | )); |
||
| 97 | $result = $greet->execute(); |
||
| 98 | $expectedSessionId = md5("sessionID" . $time); |
||
| 99 | |||
| 100 | $this->assertEquals($expectedSessionId, $result['session_id']); |
||
| 101 | } |
||
| 102 | |||
| 103 | public function testUserOnlineMapperInsert(){ |
||
| 104 | $this->container['UserOnlineMapper'] = $this->getMockBuilder('\OCA\Chat\OCH\Db\UserOnlineMapper') |
||
| 105 | ->disableOriginalConstructor() |
||
| 106 | ->getMock(); |
||
| 107 | $this->container['UserOnlineMapper']->expects($this->any()) |
||
| 108 | ->method('insert') |
||
| 109 | ->will($this->returnCallback(function($userOnline){ |
||
| 110 | GreetTest::$userOnline = $userOnline; |
||
| 111 | })); |
||
| 112 | |||
| 113 | $time = time(); |
||
| 114 | $greet = new Greet($this->container); |
||
|
0 ignored issues
–
show
$this->container is of type array<string,?,{"UserOnlineMapper":"?"}>, but the function expects a object<OCA\Chat\OCH\Db\PushMessageMapper>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 115 | $greet->setRequestData(array( |
||
| 116 | 'timestamp' => $time, |
||
| 117 | 'user' => array ( |
||
| 118 | 'id' => 'admin', |
||
| 119 | 'online' => false, |
||
| 120 | 'displayname' => 'admin', |
||
| 121 | 'backends' => array ( |
||
| 122 | 'och' => array ( |
||
| 123 | 'id' => NULL, |
||
| 124 | 'displayname' => 'ownCloud Handle', |
||
| 125 | 'protocol' => 'x-owncloud-handle', |
||
| 126 | 'namespace' => 'och', |
||
| 127 | 'value' => 'admin', |
||
| 128 | ), |
||
| 129 | ), |
||
| 130 | 'address_book_id' => 'admin', |
||
| 131 | 'address_book_backend' => 'localusers', |
||
| 132 | ), |
||
| 133 | )); |
||
| 134 | $greet->execute(); |
||
| 135 | |||
| 136 | $expectedUserOnline = new UserOnline(); |
||
| 137 | $expectedUserOnline->setUser('admin'); |
||
| 138 | $expectedUserOnline->setSessionId(md5("sessionID" . $time)); |
||
| 139 | $expectedUserOnline->setLastOnline($time); |
||
| 140 | |||
| 141 | $this->assertEquals($expectedUserOnline, GreetTest::$userOnline); |
||
| 142 | |||
| 143 | } |
||
| 144 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.