Issues (493)

Security Analysis    not enabled

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/backend/backend_test.php (5 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 16 and the first side effect is on line 14.

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) 2013 Thomas Tanghus ([email protected])
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
namespace OCA\Contacts\Backend;
10
11
use Sabre\VObject\Reader;
12
use Test\TestCase;
13
14
require_once __DIR__ .'/mock.php';
15
16
class BackendTest extends TestCase {
17
18
	/**
19
	* @var array
20
	*/
21
	protected $abinfo;
22
23
	/**
24
	* @var array
25
	*/
26
	protected $permissions = array(
27
		\OCP\PERMISSION_READ,
28
		\OCP\PERMISSION_CREATE,
29
		\OCP\PERMISSION_UPDATE,
30
		\OCP\PERMISSION_DELETE
31
	);
32
33
	/**
34
	* @var \OCA\Contacts\Backend\AbstractBackend
35
	*/
36
	protected $backend;
37
38
	public function setUp() {
39
		parent::setUp();
40
		$this->backend = new Mock('foobar');
41
	}
42
43
	public function tearDown() {
44
		unset($this->backend);
45
		parent::tearDown();
46
	}
47
48
	public function testHasContactMethodFor() {
49
50
		foreach($this->permissions as $permission) {
51
			$this->assertTrue($this->backend->hasContactMethodFor($permission));
52
		}
53
54
	}
55
56
	public function testHasAddressBookMethodFor() {
57
58
		foreach($this->permissions as $permission) {
59
			$this->assertTrue($this->backend->hasAddressBookMethodFor($permission));
60
		}
61
62
	}
63
64
	public function testgetAddressBooksForUser() {
65
66
		$this->assertEquals(1, count($this->backend->getAddressBooksForUser()));
67
68
	}
69
70
	public function testDeleteAddressBook() {
71
72
		$this->assertTrue($this->backend->deleteAddressBook('foo'));
73
		$this->assertEquals(array(), $this->backend->addressBooks);
0 ignored issues
show
The property addressBooks does not seem to exist in OCA\Contacts\Backend\AbstractBackend.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
74
75
	}
76
77
	public function testCreateAddressBook() {
78
79
		$id = $this->backend->createAddressBook(array('displayname' => 'bar'));
80
81
		$this->assertNotEquals(false, $id);
82
83
		$this->assertEquals(2, count($this->backend->getAddressBooksForUser()));
84
85
		$book = $this->backend->getAddressBook($id);
86
87
		$this->assertEquals('bar', $book['displayname']);
88
89
	}
90
91
	public function testCreateAddressBookFail() {
92
93
		// displayname must be provided.
94
		$id = $this->backend->createAddressBook(array('description' => 'foo bar'));
95
96
		$this->assertFalse($id);
97
98
	}
99
100 View Code Duplication
	public function testUpdateAddressBook() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
102
		$this->assertTrue(
103
			$this->backend->updateAddressBook('foo', array('displayname' => 'bar'))
104
		);
105
106
		$this->assertEquals('bar', $this->backend->addressBooks[0]['displayname']);
0 ignored issues
show
The property addressBooks does not seem to exist in OCA\Contacts\Backend\AbstractBackend.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
107
108
		return $this->backend;
109
110
	}
111
112
	public function testUpdateAddressBookFail() {
113
114
		$this->assertFalse(
115
			$this->backend->updateAddressBook('foo', array('description' => 'foo bar'))
116
		);
117
118
	}
119
120
	/**
121
	* @depends testUpdateAddressBook
122
	*/
123
	public function testGetAddressBook($backend) {
124
125
		$book = $backend->getAddressBook('foo');
126
		$this->assertEquals('bar', $book['displayname']);
127
128
	}
129
130
	public function testGetAddressBookFail() {
131
132
		$this->assertNull($this->backend->getAddressBook('bar'));
133
134
	}
135
136
	public function testGetLastModifiedAddressBook() {
137
138
		$this->assertNull($this->backend->lastModifiedAddressBook('foo'));
139
140
	}
141
142
	public function testGetContact() {
143
144
		$contact = $this->backend->getContact('foo', '123');
145
		$this->assertTrue(is_array($contact));
146
		$this->assertEquals('Max Mustermann', $contact['displayname']);
147
		$this->assertEquals('foobar', $contact['owner']);
148
		$this->assertEquals(\OCP\PERMISSION_ALL, $contact['permissions']);
149
150
	}
151
152
	public function testGetContactFail() {
153
154
		$this->assertNull($this->backend->getContact('foo', '1234'));
155
156
	}
157
158 View Code Duplication
	public function testCreateContact() {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
159
160
		$carddata = file_get_contents(__DIR__ . '/../../data/test2.vcf');
161
		$vcard = Reader::read($carddata);
162
		$id = $this->backend->createContact('foo', $vcard);
163
164
		$this->assertNotEquals(false, $id);
165
166
		return $this->backend;
167
	}
168
169
	/**
170
	* @depends testCreateContact
171
	*/
172
	public function testGetContacts($backend) {
173
174
		$contacts = $backend->getContacts('foo');
175
176
		$this->assertCount(2, $contacts);
177
178
		$this->assertEquals('Max Mustermann', $contacts[0]['displayname']);
179
		$this->assertEquals('John Q. Public', $contacts[1]['displayname']);
180
181
	}
182
183
	public function testUpdateContact() {
184
185
		$carddata = file_get_contents(__DIR__ . '/../../data/test2.vcf');
186
		$vcard = Reader::read($carddata);
187
188
		$this->assertInstanceOf('OCA\\Contacts\\VObject\\VCard', $vcard);
189
190
		$this->assertTrue($this->backend->updateContact('foo', '123', $vcard));
191
192
		$contact = $this->backend->getContact('foo', '123');
193
194
		$this->assertEquals('John Q. Public', $contact['displayname']);
195
196
	}
197
198
	public function testDeleteContact() {
199
200
		$this->assertTrue($this->backend->deleteContact('foo', '123'));
201
		$this->assertEquals(array(), $this->backend->getContacts('foo'));
202
203
	}
204
205
}
206