Issues (15)

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/TestCase/RequestTest.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
 * Created by PhpStorm.
4
 * User: lejla
5
 * Date: 2016.02.10.
6
 * Time: 17:51
7
 */
8
9
namespace CurlX\Tests;
10
11
use CurlX\Request;
12
use CurlX\RequestInterface;
13
use PHPUnit_Framework_TestCase;
14
15
class RequestTest extends PHPUnit_Framework_TestCase
16
{
17
    public function testUrl()
18
    {
19
        $request = new Request('http://url.com');
20
        $this->assertEquals('http://url.com', $request->url);
21
22
        $request->url = 'http://url2.com';
23
        $this->assertEquals('http://url2.com', $request->url);
24
25
        $request->url = 'badurl';
26
        $this->assertEquals('http://url2.com', $request->url);
27
    }
28
29
    public function testPostFieldsBuilder()
30
    {
31
        $request = new Request();
32
33
        // No post values yet, so it should default to GET
34
        $this->assertArrayNotHasKey(CURLOPT_POST, $request->options);
35
        $this->assertEmpty($request->post_data);
36
37
        // With post values
38
        $post = ['username' => 'mike', 'password' => 'pass'];
39
        $request->post_data = $post;
40
        $this->assertArrayHasKey(CURLOPT_POST, $request->options);
41
        $this->assertEquals($post, $request->post_data);
42
43
        // Add more post fields
44
        $post2 = ['otherdata' => 'newvalue', 'username' => 'stacey'];
45
        $request->post_data = $post2;
46
        $this->assertArrayHasKey(CURLOPT_POST, $request->options);
47
        $this->assertEquals($post2 + $post, $request->post_data);
48
    }
49
50
    public function testNotify()
51
    {
52
        $request = new Request();
53
        $called1 = false;
54
        $called2 = false;
55
        $r1 = null;
56
        $r2 = null;
57
58
        $request->addListener(function (RequestInterface $var) use (&$called1, &$r1) {
59
            $called1 = true;
60
            $r1 = $var;
61
        });
62
63
        $request->addListener(function (RequestInterface $var) use (&$called2, &$r2) {
64
            $called2 = true;
65
            $r2 = $var;
66
        });
67
68
        $request->callBack([]);
69
70
        $this->assertTrue($called1, 'Callback 1 was not notified on request completion!');
71
        $this->assertInstanceOf('CurlX\RequestInterface', $r1, 'Callback 1 did not receive the request object');
72
        $this->assertTrue($called2, 'Callback 2 was not notified on request completion!');
73
        $this->assertInstanceOf('CurlX\RequestInterface', $r2, 'Callback 2 did not receive the request object');
74
    }
75
76
    public function testHeaders()
77
    {
78
        $request = new Request();
79
80
        $header = ['a' => 'aaa', 'b' => 'bbb'];
81
        $normalHeader = ['a: aaa', 'b: bbb'];
82
83
        $request->headers = $header;
84
        $this->assertEquals($header, $request->headers);
85
86
        $this->assertArrayHasKey(CURLOPT_HTTPHEADER, $request->options);
87
        $this->assertEquals($normalHeader, $request->options[CURLOPT_HTTPHEADER]);
88
89
        $header2 = ['b' => 'BBB', 'c' => 'CCC'];
90
        $normalOfBothHeaders = ['b: BBB', 'c: CCC', 'a: aaa'];
91
        $request->headers = $header2;
92
        $this->assertEquals($header2 + $header, $request->headers);
93
94
        $this->assertArrayHasKey(CURLOPT_HTTPHEADER, $request->options);
95
        $this->assertArraySubset($normalOfBothHeaders, $request->options[CURLOPT_HTTPHEADER]);
96
    }
97
98
    public function testOptions()
99
    {
100
        $request = new Request();
101
102
        $opt = [CURLOPT_CRLF => 'test', CURLOPT_AUTOREFERER => 'test'];
103
        $request->options = $opt;
104
105
        $this->assertArrayHasKey(CURLOPT_CRLF, $request->options);
106
        $this->assertArrayHasKey(CURLOPT_AUTOREFERER, $request->options);
107
        $this->assertArraySubset($opt, $request->options);
108
109
        $opt2 = [CURLOPT_AUTOREFERER => 'no-test', CURLOPT_BINARYTRANSFER => 'no-test'];
110
        $request->options = $opt2;
111
112
        $this->assertArrayHasKey(CURLOPT_CRLF, $request->options);
113
        $this->assertArrayHasKey(CURLOPT_AUTOREFERER, $request->options);
114
        $this->assertArrayHasKey(CURLOPT_BINARYTRANSFER, $request->options);
115
        $this->assertArraySubset($opt2 + $opt, $request->options);
116
    }
117
118
    public function testHandle()
119
    {
120
        $request = new Request('http://example.com');
121
        $ch = $request->handle;
122
123
        $this->assertNotNull($ch);
124
        $info = curl_getinfo($ch);
125
126
        $this->assertEquals($request->url, $info['url']);
127
128
        // Test default cUrl options
129
        $this->assertArrayHasKey(CURLOPT_RETURNTRANSFER, $request->options);
130
        $this->assertEquals($request->options[CURLOPT_RETURNTRANSFER], true);
131
    }
132
133
    public function testClone()
134
    {
135
        // We make a Request object and set parameters
136
        $request = new Request('http://url.url');
137
        $request->addListener(function (RequestInterface $r) {
0 ignored issues
show
The parameter $r is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
138
        });
139
        $request->post_data = ['a' => 'a'];
140
        $request->headers = ['a' => 'a'];
141
        $request->timeout = 5;
142
        $request->options = [CURLOPT_BINARYTRANSFER => true];
143
144
        // We clone it, and overwrite the parameters
145
        $request2 = clone $request;
146
        $request2->url = 'http://url2.url2';
147
        $iWasCalled = false;
148
        $request2->addListener(function (RequestInterface $r) use (&$iWasCalled) {
0 ignored issues
show
The parameter $r is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
            $iWasCalled = true;
150
        });
151
        $request2->post_data = ['a' => 'A', 'b' => 'B'];
152
        $request2->headers = ['a' => 'A', 'b' => 'B'];
153
        $request2->timeout = 10;
154
        $request2->options = [CURLOPT_BINARYTRANSFER => false];
155
156
        // Modifying the new object should not change values of the original one
157
        $this->assertEquals('http://url.url', $request->url);
158
        $this->assertEquals(['a' => 'a'], $request->post_data);
159
        $this->assertEquals(['a' => 'a'], $request->headers);
160
        $this->assertEquals(5, $request->timeout);
161
        $this->assertArraySubset([CURLOPT_BINARYTRANSFER => true], $request->options);
162
163
        // Running the first Request should not notify the cloned Request's listeners
164
        $request->callBack([]);
165
        $this->assertFalse($iWasCalled);
166
    }
167
}
168