Issues (6)

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/CronTaskControllerTest.php (1 issue)

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 SilverStripe\CronTask\Tests;
4
5
use Cron\CronExpression;
6
use SilverStripe\CronTask\Controllers\CronTask;
7
use SilverStripe\CronTask\Controllers\CronTaskController;
8
use SilverStripe\CronTask\CronTaskStatus;
9
use SilverStripe\Dev\FunctionalTest;
10
use SilverStripe\ORM\FieldType\DBDate;
11
use SilverStripe\ORM\FieldType\DBDatetime;
12
13
/**
14
 * @package crontask
15
 */
16
class CronTaskControllerTest extends FunctionalTest
17
{
18
    /**
19
     * {@inheritDoc}
20
     * @var bool
21
     */
22
    protected $usesDatabase = true;
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected function setUp()
28
    {
29
        parent::setUp();
30
        CronTaskTest\TestCron::$times_run = 0;
31
    }
32
33
    /**
34
     * Tests CronTaskController::isTaskDue
35
     */
36
    public function testIsTaskDue()
37
    {
38
        $runner = CronTaskController::create();
39
        $task = new CronTaskTest\TestCron();
40
        $cron = CronExpression::factory($task->getSchedule());
41
42
        // Assuming first run, match the exact time (seconds are ignored)
43
        DBDatetime::set_mock_now('2010-06-20 13:00:10');
44
        $this->assertTrue($runner->isTaskDue($task, $cron));
45
46
        // Assume first run, do not match time just before or just after schedule
47
        DBDatetime::set_mock_now('2010-06-20 13:01:10');
48
        $this->assertFalse($runner->isTaskDue($task, $cron));
49
        DBDatetime::set_mock_now('2010-06-20 12:59:50');
50
        $this->assertFalse($runner->isTaskDue($task, $cron));
51
52
        // Mock a run and test that subsequent runs are properly scheduled
53
        DBDatetime::set_mock_now('2010-06-20 13:30:10');
54
        CronTaskStatus::update_status('SilverStripe\\CronTask\\Tests\\CronTaskTest\\TestCron', true);
55
56
        // Job prior to next hour mark should not run
57
        DBDatetime::set_mock_now('2010-06-20 13:40:00');
58
        $this->assertFalse($runner->isTaskDue($task, $cron));
59
60
        // Jobs just after the next hour mark should run
61
        DBDatetime::set_mock_now('2010-06-20 14:10:00');
62
        $this->assertTrue($runner->isTaskDue($task, $cron));
63
64
        // Jobs somehow delayed a whole day should be run
65
        DBDatetime::set_mock_now('2010-06-21 13:40:00');
66
        $this->assertTrue($runner->isTaskDue($task, $cron));
67
    }
68
69
    /**
70
     * Test CronTaskController::runTask
71
     */
72
    public function testRunTask()
73
    {
74
        $runner = CronTaskController::create();
75
        $runner->setQuiet(true);
0 ignored issues
show
Deprecated Code introduced by
The method SilverStripe\CronTask\Co...kController::setQuiet() has been deprecated with message: Use setVerbosity instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
        $task = new CronTaskTest\TestCron();
77
78
        // Assuming first run, match the exact time (seconds are ignored)
79
        $this->assertEquals(0, CronTaskTest\TestCron::$times_run);
80
        DBDatetime::set_mock_now('2010-06-20 13:00:10');
81
        $runner->runTask($task);
82
        $this->assertEquals(1, CronTaskTest\TestCron::$times_run);
83
84
        // Test that re-requsting the task in the same minute do not retrigger another run
85
        DBDatetime::set_mock_now('2010-06-20 13:00:40');
86
        $runner->runTask($task);
87
        $this->assertEquals(1, CronTaskTest\TestCron::$times_run);
88
89
        // Job prior to next hour mark should not run
90
        DBDatetime::set_mock_now('2010-06-20 13:40:00');
91
        $runner->runTask($task);
92
        $this->assertEquals(1, CronTaskTest\TestCron::$times_run);
93
94
        // Jobs just after the next hour mark should run
95
        DBDatetime::set_mock_now('2010-06-20 14:10:00');
96
        $runner->runTask($task);
97
        $this->assertEquals(2, CronTaskTest\TestCron::$times_run);
98
99
        // Jobs run on the exact next expected date should run
100
        DBDatetime::set_mock_now('2010-06-20 15:00:00');
101
        $runner->runTask($task);
102
        $this->assertEquals(3, CronTaskTest\TestCron::$times_run);
103
104
        // Jobs somehow delayed a whole day should be run
105
        DBDatetime::set_mock_now('2010-06-21 13:40:00');
106
        $runner->runTask($task);
107
        $this->assertEquals(4, CronTaskTest\TestCron::$times_run);
108
    }
109
110
111
    // normal cron output includes the current date/time - we check for that
112
    // the exact output here could vary depending on what other modules are installed
113
    public function testDefaultQuietFlagOutput()
114
    {
115
        $this->loginWithPermission('ADMIN');
116
        $this->expectOutputRegex('#' . DBDatetime::now()->Format(DBDate::ISO_DATE) . '#');
117
        $this->get('dev/cron?debug=1');
118
    }
119
120
    // with the flag set we want no output
121
    public function testQuietFlagOnOutput()
122
    {
123
        $this->loginWithPermission('ADMIN');
124
        $this->expectOutputString('');
125
        $this->get('dev/cron?quiet=1');
126
    }
127
}
128