Issues (6)

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/Units/DbUser.php (3 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
 * Test class for DbUser.
4
 *
5
 * @author  Stéphane Monnot <[email protected]>
6
 * @license MIT http://mit-license.org/
7
 */
8
namespace Shinbuntu\DbUser\Tests\Units;
9
10
use atoum;
11
use mock\Doctrine\DBAL\Connection;
12
use Shinbuntu\DbUser\DbUser as testedClass;
13
14
/**
15
 * Test class for DbUser.
16
 *
17
 * @author  Stéphane Monnot <[email protected]>
18
 * @license MIT http://mit-license.org/
19
 */
20
class DbUser extends atoum
21
{
22
    private $connection = null;
23
24
    private function getConnection()
25
    {
26
        if ($this->connection !== null) {
27
            return $this->connection;
28
        }
29
        $this->mockGenerator->shuntParentClassCalls();
30
        $this->mockGenerator->orphanize('__construct');
31
        $this->mockGenerator->orphanize('__construct');
32
33
        $this->connection = new Connection();
34
        $this->connection->getMockController()->connect = function () {
35
        };
36
        $this->connection->getMockController()->fetchColumn = function () {
37
        };
38
        $this->connection->getMockController()->quote = function ($input) {
39
            return '"'.addslashes($input).'"';
40
        };
41
42
        $this->mockGenerator->unshuntParentClassCalls();
43
44
        return $this->connection;
45
    }
46
47
    /**
48
     * Test createUserQuery method.
49
     *
50
     * @return void
51
     */
52 View Code Duplication
    public function testCreateUserQuery()
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
        $connection = $this->getConnection();
55
56
        $this
57
            ->if($this->newTestedInstance($connection))
58
            ->string($this->testedInstance->createUserQuery('test_username', '!super_secure_password$'))
59
                ->isEqualTo('CREATE USER test_username@localhost IDENTIFIED BY "!super_secure_password$";');
60
    }
61
62
    /**
63
     * Test dropUser method.
64
     *
65
     * @return void
66
     */
67 View Code Duplication
    public function testDropUserQuery()
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...
68
    {
69
        $connection = $this->getConnection();
70
71
        $this
72
            ->if($this->newTestedInstance($connection))
73
            ->string($this->testedInstance->dropUserQuery('test_username', '!super_secure_password$'))
74
                ->isEqualTo('DROP USER test_username@localhost;');
75
    }
76
77
    /**
78
     * Test userExistQuery method.
79
     *
80
     * @return void
81
     */
82 View Code Duplication
    public function testUserExistQuery()
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...
83
    {
84
        $connection = $this->getConnection();
85
86
        $this
87
            ->if($this->newTestedInstance($connection))
88
            ->string($this->testedInstance->userExistQuery('test_username'))
89
                ->isEqualTo('SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = "test_username");');
90
    }
91
92
    /**
93
     * Test flushPrivilegesQuery method.
94
     *
95
     * @return void
96
     */
97
    public function testFlushPrivilegesQuery()
98
    {
99
        $connection = $this->getConnection();
100
101
        $this
102
            ->if($this->newTestedInstance($connection))
103
            ->string($this->testedInstance->flushPrivilegesQuery())
104
                ->isEqualTo('FLUSH PRIVILEGES;');
105
    }
106
107
    /**
108
     * Test changePrivilegesQuery method.
109
     *
110
     * @return void
111
     */
112
    public function testChangePrivilegesQuery()
113
    {
114
        $connection = $this->getConnection();
115
116
        $this
117
            ->if($this->newTestedInstance($connection))
118
            ->string(
119
                $this->testedInstance->changePrivilegesQuery(
120
                    testedClass::PRIVILEGE_STATEMENT_GRANT,
121
                    'test_username',
122
                    [
123
                        testedClass::PRIVILEGE_CREATE,
124
                        testedClass::PRIVILEGE_UPDATE,
125
                        testedClass::PRIVILEGE_DELETE,
126
                    ],
127
                    'test_database',
128
                    'test_table'
129
            ))
130
                ->isEqualTo('GRANT CREATE, UPDATE, DELETE ON test_database.test_table TO "test_username"@localhost;')
131
132
            ->string(
133
                $this->testedInstance->changePrivilegesQuery(
134
                    testedClass::PRIVILEGE_STATEMENT_GRANT,
135
                    'test_username',
136
                    testedClass::PRIVILEGE_CREATE,
137
                    'test_database',
138
                    'test_table'
139
                ))
140
                ->isEqualTo('GRANT CREATE ON test_database.test_table TO "test_username"@localhost;');
141
    }
142
143
    /**
144
     * Fake Tests for doctrine to ignore in coverage percentage.
145
     *
146
     * @return void
147
     */
148
    public function testDoctrine()
149
    {
150
        $connection = $this->getConnection();
151
152
        $this
153
            ->if($this->newTestedInstance($connection))
154
            ->variable($this->testedInstance->flushPrivileges())
155
                ->isEqualTo(true)
156
157
            ->variable($this->testedInstance->revokePrivileges('test_username'))
158
                ->isEqualTo(true)
159
160
            ->variable($this->testedInstance->grantPrivileges('test_username'))
161
                ->isEqualTo(true)
162
163
            ->variable($this->testedInstance->userExist('test_username'))
164
                ->isNull()
165
166
            ->variable($this->testedInstance->dropUser('test_username'))
167
                ->isEqualTo(true)
168
169
            ->variable($this->testedInstance->createUser('test_username', 'test_password'))
170
                ->isEqualTo(true);
171
    }
172
}
173