Issues (48)

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/Command/CreateOrganizationCommandTest.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
/*
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\MultiTenancyBundle\Tests\Command;
16
17
use PHPUnit\Framework\TestCase;
18
use SWP\Bundle\MultiTenancyBundle\Command\CreateOrganizationCommand;
19
use SWP\Component\MultiTenancy\Factory\OrganizationFactoryInterface;
20
use SWP\Component\MultiTenancy\Model\Organization;
21
use SWP\Component\MultiTenancy\Model\OrganizationInterface;
22
use SWP\Component\MultiTenancy\Repository\OrganizationRepositoryInterface;
23
use Symfony\Component\Console\Application;
24
use Symfony\Component\Console\Helper\QuestionHelper;
25
use Symfony\Component\Console\Tester\CommandTester;
26
27
class CreateOrganizationCommandTest extends TestCase
28
{
29
    private $commandTester;
30
31
    private $command;
32
33
    /**
34
     * @var QuestionHelper
35
     */
36
    private $question;
37
38
    public function setUp()
39
    {
40
        $application = new Application();
41
        $application->add(new CreateOrganizationCommand());
42
        $this->command = $application->get('swp:organization:create');
43
        $this->question = $this->command->getHelper('question');
44
    }
45
46
    /**
47
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\CreateOrganizationCommand
48
     */
49
    public function testExecuteWhenCreatingNewOrganization()
50
    {
51
        $organization = new Organization();
52
        $organization->setCode('123456');
53
        $this->command->setContainer($this->getMockContainer(null, $organization, 'Test'));
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Command\Command as the method setContainer() does only exist in the following sub-classes of Symfony\Component\Console\Command\Command: Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...Command\DoctrineCommand, Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...EntitiesDoctrineCommand, Doctrine\Bundle\Doctrine...tMappingDoctrineCommand, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, Symfony\Bundle\Framework...d\ContainerAwareCommand. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
54
        $this->commandTester = new CommandTester($this->command);
55
        $this->commandTester->setInputs(['Test']);
56
        $this->commandTester->execute(['command' => $this->command->getName()]);
57
58
        $this->assertEquals(
59
            'Please enter name:Organization Test (code: 123456) has been created and enabled!',
60
            trim($this->commandTester->getDisplay())
61
        );
62
    }
63
64
    /**
65
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\CreateOrganizationCommand
66
     */
67 View Code Duplication
    public function testExecuteWhenCreatingDefaultOrganization()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $organization = new Organization();
70
        $organization->setCode('123456');
71
        $this->command->setContainer($this->getMockContainer(null, $organization));
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Command\Command as the method setContainer() does only exist in the following sub-classes of Symfony\Component\Console\Command\Command: Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...Command\DoctrineCommand, Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...EntitiesDoctrineCommand, Doctrine\Bundle\Doctrine...tMappingDoctrineCommand, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, Symfony\Bundle\Framework...d\ContainerAwareCommand. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
72
        $this->commandTester = new CommandTester($this->command);
73
74
        $this->commandTester->execute([
75
            'command' => $this->command->getName(),
76
            '--default' => true,
77
        ]);
78
79
        $this->assertEquals(
80
            'Organization default (code: 123456) has been created and enabled!',
81
            trim($this->commandTester->getDisplay())
82
        );
83
    }
84
85
    /**
86
     * @expectedException \InvalidArgumentException
87
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\CreateOrganizationCommand
88
     */
89 View Code Duplication
    public function testExecuteWhenDefaultTenantExists()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
        $organization = new Organization();
92
        $organization->setCode('123456');
93
        $this->command->setContainer($this->getMockContainer($organization));
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Command\Command as the method setContainer() does only exist in the following sub-classes of Symfony\Component\Console\Command\Command: Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...Command\DoctrineCommand, Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...EntitiesDoctrineCommand, Doctrine\Bundle\Doctrine...tMappingDoctrineCommand, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, Symfony\Bundle\Framework...d\ContainerAwareCommand. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
94
        $this->commandTester = new CommandTester($this->command);
95
96
        $this->commandTester->execute([
97
            'command' => $this->command->getName(),
98
            '--default' => true,
99
        ]);
100
    }
101
102
    /**
103
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\CreateOrganizationCommand
104
     */
105
    public function testExecuteDisabledOrganization()
106
    {
107
        $organization = new Organization();
108
        $organization->setCode('123456');
109
        $this->command->setContainer($this->getMockContainer(null, $organization, 'Example'));
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Command\Command as the method setContainer() does only exist in the following sub-classes of Symfony\Component\Console\Command\Command: Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...Command\DoctrineCommand, Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...EntitiesDoctrineCommand, Doctrine\Bundle\Doctrine...tMappingDoctrineCommand, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, Symfony\Bundle\Framework...d\ContainerAwareCommand. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
110
        $this->commandTester = new CommandTester($this->command);
111
        $this->commandTester->setInputs(['Example']);
112
        $this->commandTester->execute([
113
            'command' => $this->command->getName(),
114
            '--disabled' => true,
115
        ]);
116
117
        $this->assertEquals(
118
            'Please enter name:Organization Example (code: 123456) has been created and disabled!',
119
            trim($this->commandTester->getDisplay())
120
        );
121
    }
122
123
    private function getMockContainer($mockOrganization = null, $mockedOrganizationInFactory = null, $name = OrganizationInterface::DEFAULT_NAME)
124
    {
125
        $mockRepo = $this->getMockBuilder(OrganizationRepositoryInterface::class)
126
            ->getMock();
127
128
        $mockRepo->expects($this->any())
129
            ->method('findOneByName')
130
            ->with($name)
131
            ->willReturn($mockOrganization);
132
133
        $mockDoctrine = $this
134
            ->getMockBuilder('Doctrine\ORM\EntityManager')
135
            ->disableOriginalConstructor()
136
            ->getMock();
137
138
        $mockDoctrine->expects($this->any())
139
            ->method('persist')
140
            ->will($this->returnValue(null));
141
        $mockDoctrine->expects($this->any())
142
            ->method('flush')
143
            ->will($this->returnValue(null));
144
145
        $mockFactory = $this->getMockBuilder(OrganizationFactoryInterface::class)
146
            ->getMock();
147
148
        $mockFactory->expects($this->any())
149
            ->method('createWithCode')
150
            ->willReturn($mockedOrganizationInFactory);
151
152
        $mockFactory->expects($this->any())
153
            ->method('create')
154
            ->willReturn(new Organization());
155
156
        $mockContainer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')
157
            ->getMock();
158
159
        $mockContainer->expects($this->any())
160
            ->method('get')
161
            ->will($this->returnValueMap([
162
                ['swp.object_manager.organization', 1, $mockDoctrine],
163
                ['swp.repository.organization', 1, $mockRepo],
164
                ['swp.factory.organization', 1, $mockFactory],
165
            ]));
166
167
        return $mockContainer;
168
    }
169
170
    /**
171
     * @param $input
172
     *
173
     * @return resource
174
     */
175 View Code Duplication
    protected function getInputStream($input)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177
        $stream = fopen('php://memory', 'r+', false);
178
        fwrite($stream, $input);
179
        rewind($stream);
180
181
        return $stream;
182
    }
183
}
184