Issues (3099)

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.

AdminBundle/Tests/unit/Entity/GroupTest.php (2 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 Kunstmaan\AdminBundle\Tests\Entity;
4
5
use Kunstmaan\AdminBundle\Entity\Group;
6
use Kunstmaan\AdminBundle\Entity\Role;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Validator\Validation;
9
10
/**
11
 * Generated by PHPUnit_SkeletonGenerator on 2012-08-28 at 17:50:57.
12
 */
13
class GroupTest extends TestCase
14
{
15
    /**
16
     * @var Group
17
     */
18
    protected $object;
19
20
    /**
21
     * Sets up the fixture, for example, opens a network connection.
22
     * This method is called before a test is executed.
23
     */
24
    protected function setUp(): void
25
    {
26
        $this->object = new Group('group');
27
    }
28
29
    public function testGetId()
30
    {
31
        $this->assertEquals(null, $this->object->getId());
32
    }
33
34
    public function test__toString()
35
    {
36
        $this->assertEquals('group', $this->object->__toString());
37
    }
38
39
    public function testGetRoles()
40
    {
41
        /* @var $role Role */
42
        $role = $this->getRole();
43
        $this->object->addRole($role);
44
45
        $this->assertEquals(array('role1'), $this->object->getRoles());
46
    }
47
48
    public function testGetRolesCollection()
49
    {
50
        /* @var $role Role */
51
        $role = $this->getRole();
52
        $this->object->addRole($role);
53
54
        $collection = new \Doctrine\Common\Collections\ArrayCollection();
55
        $collection->add($role);
56
57
        $this->assertEquals($collection, $this->object->getRolesCollection());
58
    }
59
60
    public function testGetRole()
61
    {
62
        /* @var $role Role */
63
        $role = $this->getRole();
64
        $this->object->addRole($role);
65
66
        $result = $this->object->getRole('role1');
67
        $this->assertEquals($role, $result);
68
69
        $result = $this->object->getRole('role2');
70
        $this->assertEquals(null, $result);
71
    }
72
73
    public function testHasRole()
74
    {
75
        /* @var $role Role */
76
        $role = $this->getRole();
77
        $this->object->addRole($role);
78
79
        $this->assertTrue($this->object->hasRole('role1'));
80
        $this->assertFalse($this->object->hasRole('role2'));
81
    }
82
83 View Code Duplication
    public function testRemoveRole()
84
    {
85
        /* @var $role Role */
86
        $role = $this->getRole();
87
        $this->object->addRole($role);
88
        $this->assertTrue($this->object->hasRole('role1'));
89
90
        $this->object->removeRole('role1');
91
        $this->assertFalse($this->object->hasRole('role1'));
92
    }
93
94
    public function testAddRoleWithInvalidParameter()
95
    {
96
        $this->expectException(\InvalidArgumentException::class);
97
        /* @var $role Role */
98
        $role = new \StdClass();
99
        $this->object->addRole($role);
100
    }
101
102
    public function testSetRoles()
103
    {
104
        $role1 = $this->getRole('role1');
105
        $role2 = $this->getRole('role2');
106
        $role3 = $this->getRole('role3');
107
        $roles = array($role1, $role2, $role3);
108
        $this->object->setRoles($roles);
109
110
        $this->assertCount(3, $this->object->getRoles());
111
    }
112
113
    public function testSetRolesCollection()
114
    {
115
        $role1 = $this->getRole('role1');
116
        $role2 = $this->getRole('role2');
117
        $role3 = $this->getRole('role3');
118
119
        $roles = new \Doctrine\Common\Collections\ArrayCollection();
120
        $roles->add($role1);
121
        $roles->add($role2);
122
        $roles->add($role3);
123
124
        $this->object->setRolesCollection($roles);
125
        $this->assertEquals(3, $this->object->getRolesCollection()->count());
126
    }
127
128
    public function testConstructorAndGetSetName()
129
    {
130
        $object = new Group('testgroup');
131
        $this->assertEquals('testgroup', $object->getName());
132
133
        $object->setName('group2');
134
        $this->assertEquals('group2', $object->getName());
135
    }
136
137 View Code Duplication
    public function testValidateGroupWithoutRole()
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...
138
    {
139
        $group = new Group('test');
140
141
        $validator = Validation::createValidatorBuilder()
142
            ->enableAnnotationMapping()
143
            ->getValidator();
144
145
        $violations = $validator->validate($group);
146
147
        $this->assertCount(1, $violations);
148
    }
149
150 View Code Duplication
    public function testValidateGroupWithRole()
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...
151
    {
152
        $group = new Group('test');
153
        $group->addRole(new Role('role'));
154
155
        $validator = Validation::createValidatorBuilder()
156
            ->enableAnnotationMapping()
157
            ->getValidator();
158
159
        $violations = $validator->validate($group);
160
161
        $this->assertCount(0, $violations);
162
    }
163
164
    /**
165
     * @param string $name
166
     *
167
     * @return \Kunstmaan\AdminBundle\Entity\Role
168
     */
169
    protected function getRole($name = 'role1')
170
    {
171
        $role = $this->getMockBuilder('Kunstmaan\AdminBundle\Entity\Role')
172
            ->disableOriginalConstructor()
173
            ->getMock();
174
        $role->expects($this->any())
175
            ->method('getRole')
176
            ->will($this->returnValue($name));
177
178
        return $role;
179
    }
180
}
181