Issues (245)

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/CommentsGridFieldActionTest.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 SilverStripe\Comments\Tests;
4
5
use SilverStripe\Comments\Admin\CommentAdmin;
6
use SilverStripe\Comments\Admin\CommentsGridField;
7
use SilverStripe\Comments\Admin\CommentsGridFieldAction;
8
use SilverStripe\Comments\Admin\CommentsGridFieldConfig;
9
use SilverStripe\Comments\Model\Comment;
10
use SilverStripe\Comments\Tests\Stubs\CommentableItem;
11
use SilverStripe\Control\Controller;
12
use SilverStripe\Dev\SapphireTest;
13
use SilverStripe\Forms\FieldList;
14
use SilverStripe\Forms\Form;
15
use SilverStripe\Forms\GridField\GridField;
16
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
17
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
18
use SilverStripe\ORM\ArrayList;
19
use SilverStripe\ORM\DataList;
20
use SilverStripe\ORM\DataObject;
21
22
class CommentsGridFieldActionTest extends SapphireTest
23
{
24
    protected $usesDatabase = true;
25
26
    protected static $extra_dataobjects = [
27
        CommentableItem::class,
28
    ];
29
30
    /** @var ArrayList */
31
    protected $list;
32
33
    /** @var GridField */
34
    protected $gridField;
35
36
    /** @var Form */
37
    protected $form;
38
39
    protected function setUp()
40
    {
41
        parent::setUp();
42
        $this->list = new DataList(Team::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SilverStripe\ORM\Da...dFieldTest\Team::class) of type object<SilverStripe\ORM\DataList> is incompatible with the declared type object<SilverStripe\ORM\ArrayList> of property $list.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction());
44
        $this->gridField = new CommentsGridField('testfield', 'testfield', $this->list, $config);
45
        $this->form = new Form(new CommentAdmin(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
46
    }
47
48
    public function testAugmentColumns()
49
    {
50
        $action = new CommentsGridFieldAction();
51
52
        // an entry called 'Actions' is added to the columns array
53
        $columns = array();
54
        $action->augmentColumns($this->gridField, $columns);
55
        $expected = array('Actions');
56
        $this->assertEquals($expected, $columns);
57
58
        $columns = array('Actions');
59
        $action->augmentColumns($this->gridField, $columns);
60
        $expected = array('Actions');
61
        $this->assertEquals($expected, $columns);
62
    }
63
64
    public function testGetColumnAttributes()
65
    {
66
        $action = new CommentsGridFieldAction();
67
        $record = new Comment();
68
        $attrs = $action->getColumnAttributes($this->gridField, $record, Comment::class);
69
        $this->assertEquals(array('class' => 'col-buttons'), $attrs);
70
    }
71
72
    public function testGetColumnMetadata()
73
    {
74
        $action = new CommentsGridFieldAction();
75
        $result = $action->getColumnMetadata($this->gridField, 'Actions');
76
        $this->assertEquals(array('title' => ''), $result);
77
        $result = $action->getColumnMetadata($this->gridField, 'SomethingElse');
78
        $this->assertNull($result);
79
    }
80
81
    public function testGetColumnsHandled()
82
    {
83
        $action = new CommentsGridFieldAction();
84
        $result = $action->getColumnsHandled($this->gridField);
85
        $this->assertEquals(array('Actions'), $result);
86
    }
87
88
    public function testGetColumnContent()
89
    {
90
        $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
91
        $action = new CommentsGridFieldAction();
92
        $record = new Comment();
93
        $record->Name = 'Name of commeter';
94
        $record->Comment = 'This is a comment';
95
        $record->write();
96
        $recordID = $record->ID;
97
        $html = $action->getColumnContent($this->gridField, $record, Comment::class);
98
        $this->assertContains('data-url="admin/comments/mockform/field/testfield', $html);
99
100
        $this->assertContains('value="Spam"', $html);
101
        $this->assertContains('id="action_CustomAction' . $recordID . 'Spam"', $html);
102
103
        $this->assertContains('value="Approve"', $html);
104
        $this->assertContains('id="action_CustomAction' . $recordID . 'Approve"', $html);
105
106
        // If marked as spam, only the approve button should be available
107
        $record->markSpam();
108
        $record->write();
109
        $html = $action->getColumnContent($this->gridField, $record, Comment::class);
110
        $this->assertContains('value="Approve"', $html);
111
        $this->assertNotContains('value="Spam"', $html);
112
113
        // If marked as spam, only the approve button should be available
114
        $record->markApproved();
115
        $record->write();
116
        $html = $action->getColumnContent($this->gridField, $record, Comment::class);
117
        $this->assertNotContains('value="Approve"', $html);
118
        $this->assertContains('value="Spam"', $html);
119
    }
120
121
    public function testGetActions()
122
    {
123
        $action = new CommentsGridFieldAction();
124
        $result = $action->getActions($this->gridField);
125
        $this->assertEquals(array('spam', 'approve'), $result);
126
    }
127
128
    public function testHandleAction()
129
    {
130
        $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
131
        $item = new CommentableItem;
132
        $item->write();
133
134
        $action = new CommentsGridFieldAction();
135
        $record = new Comment();
136
        $record->Name = 'Name of commenter';
137
        $record->Comment = 'This is a comment';
138
        $record->ParentID = $item->ID;
139
        $record->ParentClass = $item->class;
0 ignored issues
show
The property ParentClass does not exist on object<SilverStripe\Comments\Model\Comment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
The property class does not exist on object<SilverStripe\Comm...\Stubs\CommentableItem>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
140
        $record->write();
141
        $recordID = $record->ID;
142
        $arguments = array('RecordID' => $recordID);
143
        $data = array();
144
        $result = $action->handleAction($this->gridField, 'spam', $arguments, $data);
0 ignored issues
show
Are you sure the assignment to $result is correct as $action->handleAction($t...am', $arguments, $data) (which targets SilverStripe\Comments\Ad...dAction::handleAction()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
145
        $this->assertEquals(200, Controller::curr()->getResponse()->getStatusCode());
146
        $this->assertEquals(
147
            'Comment marked as spam.',
148
            Controller::curr()->getResponse()->getStatusDescription()
149
        );
150
        $record = DataObject::get_by_id(Comment::class, $recordID);
151
        $this->assertEquals(1, $record->Moderated);
152
        $this->assertEquals(1, $record->IsSpam);
153
154
        //getStatusDescription
155
        $result = $action->handleAction($this->gridField, 'approve', $arguments, $data);
0 ignored issues
show
Are you sure the assignment to $result is correct as $action->handleAction($t...ve', $arguments, $data) (which targets SilverStripe\Comments\Ad...dAction::handleAction()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
156
        $this->assertEquals(200, Controller::curr()->getResponse()->getStatusCode());
157
        $this->assertEquals(
158
            'Comment approved.',
159
            Controller::curr()->getResponse()->getStatusDescription()
160
        );
161
162
        $record = DataObject::get_by_id(Comment::class, $recordID);
163
        $this->assertEquals(1, $record->Moderated);
164
        $this->assertEquals(0, $record->IsSpam);
165
    }
166
}
167