Issues (258)

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.

UI/API/Tests/Functional/ProxyLoginTest.php (1 issue)

duplicate/similar methods.

Duplication Informational

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 App\Containers\Authentication\UI\API\Tests\Functional;
4
5
use App\Containers\Authentication\Tests\ApiTestCase;
6
use Illuminate\Support\Facades\Config;
7
use Illuminate\Support\Facades\DB;
8
9
/**
10
 * Class ProxyLoginTest
11
 *
12
 * @group authorization
13
 * @group api
14
 *
15
 * @author  Mahmoud Zalt  <[email protected]>
16
 */
17
class ProxyLoginTest extends ApiTestCase
18
{
19
    protected $endpoint = '[email protected]/clients/web/admin/login';
20
21
    protected $access = [
22
        'permissions' => '',
23
        'roles'       => '',
24
    ];
25
26
    private $testingFilesCreated = false;
27
28
    /**
29
     * @test
30
     */
31
    public function testClientWebAdminProxyLogin_()
32
    {
33
        // create data to be used for creating the testing user and to be sent with the post request
34
        $data = [
35
            'email'    => '[email protected]',
36
            'password' => 'testingpass'
37
        ];
38
39
        $user = $this->getTestingUser($data);
40
        $this->actingAs($user, 'web');
41
42
        $clientId = '100';
43
        $clientSecret = 'XXp8x4QK7d3J9R7OVRXWrhc19XPRroHTTKIbY8XX';
44
45
        // create client
46
        DB::table('oauth_clients')->insert([
47
            [
48
                'id'                     => $clientId,
49
                'secret'                 => $clientSecret,
50
                'name'                   => 'Testing',
51
                'redirect'               => 'http://localhost',
52
                'password_client'        => '1',
53
                'personal_access_client' => '0',
54
                'revoked'                => '0',
55
            ],
56
        ]);
57
58
        // make the clients credentials available as env variables
59
        Config::set('authentication-container.clients.web.admin.id', $clientId);
60
        Config::set('authentication-container.clients.web.admin.secret', $clientSecret);
61
62
        // create testing oauth keys files
63
        $publicFilePath = $this->createTestingKey('oauth-public.key');
64
        $privateFilePath = $this->createTestingKey('oauth-private.key');
65
66
        $response = $this->makeCall($data);
67
68
        $response->assertStatus(200);
69
70
        $response->assertCookie('refreshToken');
71
72
        $this->assertResponseContainKeyValue([
73
            'token_type' => 'Bearer',
74
        ]);
75
76
        $this->assertResponseContainKeys(['expires_in', 'access_token']);
77
78
        // delete testing keys files if they were created for this test
79
        if ($this->testingFilesCreated) {
80
            unlink($publicFilePath);
81
            unlink($privateFilePath);
82
        }
83
    }
84
85
    /**
86
     * @test
87
     */
88
    public function testClientWebAdminProxyUnconfirmedLogin_()
89
    {
90
        // create data to be used for creating the testing user and to be sent with the post request
91
        $data = [
92
            'email'     => '[email protected]',
93
            'password'  => 'testingpass',
94
            'confirmed' => false,
95
        ];
96
97
        $user = $this->getTestingUser($data);
98
        $this->actingAs($user, 'web');
99
100
        $clientId = '100';
101
        $clientSecret = 'XXp8x4QK7d3J9R7OVRXWrhc19XPRroHTTKIbY8XX';
102
103
        // create client
104
        DB::table('oauth_clients')->insert([
105
            [
106
                'id'                     => $clientId,
107
                'secret'                 => $clientSecret,
108
                'name'                   => 'Testing',
109
                'redirect'               => 'http://localhost',
110
                'password_client'        => '1',
111
                'personal_access_client' => '0',
112
                'revoked'                => '0',
113
            ],
114
        ]);
115
116
        // make the clients credentials available as env variables
117
        Config::set('authentication-container.clients.web.admin.id', $clientId);
118
        Config::set('authentication-container.clients.web.admin.secret', $clientSecret);
119
120
        // create testing oauth keys files
121
        $publicFilePath = $this->createTestingKey('oauth-public.key');
122
        $privateFilePath = $this->createTestingKey('oauth-private.key');
123
124
        $response = $this->makeCall($data);
125
126
        if (Config::get('authentication-container.require_email_confirmation')) {
127
            $response->assertStatus(409);
128
        } else {
129
            $response->assertStatus(200);
130
        }
131
132
        // delete testing keys files if they were created for this test
133
        if ($this->testingFilesCreated) {
134
            unlink($publicFilePath);
135
            unlink($privateFilePath);
136
        }
137
    }
138
139
    public function testLoginWithNameAttribute()
140
    {
141
        // create data to be used for creating the testing user and to be sent with the post request
142
        $data = [
143
            'email'    => '[email protected]',
144
            'password' => 'testingpass',
145
            'name'     => 'username',
146
        ];
147
148
        $user = $this->getTestingUser($data);
149
        $this->actingAs($user, 'web');
150
151
        $clientId = '100';
152
        $clientSecret = 'XXp8x4QK7d3J9R7OVRXWrhc19XPRroHTTKIbY8XX';
153
154
        // create client
155
        DB::table('oauth_clients')->insert([
156
            [
157
              'id'                     => $clientId,
158
              'secret'                 => $clientSecret,
159
              'name'                   => 'Testing',
160
              'redirect'               => 'http://localhost',
161
              'password_client'        => '1',
162
              'personal_access_client' => '0',
163
              'revoked'                => '0',
164
            ],
165
        ]);
166
167
        // make the clients credentials available as env variables
168
        Config::set('authentication-container.clients.web.admin.id', $clientId);
169
        Config::set('authentication-container.clients.web.admin.secret', $clientSecret);
170
171
        // specifically allow to login with "name" attribute
172
        Config::set('authentication-container.login.attributes',
173
            [
174
              'email' => ['email'],
175
              'name' => [],
176
            ]
177
        );
178
179
        // create testing oauth keys files
180
        $publicFilePath = $this->createTestingKey('oauth-public.key');
181
        $privateFilePath = $this->createTestingKey('oauth-private.key');
182
183
        $request = [
184
            'password' => 'testingpass',
185
            'name'     => 'username',
186
        ];
187
188
        $response = $this->makeCall($request);
189
190
        $response->assertStatus(200);
191
192
        $this->assertResponseContainKeyValue([
193
            'token_type' => 'Bearer',
194
        ]);
195
196
        $this->assertResponseContainKeys(['expires_in', 'access_token', 'refresh_token']);
197
198
        // delete testing keys files if they were created for this test
199
        if ($this->testingFilesCreated) {
200
          unlink($publicFilePath);
201
          unlink($privateFilePath);
202
        }
203
    }
204
205
    /**
206
     * @param $fileName
207
     *
208
     * @return  string
209
     */
210 View Code Duplication
    private function createTestingKey($fileName)
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...
211
    {
212
        $filePath = storage_path($fileName);
213
214
        if (!file_exists($filePath)) {
215
            $keysStubDirectory = __DIR__ . '/Stubs/';
216
217
            copy($keysStubDirectory . $fileName, $filePath);
218
219
            $this->testingFilesCreated = true;
220
        }
221
222
        return $filePath;
223
    }
224
}
225