Issues (24)

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.

src/Testing/MakesApiRequests.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 Flugg\Responder\Testing;
4
5
use Flugg\Responder\Responder;
6
use Illuminate\Http\JsonResponse;
7
8
/**
9
 * A trait to be used by test case classes to give access to additional assertion methods.
10
 *
11
 * @package flugger/laravel-responder
12
 * @author  Alexander Tømmerås <[email protected]>
13
 * @license The MIT License
14
 */
15
trait MakesApiRequests
16
{
17
    /**
18
     * Assert that the response is a valid success response.
19
     *
20
     * @param  mixed $data
21
     * @param  int   $status
22
     * @return $this
23
     */
24 View Code Duplication
    protected function seeSuccess($data = null, $status = 200)
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...
25
    {
26
        $response = $this->seeSuccessResponse($data, $status);
27
        $this->seeSuccessData($response->getData(true)['data']);
28
29
        return $this;
30
    }
31
32
    /**
33
     * Assert that the response is a valid success response.
34
     *
35
     * @param  mixed $data
36
     * @param  int   $status
37
     * @return $this
38
     */
39 View Code Duplication
    protected function seeSuccessEquals($data = null, $status = 200)
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...
40
    {
41
        $response = $this->seeSuccessResponse($data, $status);
42
        $this->seeJsonEquals($response->getData(true));
43
44
        return $this;
45
    }
46
47
    /**
48
     * Assert that the response data contains the given structure.
49
     *
50
     * @param  mixed $data
51
     * @return $this
52
     */
53
    protected function seeSuccessStructure($data = null)
54
    {
55
        $this->seeJsonStructure([
56
            'data' => $data,
57
        ]);
58
59
        return $this;
60
    }
61
62
    /**
63
     * Assert that the response is a valid success response.
64
     *
65
     * @param  mixed $data
66
     * @param  int   $status
67
     * @return \Illuminate\Http\JsonResponse
68
     */
69
    protected function seeSuccessResponse($data = null, $status = 200): JsonResponse
70
    {
71
        $response = $this->app->make(Responder::class)->success($data, $status);
72
73
        $this->seeStatusCode($response->getStatusCode())->seeJson([
74
            'success' => true,
75
            'status' => $response->getStatusCode(),
76
        ])->seeJsonStructure(['data']);
77
78
        return $response;
79
    }
80
81
    /**
82
     * Assert that the response data contains given values.
83
     *
84
     * @param  mixed $data
85
     * @return $this
86
     */
87
    protected function seeSuccessData($data = null)
88
    {
89
        collect($data)->each(function ($value, $key) {
90
            if (is_array($value)) {
91
                $this->seeSuccessData($value);
92
            } else {
93
                $this->seeJson([$key => $value]);
94
            }
95
        });
96
97
        return $this;
98
    }
99
100
    /**
101
     * Decodes JSON response and returns the data.
102
     *
103
     * @param  string|array|null $attributes
104
     * @return array
105
     */
106
    protected function getSuccessData($attributes = null)
107
    {
108
        $rawData = $this->decodeResponseJson()['data'];
109
110
        if (is_null($attributes)) {
111
            return $rawData;
112
        } elseif (is_string($attributes)) {
113
            return array_get($rawData, $attributes);
114
        }
115
116
        $data = [];
117
118
        foreach ($attributes as $attribute) {
119
            $data[] = array_get($rawData, $attribute);
120
        }
121
122
        return $data;
123
    }
124
125
    /**
126
     * Assert that the response is a valid error response.
127
     *
128
     * @param  string   $error
129
     * @param  int|null $status
130
     * @return $this
131
     */
132
    protected function seeError(string $error, int $status = null)
133
    {
134
        if (! is_null($status)) {
135
            $this->seeStatusCode($status);
136
        }
137
138
        if ($this->app->config->get('responder.status_code')) {
139
            $this->seeJson([
140
                'status' => $status,
141
            ]);
142
        }
143
144
        return $this->seeJson([
145
            'success' => false,
146
        ])->seeJsonSubset([
147
            'error' => [
148
                'code' => $error,
149
            ],
150
        ]);
151
    }
152
153
    /**
154
     * Asserts that the status code of the response matches the given code.
155
     *
156
     * @param  int $status
157
     * @return $this
158
     */
159
    abstract protected function seeStatusCode($status);
160
161
    /**
162
     * Assert that the response contains JSON.
163
     *
164
     * @param  array|null $data
165
     * @param  bool       $negate
166
     * @return $this
167
     */
168
    abstract public function seeJson(array $data = null, $negate = false);
169
170
    /**
171
     * Assert that the JSON response has a given structure.
172
     *
173
     * @param  array|null $structure
174
     * @param  array|null $responseData
175
     * @return $this
176
     */
177
    abstract public function seeJsonStructure(array $structure = null, $responseData = null);
178
179
    /**
180
     * Assert that the response is a superset of the given JSON.
181
     *
182
     * @param  array $data
183
     * @return $this
184
     */
185
    abstract protected function seeJsonSubset(array $data);
186
187
    /**
188
     * Assert that the response contains an exact JSON array.
189
     *
190
     * @param  array $data
191
     * @return $this
192
     */
193
    abstract public function seeJsonEquals(array $data);
194
195
    /**
196
     * Validate and return the decoded response JSON.
197
     *
198
     * @return array
199
     */
200
    abstract protected function decodeResponseJson();
201
}
202