Issues (108)

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.

UserAdminBundle/Repository/UserRepositoryTest.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
2
3
namespace OpenOrchestra\FunctionalTests\UserAdminBundle\Repository;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase;
6
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
7
use OpenOrchestra\UserBundle\Model\UserInterface;
8
use OpenOrchestra\UserBundle\Repository\UserRepository;
9
use OpenOrchestra\GroupBundle\Document\Group;
10
11
/**
12
 * Class UserRepositoryTest
13
 *
14
 * @group integrationTest
15
 */
16
class UserRepositoryTest extends AbstractKernelTestCase
17
{
18
    /**
19
     * @var UserRepository
20
     */
21
    protected $repository;
22
    protected $groupRepository;
23
    protected $language = 'en';
24
25
    /**
26
     * Set up test
27
     */
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
32
        static::bootKernel();
33
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_user.repository.user');
34
        $this->groupRepository = static::$kernel->getContainer()->get('open_orchestra_user.repository.group');
35
    }
36
37
    /**
38
     * @param PaginateFinderConfiguration  $configuration
39
     * @param int                          $count
40
     *
41
     * @dataProvider providePaginateAndSearch
42
     */
43
    public function testFindForPaginate(PaginateFinderConfiguration $configuration, $count)
44
    {
45
        $users = $this->repository->findForPaginate($configuration, $this->language);
46
        $this->assertCount($count, $users);
47
    }
48
49
    /**
50
     * @return array
51
     */
52 View Code Duplication
    public function providePaginateAndSearch()
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...
53
    {
54
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
55
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
56
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('search' => 'demo'));
57
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('username' => 'desc'), 0, 100, array());
58
59
        return array(
60
            'all' => array($configurationAll, 5),
61
            'limit' => array($configurationLimit, 1),
62
            'search' => array($configurationSearch, 2),
63
            'order' => array($configurationAllOrder, 5),
64
        );
65
    }
66
67
    /**
68
     * @param PaginateFinderConfiguration  $configuration
69
     * @param array                        $sitesId
70
     * @param int                          $count
71
     *
72
     * @dataProvider providePaginateAndSearchWithSitesId
73
     */
74
    public function testPaginateAndSearchWithSitesId(PaginateFinderConfiguration $configuration, array $sitesId, $count)
75
    {
76
        $sitesId = $this->convertSiteIdInMongoId($sitesId);
77
        $users = $this->repository->findForPaginateFilterBySiteIds($configuration, $this->language, $sitesId);
78
        $this->assertCount($count, $users);
79
    }
80
81
    /**
82
     * @return array
83
     */
84 View Code Duplication
    public function providePaginateAndSearchWithSitesId()
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...
85
    {
86
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
87
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
88
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('search' => 'admin'));
89
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('username' => 'desc'), 0, 100, array());
90
91
        return array(
92
            array($configurationAll, array(), 0),
93
            array($configurationAll, array('2'), 2),
94
            array($configurationLimit, array('2'), 1),
95
            array($configurationAllOrder, array('2'), 2),
96
            array($configurationSearch, array('2'), 2),
97
        );
98
    }
99
100
    /**
101
     * test count all user
102
     */
103
    public function testCount()
104
    {
105
        $users = $this->repository->count();
106
        $this->assertEquals(5, $users);
107
    }
108
109
    /**
110
     * test count all filter with site id
111
     */
112
    public function testCountFilterBySiteId()
113
    {
114
        $sitesId = $this->convertSiteIdInMongoId(array('2'));
115
        $users = $this->repository->countFilterBySiteIds($sitesId);
116
        $this->assertEquals(2, $users);
117
    }
118
119
    /**
120
     * @param PaginateFinderConfiguration $configuration
121
     * @param int                         $count
122
     *
123
     * @dataProvider provideCountWithFilter
124
     */
125
    public function testCountWithFilter($configuration, $count)
126
    {
127
        $users = $this->repository->countWithFilter($configuration, $this->language);
128
        $this->assertEquals($count, $users);
129
    }
130
131
    /**
132
     * @return array
133
     */
134 View Code Duplication
    public function provideCountWithFilter()
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...
135
    {
136
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
137
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
138
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('search' => 'demo'));
139
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('username' => 'desc'), 0, 100, array());
140
141
        return array(
142
            'all' => array($configurationAll, 5),
143
            'limit' => array($configurationLimit, 5),
144
            'search' => array($configurationSearch, 2),
145
            'order' => array($configurationAllOrder, 5),
146
        );
147
    }
148
149
    /**
150
     * @param PaginateFinderConfiguration $configuration
151
     * @param array                       $sitesId
152
     * @param int                         $count
153
     *
154
     * @dataProvider provideCountWithFilterAndSitesId
155
     */
156
    public function testCountWithFilterAndSitesId($configuration, array $sitesId, $count)
157
    {
158
        $sitesId = $this->convertSiteIdInMongoId($sitesId);
159
        $users = $this->repository->countWithFilterAndSiteIds($configuration, $this->language, $sitesId);
160
        $this->assertEquals($count, $users);
161
    }
162
163
    /**
164
     * @return array
165
     */
166 View Code Duplication
    public function provideCountWithFilterAndSitesId()
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...
167
    {
168
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
169
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
170
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('search' => 'admin'));
171
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('username' => 'desc'), 0, 100, array());
172
173
        return array(
174
            array($configurationAll, array(), 0),
175
            array($configurationAll, array('2'), 2),
176
            array($configurationLimit, array('2'), 2),
177
            array($configurationAllOrder, array('2'), 2),
178
            array($configurationSearch, array('2'), 2),
179
        );
180
    }
181
182
    /**
183
     * Test remove users
184
     */
185 View Code Duplication
    public function testRemoveUsers()
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...
186
    {
187
        $dm = static::$kernel->getContainer()->get('object_manager');
188
        $userDemo = $this->repository->findOneByUsername('demo');
189
        $userSAdmin = $this->repository->findOneByUsername('s-admin');
190
191
        $userIds = array($userDemo->geTId(), $userSAdmin->getId());
192
193
        $this->repository->removeUsers($userIds);
194
        $this->assertNull($this->repository->findOneByUsername('demo'));
195
        $this->assertNull($this->repository->findOneByUsername('s-admin'));
196
197
        $dm->persist(clone $userDemo);
198
        $dm->persist(clone $userSAdmin);
199
        $dm->flush();
200
    }
201
202
    /**
203
     * Test remove users
204
     */
205
    public function testGetCountsUsersByGroups()
206
    {
207
        $groupDemo = $this->groupRepository->findOneBy(array('labels.en' => 'Demo group'));
208
        $groupAdmin = $this->groupRepository->findOneBy(array('labels.en' => 'Site admin demo'));
209
210
        $groupIds = array($groupDemo->getId(), $groupAdmin->getId());
211
212
        $count = $this->repository->getCountsUsersByGroups($groupIds);
213
        $this->assertEquals(array($groupAdmin->getId() => 1, $groupDemo->getId() =>1), $count);
214
    }
215
216
    /**
217
     * @param array $sitesId
218
     *
219
     * @return array
220
     */
221
    protected function convertSiteIdInMongoId(array $sitesId)
222
    {
223
        $sitesMongoId = array();
224
225
        foreach ($sitesId as $siteId) {
226
            $sitesMongoId[] = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId)->getId();
227
        }
228
229
        return $sitesMongoId;
230
    }
231
232
    /**
233
     * @param string $email
234
     *
235
     * @dataProvider provideEmail
236
     */
237
    public function testFindOneByEmail($email)
238
    {
239
        $user = $this->repository->findOneByEmail($email);
240
        $this->assertInstanceOf(UserInterface::class, $user);
241
        $this->assertEquals($user->getEmail(), $email);
242
    }
243
244
    /**
245
     * @return array
246
     */
247
    public function provideEmail()
248
    {
249
        return array(
250
            array('[email protected]'),
251
            array('[email protected]'),
252
            array('[email protected]'),
253
        );
254
    }
255
256
    /**
257
     * test findUsersByGroupsForPaginate
258
     */
259
    public function testFindUsersByGroupsForPaginate()
260
    {
261
        $configuration = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
262
        $group = $this->groupRepository->findOneBy(array('labels.en' => 'Demo group'));
263
        $users = $this->repository->findUsersByGroupsForPaginate($configuration, $group->getId());
264
        $this->assertEquals(1, count($users));
265
    }
266
267
    /**
268
     * test countFilterByGroups
269
     */
270
    public function testCountFilterByGroups()
271
    {
272
        $group = $this->groupRepository->findOneBy(array('labels.en' => 'Demo group'));
273
        $this->assertEquals(1, $this->repository->countFilterByGroups($group->getId()));
274
    }
275
276
    /**
277
     * test removeGroupFromNotListedUsers
278
     */
279
    public function testRemoveGroupFromNotListedUsers()
280
    {
281
        $dm = static::$kernel->getContainer()->get('object_manager');
282
283
        $fakeGroup = new Group();
284
        $fakeGroup->setLabels(array('en' => 'fakeGroup'));
285
        $dm->persist($fakeGroup);
286
        $user = $this->repository->findOneByUsername('demo');
287
        $user->addGroup($fakeGroup);
288
        $dm->persist($user);
289
290
        $dm->flush();
291
292
        $group = $this->groupRepository->findOneBy(array('labels.en' => 'fakeGroup'));
293
294
        $this->assertEquals(1, $this->repository->countFilterByGroups($group->getId()));
295
296
        $this->repository->removeGroup($user->getId(), $group->getId());
297
298
        $this->assertEquals(0, $this->repository->countFilterByGroups($group->getId()));
299
    }
300
301
    /**
302
     * test addGroup
303
     */
304
    public function testAddGroup()
305
    {
306
        $dm = static::$kernel->getContainer()->get('object_manager');
307
308
        $fakeGroup = new Group();
309
        $fakeGroup->setLabels(array('en' => 'fakeGroup'));
310
        $dm->persist($fakeGroup);
311
        $dm->flush();
312
313
        $users = $this->repository->findAll();
314
        $nbrUsers = count($users);
315
316
        $this->repository->addGroup($users, $fakeGroup);
317
        $dm->flush();
318
        $this->assertEquals($nbrUsers, $this->repository->countFilterByGroups($fakeGroup->getId()));
319
320
        foreach ($users as $user) {
321
            $this->repository->removeGroup($user->getId(), $fakeGroup->getId());
322
        }
323
324
        $dm->flush();
325
        $this->assertEquals(0, $this->repository->countFilterByGroups($fakeGroup->getId()));
326
327
        $dm->remove($fakeGroup);
328
    }
329
330
}
331