Issues (164)

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.

test/JhFlexiTimeTest/ModuleTest.php (1 issue)

Labels
Severity

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 JhFlexiTimeTest;
4
5
use JhFlexiTime\Module;
6
use JhHubBase\Notification\NotificationService;
7
use JhUser\Entity\User;
8
use Zend\ServiceManager\ServiceManager;
9
10
/**
11
 * Class ModuleTest
12
 * @package JhFlexiTimeTest
13
 * @author Aydin Hassan <[email protected]>
14
 */
15
class ModuleTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    /**
19
     * @var \Zend\ServiceManager\ServiceManager
20
     */
21
    protected $serviceLocator;
22
    protected $sharedEvm;
23
24
    /**
25
     * @var \Zend\EventManager\EventManagerInterface|\PHPUnit_Framework_MockObject_MockObject
26
     */
27
    protected $eventManager;
28
29
    public function testGetConfig()
30
    {
31
        $module = new Module();
32
33
        $this->assertInternalType('array', $module->getConfig());
34
        $this->assertSame($module->getConfig(), unserialize(serialize($module->getConfig())), 'Config is serializable');
35
    }
36
37
    public function testGetAutoloaderConfig()
38
    {
39
        $module = new Module;
40
        $this->assertInternalType('array', $module->getAutoloaderConfig());
41
    }
42
43
    public function testListenersAreRegistered()
44
    {
45
        $event = $this->getEvent(true);
46
        $module = new Module();
47
48
        $bookingSaveListener = $this->getMockBuilder('JhFlexiTime\Listener\BookingSaveListener')
49
            ->disableOriginalConstructor()
50
            ->getMock();
51
52
        $this->serviceLocator->setService('JhFlexiTime\Listener\BookingSaveListener', $bookingSaveListener);
53
        $this->eventManager
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\EventManager\EventManagerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
54
            ->expects($this->at(0))
55
            ->method('attach')
56
            ->with($bookingSaveListener);
57
58
        $cappedCreditListener = $this->getMockBuilder('JhFlexiTime\Listener\CappedCreditListener')
59
            ->disableOriginalConstructor()
60
            ->getMock();
61
62
        $this->serviceLocator->setService('JhFlexiTime\Listener\CappedCreditListener', $cappedCreditListener);
63
        $this->eventManager
64
            ->expects($this->at(1))
65
            ->method('attach')
66
            ->with($cappedCreditListener);
67
68
        $this->sharedEvm
69
            ->expects($this->at(0))
70
            ->method('attach')
71
            ->with(
72
                'ScnSocialAuth\Authentication\Adapter\HybridAuth',
73
                'registerViaProvider.post',
74
                [$module, 'onRegister']
75
            );
76
77
        $this->sharedEvm
78
            ->expects($this->at(1))
79
            ->method('attach')
80
            ->with('ZfcUser\Service\User', 'register.post', [$module, 'onRegister']);
81
82
83
        $notificationService = new NotificationService;
84
        $this->serviceLocator->setService('JhHubBase\Notification\NotificationService', $notificationService);
85
        $this->serviceLocator->setService(
86
            'JhFlexiTime\NotificationHandler\MissedBookingEmailNotificationHandler',
87
            $this->getMock('JhHubBase\Notification\NotificationHandlerInterface')
88
        );
89
90
        $module->onBootstrap($event);
91
    }
92
93
    /**
94
     * @param bool $addEventManager
95
     * @return \PHPUnit_Framework_MockObject_MockObject
96
     */
97
    private function getEvent($addEventManager = false)
98
    {
99
        $this->serviceLocator = new ServiceManager();
100
        $this->eventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
101
        $application = $this->getMock('Zend\Mvc\Application', [], [], '', false);
102
103
        $application->expects($this->any())
104
            ->method('getServiceManager')
105
            ->will($this->returnValue($this->serviceLocator));
106
107
        if ($addEventManager) {
108
            $application->expects($this->any())
109
                ->method('getEventManager')
110
                ->will($this->returnValue($this->eventManager));
111
112
            $this->sharedEvm = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
113
            $this->eventManager
114
                ->expects($this->once())
115
                ->method('getSharedManager')
116
                ->will($this->returnValue($this->sharedEvm));
117
        }
118
119
        $event = $this->getMock('Zend\EventManager\EventInterface');
120
        $event->expects($this->any())->method('getTarget')->will($this->returnValue($application));
121
122
        return $event;
123
    }
124
125
    public function testConsoleUsage()
126
    {
127
        $mockConsole = $this->getMock('Zend\Console\Adapter\AdapterInterface');
128
        $module = new Module();
129
130
        $expected = [
131
            're-calc-balance-user <userEmail>' =>
132
                "Recalculate a User's running balance",
133
            're-calc-balance-all ' =>
134
                "Recalculate all User's running balance",
135
            'calc-prev-month-balance' =>
136
                "Calculate the previous month balance for all users and add it on to their running balance",
137
            'set user init-balance <userEmail> <balance>' =>
138
                "Set a user's starting balance",
139
            'notify-missing-bookings' =>
140
                'Send reminder e-mail to any user who has missed bookings for the period specified in the config'
141
        ];
142
        $this->assertSame($expected, $module->getConsoleUsage($mockConsole));
143
    }
144
145
    public function testUserIsInstalledOnRegister()
146
    {
147
        $event      = $this->getEvent();
148
        $user = new User();
149
        $event
150
            ->expects($this->once())
151
            ->method('getParam')
152
            ->with('user')
153
            ->will($this->returnValue($user));
154
155
        $installer  = $this->getMockBuilder('JhFlexiTime\Install\Installer')
156
            ->disableOriginalConstructor()
157
            ->getMock();
158
159
        $installer
160
            ->expects($this->once())
161
            ->method('createSettingsRow')
162
            ->with($user);
163
164
        $installer
165
            ->expects($this->once())
166
            ->method('createRunningBalanceRow')
167
            ->with($user);
168
169
        $this->serviceLocator->setService('JhFlexiTime\Install\Installer', $installer);
170
171
        $module = new Module();
172
        $module->onRegister($event);
173
    }
174
175
    public function testGetInstallService()
176
    {
177
        $module = new Module();
178
        $this->assertSame('JhFlexiTime\Install\Installer', $module->getInstallService());
179
    }
180
}
181