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/Captcha/CaptchaTest.php (7 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\Captcha;
4
5
use Koch\Captcha\Captcha;
6
7
class CaptchaTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var Captcha
11
     */
12
    protected $object;
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
        if (extension_loaded('gd') === false) {
21
            $this->markTestSkipped('This test requires the PHP extension "gd".');
22
        }
23
24
        // set captcha folder
25
        $options['captcha_dir'] = __DIR__;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
26
27
        $this->object = new Captcha($options);
28
    }
29
30
    /**
31
     * Tears down the fixture, for example, closes a network connection.
32
     * This method is called after a test is executed.
33
     */
34
    public function tearDown()
35
    {
36
    }
37
38
    public function testSetFontFolder()
39
    {
40
        // accepts string
41
        $this->object->setFontFolder('folder');
42
43
        $expectedFolders = $this->object->getFontFolders();
44
        // note:  $expected_folders[0] is the path to the framework's font folder
45
        $this->assertEquals('folder', $expectedFolders[1]);
46
47
        // accepts array
48
        $folders = ['folder/A', 'folder/B'];
49
50
        $this->object->setFontFolder($folders);
51
52
        $expectedFolders = array_merge($expectedFolders, $folders);
53
        $this->assertEquals($expectedFolders, $this->object->getFontFolders());
54
    }
55
56
    /**
57
     * @covers Koch\Captcha\Captcha::getRandomFont
58
     */
59
    public function testGetRandomFont()
60
    {
61
        $font = $this->object->getRandomFont();
62
63
        $this->assertContains('.ttf', $font);
64
    }
65
66
    /**
67
     * @covers Koch\Captcha\Captcha::generateRandomString
68
     */
69
    public function testGenerateRandomString()
70
    {
71
        $length       = 5;
72
        $randomString = $this->object->generateRandomString($length);
73
74
        // test valid chars, length, excluded chars
75
        $constraint = $this->logicalAnd(
76
            $this->isType('string'), $this->matchesRegularExpression('/[a-zA-Z0-9]{5}/i'), $this->logicalNot(
77
                $this->matchesRegularExpression('/[017IO]/') // not case-[i]nsensitve
78
            )
79
        );
80
        $this->assertThat($randomString, $constraint);
81
82
        // silly random test
83
        $this->assertNotEquals($randomString, $this->object->generateRandomString($length));
84
    }
85
86
    /**
87
     * @covers Koch\Captcha\Captcha::generateCaptchaImage
88
     */
89
    public function testGenerateCaptchaImage()
90
    {
91
        $font = $this->object->getRandomFont();
92
        $this->object->setFont($font);
93
94
        // base64 embedded captcha image
95
        $result = $this->object->generateCaptchaImage();
96
        $this->assertContains(
97
            '<img alt="Embedded Captcha Image" src="data:image/png;base64,', $result
98
        );
99
    }
100
101
    /**
102
     * @covers Koch\Captcha\Captcha::render
103
     */
104
    public function testRender()
105
    {
106
        // lets generate a simple image
107
        $image      = imagecreatetruecolor(120, 20);
108
        $text_color = imagecolorallocate($image, 233, 14, 91);
0 ignored issues
show
$text_color 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...
109
        imagestring($image, 1, 5, 5, 'A Text String', $text_color);
0 ignored issues
show
$text_color 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...
110
111
        // lets pretend that this is the generated captcha
112
        $this->object->captcha = $image;
113
114
        // now test output methods
115
116
        /* @todo
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
117
          $render_type = 'file';
118
          $this->object->render($render_type);
119
         */
120
121
        $render_type = 'base64';
0 ignored issues
show
$render_type 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...
122
        $result      = $this->object->render($render_type);
0 ignored issues
show
$render_type 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...
123
        $this->assertContains(
124
            '<img alt="Embedded Captcha Image" src="data:image/png;base64,', $result
125
        );
126
127
        /* @todo
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
128
          $render_type = 'png';
129
          $this->object->render($render_type);
130
         */
131
    }
132
133
    /**
134
     * @covers Koch\Captcha\Captcha::collectGarbage
135
     */
136
    public function testCollectGarbage()
137
    {
138
        $this->assertTrue($this->object->collectGarbage());
139
    }
140
}
141