Issues (158)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/unit/lib/och/commands/Greet.php (10 issues)

Upgrade to new PHP Analysis Engine

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
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 10.

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.

Loading history...
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
The call to Chat::__construct() misses some required arguments starting with $backendManager.
Loading history...
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
The call to Greet::__construct() misses a required argument $userOnlineMapper.

This check looks for function calls that miss required arguments.

Loading history...
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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

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
The call to Greet::__construct() misses a required argument $userOnlineMapper.

This check looks for function calls that miss required arguments.

Loading history...
$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
The call to Greet::__construct() misses a required argument $userOnlineMapper.

This check looks for function calls that miss required arguments.

Loading history...
$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
}