Issues (2014)

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.

tests/Unit/Common/Http/Client/StreamClientTest.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 OAuthTest\Unit\Common\Http\Client;
4
5
use OAuth\Common\Http\Client\StreamClient;
6
use PHPUnit\Framework\TestCase;
7
8
class StreamClientTest extends TestCase
9
{
10
    public function testConstructCorrectInstance(): void
11
    {
12
        $client = new StreamClient();
13
14
        self::assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client);
15
    }
16
17
    /**
18
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
19
     */
20
    public function testRetrieveResponseThrowsExceptionOnGetRequestWithBody(): void
21
    {
22
        $this->expectException('\\InvalidArgumentException');
23
24
        $client = new StreamClient();
25
26
        $client->retrieveResponse(
27
            $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),
0 ignored issues
show
$this->createMock('\\OAu...tp\\Uri\\UriInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Http\Uri\UriInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
            'foo',
29
            [],
30
            'GET'
31
        );
32
    }
33
34
    /**
35
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
36
     */
37
    public function testRetrieveResponseThrowsExceptionOnGetRequestWithBodyMethodConvertedToUpper(): void
38
    {
39
        $this->expectException('\\InvalidArgumentException');
40
41
        $client = new StreamClient();
42
43
        $client->retrieveResponse(
44
            $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),
0 ignored issues
show
$this->createMock('\\OAu...tp\\Uri\\UriInterface') is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<OAuth\Common\Http\Uri\UriInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
            'foo',
46
            [],
47
            'get'
48
        );
49
    }
50
51
    /**
52
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
53
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
54
     */
55
    public function testRetrieveResponseDefaultUserAgent(): void
56
    {
57
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
58
        $endPoint->expects(self::any())
59
            ->method('getHost')
60
            ->willReturn('httpbin.org');
61
        $endPoint->expects(self::any())
62
            ->method('getAbsoluteUri')
63
            ->willReturn('http://httpbin.org/get');
64
65
        $client = new StreamClient();
66
67
        $response = $client->retrieveResponse(
68
            $endPoint,
69
            '',
70
            [],
71
            'get'
72
        );
73
74
        $response = json_decode($response, true);
75
76
        self::assertSame('PHPoAuthLib', $response['headers']['User-Agent']);
77
    }
78
79
    /**
80
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
81
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
82
     */
83
    public function testRetrieveResponseCustomUserAgent(): void
84
    {
85
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
86
        $endPoint->expects(self::any())
87
            ->method('getHost')
88
            ->willReturn('httpbin.org');
89
        $endPoint->expects(self::any())
90
            ->method('getAbsoluteUri')
91
            ->willReturn('http://httpbin.org/get');
92
93
        $client = new StreamClient('My Super Awesome Http Client');
94
95
        $response = $client->retrieveResponse(
96
            $endPoint,
97
            '',
98
            [],
99
            'get'
100
        );
101
102
        $response = json_decode($response, true);
103
104
        self::assertSame('My Super Awesome Http Client', $response['headers']['User-Agent']);
105
    }
106
107
    /**
108
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
109
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
110
     */
111
    public function testRetrieveResponseWithCustomContentType(): void
112
    {
113
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
114
        $endPoint->expects(self::any())
115
            ->method('getHost')
116
            ->willReturn('httpbin.org');
117
        $endPoint->expects(self::any())
118
            ->method('getAbsoluteUri')
119
            ->willReturn('http://httpbin.org/get');
120
121
        $client = new StreamClient();
122
123
        $response = $client->retrieveResponse(
124
            $endPoint,
125
            '',
126
            ['Content-Type' => 'foo/bar'],
127
            'get'
128
        );
129
130
        $response = json_decode($response, true);
131
132
        self::assertSame('foo/bar', $response['headers']['Content-Type']);
133
    }
134
135
    /**
136
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
137
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
138
     */
139
    public function testRetrieveResponseWithFormUrlEncodedContentType(): void
140
    {
141
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
142
        $endPoint->expects(self::any())
143
            ->method('getHost')
144
            ->willReturn('httpbin.org');
145
        $endPoint->expects(self::any())
146
            ->method('getAbsoluteUri')
147
            ->willReturn('http://httpbin.org/post');
148
149
        $client = new StreamClient();
150
151
        $response = $client->retrieveResponse(
152
            $endPoint,
153
            ['foo' => 'bar', 'baz' => 'fab'],
154
            [],
155
            'POST'
156
        );
157
158
        $response = json_decode($response, true);
159
160
        self::assertSame('application/x-www-form-urlencoded', $response['headers']['Content-Type']);
161
        self::assertEquals(['foo' => 'bar', 'baz' => 'fab'], $response['form']);
162
    }
163
164
    /**
165
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
166
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
167
     */
168
    public function testRetrieveResponseHost(): void
169
    {
170
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
171
        $endPoint->expects(self::any())
172
            ->method('getHost')
173
            ->willReturn('httpbin.org');
174
        $endPoint->expects(self::any())
175
            ->method('getAbsoluteUri')
176
            ->willReturn('http://httpbin.org/post');
177
178
        $client = new StreamClient();
179
180
        $response = $client->retrieveResponse(
181
            $endPoint,
182
            ['foo' => 'bar', 'baz' => 'fab'],
183
            [],
184
            'POST'
185
        );
186
187
        $response = json_decode($response, true);
188
189
        self::assertSame('httpbin.org', $response['headers']['Host']);
190
    }
191
192
    /**
193
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
194
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
195
     */
196
    public function testRetrieveResponsePostRequestWithRequestBodyAsString(): void
197
    {
198
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
199
        $endPoint->expects(self::any())
200
            ->method('getHost')
201
            ->willReturn('httpbin.org');
202
        $endPoint->expects(self::any())
203
            ->method('getAbsoluteUri')
204
            ->willReturn('http://httpbin.org/post');
205
206
        $formData = ['baz' => 'fab', 'foo' => 'bar'];
207
208
        $client = new StreamClient();
209
210
        $response = $client->retrieveResponse(
211
            $endPoint,
212
            $formData,
213
            [],
214
            'POST'
215
        );
216
217
        $response = json_decode($response, true);
218
219
        self::assertSame($formData, $response['form']);
220
    }
221
222
    /**
223
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
224
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
225
     */
226
    public function testRetrieveResponsePutRequestWithRequestBodyAsString(): void
227
    {
228
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
229
        $endPoint->expects(self::any())
230
            ->method('getHost')
231
            ->willReturn('httpbin.org');
232
        $endPoint->expects(self::any())
233
            ->method('getAbsoluteUri')
234
            ->willReturn('http://httpbin.org/put');
235
236
        $formData = ['baz' => 'fab', 'foo' => 'bar'];
237
238
        $client = new StreamClient();
239
240
        $response = $client->retrieveResponse(
241
            $endPoint,
242
            $formData,
243
            [],
244
            'PUT'
245
        );
246
247
        $response = json_decode($response, true);
248
249
        self::assertSame($formData, $response['form']);
250
    }
251
252
    /**
253
     * @covers \OAuth\Common\Http\Client\StreamClient::generateStreamContext
254
     * @covers \OAuth\Common\Http\Client\StreamClient::retrieveResponse
255
     */
256
    public function testRetrieveResponseThrowsExceptionOnInvalidRequest(): void
257
    {
258
        $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
259
260
        $endPoint = $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
261
        $endPoint->expects(self::any())
262
            ->method('getHost')
263
            ->willReturn('dskjhfckjhekrsfhkehfkreljfrekljfkre');
264
        $endPoint->expects(self::any())
265
            ->method('getAbsoluteUri')
266
            ->willReturn('dskjhfckjhekrsfhkehfkreljfrekljfkre');
267
268
        $client = new StreamClient();
269
270
        $response = $client->retrieveResponse(
271
            $endPoint,
272
            '',
273
            ['Content-Type' => 'foo/bar'],
274
            'get'
275
        );
276
277
        $response = json_decode($response, true);
278
279
        self::assertSame('foo/bar', $response['headers']['Content-Type']);
280
    }
281
}
282