Issues (3098)

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/KochTest/Http/HttpResponseTest.php (4 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 KochTest\Http;
4
5
use Koch\Http\HttpResponse;
6
7
class HttpResponseTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var HttpResponse
11
     */
12
    protected $response;
13
14
    /**
15
     * Sets up the fixture, for example, opens a network connection.
16
     * This method is called before a test is executed.
17
     */
18
    public function setUp()
19
    {
20
        //$this->response = new HttpResponse;
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
    }
22
23
    /**
24
     * Tears down the fixture, for example, closes a network connection.
25
     * This method is called after a test is executed.
26
     */
27
    public function tearDown()
28
    {
29
        //unset($this->response);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
    }
31
32
    public function testProperty_DefaultStatusIs200()
0 ignored issues
show
function testProperty_DefaultStatusIs200() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
33
    {
34
        $this->assertEquals(200, HttpResponse::getStatusCode());
35
    }
36
37
    /**
38
     * @covers Koch\Http\HttpResponse::setStatusCode
39
     * @covers Koch\Http\HttpResponse::getStatusCode
40
     */
41
    public function testSetAndGetStatusCode()
42
    {
43
        $code = '200';
44
        HttpResponse::setStatusCode($code);
45
        $this->assertEquals($code, HttpResponse::getStatusCode());
46
    }
47
48
    public function testGetStatusCodeDescription()
49
    {
50
        $code = '200';
51
        $this->assertEquals('OK', HttpResponse::getStatusCodeDescription($code));
52
    }
53
54
    /**
55
     * @covers Koch\Http\HttpResponse::setContent
56
     * @covers Koch\Http\HttpResponse::getContent
57
     */
58
    public function testSetContent()
59
    {
60
        $content = 'Some Content. This is the response body.';
61
        HttpResponse::setContent($content);
62
        $this->assertEquals($content, HttpResponse::getContent());
63
64
        // append content
65
        $content2 = 'Some additional content to test appending.';
66
        HttpResponse::setContent($content2);
67
        $this->assertEquals($content . $content2, HttpResponse::getContent());
68
69
        // replace content
70
        $content3 = ' This new Content replaces the old content.';
71
        HttpResponse::setContent($content3, true);
72
        $this->assertEquals($content3, HttpResponse::getContent());
73
    }
74
75
    /**
76
     * @covers Koch\Http\HttpResponse::setContentType
77
     * @covers Koch\Http\HttpResponse::getContentType
78
     */
79
    public function testSetAndGetContentType()
80
    {
81
        // default type
82
        $this->assertEquals('text/html', HttpResponse::getContentType());
83
84
        HttpResponse::setContentType('xml');
85
        $this->assertEquals('application/xml', HttpResponse::getContentType());
86
    }
87
88
    /**
89
     * @covers Koch\Http\HttpResponse::setContentType
90
     * @expectedException InvalidArgumentException
91
     * @expectedExceptionMessage Specified type not valid. Use: html, txt, xml or json.
92
     */
93
    public function testSetContentType_throws()
0 ignored issues
show
function testSetContentType_throws() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
94
    {
95
        HttpResponse::setContentType('SomeInvalidType');
96
    }
97
98
    /**
99
     * @covers Koch\Http\HttpResponse::addHeader
100
     */
101
    public function testAddHeader()
102
    {
103
        $name  = 'TestName';
104
        $value = 'TestValue';
105
        HttpResponse::addHeader($name, $value);
106
107
        $this->assertArrayHasKey($name,  self::reflectProperty('headers')->getValue());
108
    }
109
110
    /**
111
     * ReflectProperty reflects a class property,
112
     * changing its scope to public.
113
     * This is used to access and test private properties
114
     * for which no getters are implemented in the public api.
115
     *
116
     * @param string $name Property name.
117
     *
118
     * @return \ReflectionProperty
119
     */
120
    protected static function reflectProperty($name)
121
    {
122
        $class  = new \ReflectionClass('Koch\Http\HttpResponse');
123
        $method = $class->getProperty($name);
124
        $method->setAccessible(true);
125
126
        return $method;
127
    }
128
129
    /**
130
     * @covers Koch\Http\HttpResponse::addHeader
131
     * @covers Koch\Http\HttpResponse::setContent
132
     * @covers Koch\Http\HttpResponse::clearHeaders
133
     * @covers Koch\Http\HttpResponse::getContent
134
     */
135
    public function testClearHeaders()
136
    {
137
        HttpResponse::addHeader('SomeHeader', 'SomeValue');
138
        HttpResponse::setContent('Some Content.');
139
140
        $this->assertTrue(HttpResponse::clearHeaders());
141
142
        $this->assertArrayNotHasKey('SomeHeader',  self::reflectProperty('headers')->getValue());
143
        $this->assertNull(HttpResponse::getContent());
144
    }
145
146
    public function testSetNoCacheHeader()
147
    {
148
        HttpResponse::setNoCacheHeader();
149
150
        $this->assertArrayHasKey('Pragma', self::reflectProperty('headers')->getValue());
151
        $this->assertArrayHasKey('Cache-Control', self::reflectProperty('headers')->getValue());
152
        $this->assertArrayHasKey('Expires',  self::reflectProperty('headers')->getValue());
153
        $this->assertArrayHasKey('Last-Modified', self::reflectProperty('headers')->getValue());
154
    }
155
156
    public function testSendResponse()
157
    {
158
        $content = 'Some Body';
159
        HttpResponse::setContent($content);
160
        HttpResponse::addHeader('Header', 'Content');
161
        HttpResponse::addHeader('Header2', 'Content2');
162
163
        ob_start();
164
        HttpResponse::sendResponse();
165
        $result = ob_get_clean();
166
167
        $this->assertEquals($content, $result);
168
    }
169
}
170