Issues (25)

Security Analysis    no request data  

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/Command/FactoryTest.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 SilverLeague\Console\Tests\Command;
4
5
use SilverLeague\Console\Command\Dev\Tasks\AbstractTaskCommand;
6
use SilverLeague\Console\Command\Factory;
7
use SilverLeague\Console\Framework\Scaffold;
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\Dev\Tasks\CleanupTestDatabasesTask;
11
use Symfony\Component\Console\Application;
12
use Symfony\Component\Console\Tester\CommandTester;
13
14
/**
15
 * @coversDefaultClass \SilverLeague\Console\Command\Factory
16
 * @package silverstripe-console
17
 * @author  Robbie Averill <[email protected]>
18
 */
19
class FactoryTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * Test that a Symfony command is bootstrapped and returned when a SilverStripe BuildTask is given
23
     */
24
    public function testGetCommandFromTask()
25
    {
26
        $task = new CleanupTestDatabasesTask;
27
28
        $command = $this->getFactory()->getCommandFromTask($task);
29
        $this->assertInstanceOf(AbstractTaskCommand::class, $command);
30
        $this->assertInstanceOf(Application::class, $command->getApplication());
31
        $this->assertSame($task, $command->getTask());
32
        $this->assertSame($task->getTitle(), $command->getDescription());
33
    }
34
35
    /**
36
     * Test that a SilverStrip task name is converted to a Symfony friendly command name
37
     *
38
     * @param string $input
39
     * @param string $expected
40
     * @dataProvider commandNameProvider
41
     */
42
    public function testGetCommandName($input, $expected)
43
    {
44
        Config::nest();
45
46
        $fakeTask = new CleanupTestDatabasesTask;
47
        Config::modify()->set(get_class($fakeTask), 'segment', $input);
48
        $this->assertSame($expected, $this->getFactory()->getCommandName($fakeTask));
49
50
        Config::unnest();
51
    }
52
53
    /**
54
     * @return array[]
55
     */
56
    public function commandNameProvider()
57
    {
58
        return [
59
            ['CleanupTestDatabasesTask', 'dev:tasks:cleanup-test-databases'],
60
            ['FooBar', 'dev:tasks:foo-bar'],
61
            ['FooBarTask', 'dev:tasks:foo-bar']
62
        ];
63
    }
64
65
    /**
66
     * Ensure that the BuildTask functionality can be returned as a closure for the Command
67
     */
68
    public function testGetTaskAsClosure()
69
    {
70
        $taskMock = $this
71
            ->getMockBuilder(CleanupTestDatabasesTask::class)
72
            ->setMethods(['run'])
73
            ->getMock();
74
75
        $taskMock
76
            ->expects($this->once())
77
            ->method('run')
78
            ->with($this->isInstanceOf(HTTPRequest::class));
79
80
        $factory = $this->getFactory();
81
        $command = $factory->getCommandFromTask($taskMock);
82
        $this->assertTrue(is_callable($factory->getTaskAsClosure($command)));
0 ignored issues
show
It seems like $command defined by $factory->getCommandFromTask($taskMock) on line 81 can also be of type false; however, SilverLeague\Console\Com...ory::getTaskAsClosure() does only seem to accept object<SilverLeague\Cons...ks\AbstractTaskCommand>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
83
84
        $tester = new CommandTester($command);
0 ignored issues
show
It seems like $command defined by $factory->getCommandFromTask($taskMock) on line 81 can also be of type false; however, Symfony\Component\Consol...ndTester::__construct() does only seem to accept object<Symfony\Component\Console\Command\Command>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
85
        $tester->execute([]);
86
    }
87
88
    /**
89
     * Ensure that SilverStripe task URL segments are made "friendly"
90
     *
91
     * @param string $input
92
     * @param string $expected
93
     * @dataProvider segmentProvider
94
     */
95
    public function testGetFriendlySegment($input, $expected)
96
    {
97
        $this->assertSame($expected, $this->getFactory()->getFriendlySegment($input));
98
    }
99
100
    /**
101
     * @return array[]
102
     */
103
    public function segmentProvider()
104
    {
105
        return [
106
            ['SomeTask', 'some'],
107
            ['Some\\Namespaced\\TaskName', 'some-namespaced-task-name'],
108
            ['CleanupTestDatabasesTask', 'cleanup-test-databases'],
109
        ];
110
    }
111
112
    /**
113
     * Get a Factory to test with
114
     *
115
     * @return Factory
116
     */
117
    protected function getFactory()
118
    {
119
        return (new Scaffold)->getSilverStripeLoader()->getCommandFactory();
120
    }
121
}
122