Issues (2)

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/RootFolderTest.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 NetWerkstatt\FolderPerPage\Tests;
4
5
use Page;
6
use SilverStripe\Core\Config\Config;
7
use NetWerkstatt\FolderPerPage\Extensions\RootFolder;
8
use SilverStripe\Dev\SapphireTest;
9
10
/**
11
 * Tests for RootFolder extension
12
 */
13
class RootFolderTest extends SapphireTest
14
{
15
16
    protected static $fixture_file = 'RootFolderTest.yml';
17
18
    /**
19
     * Check if a folder is generated and saved when a page is saved.
20
     */
21
    public function testCreateFolder()
22
    {
23
        $page = Page::create();
24
        $this->assertEquals(0, $page->RootFolderID, 'a new Page should not have a folder yet');
25
26
        $page->Title = 'Create Page Test';
27
28
        $page->write();
29
30
        $this->assertNotEquals(0, $page->RootFolderID, 'a page should have a folder after saving');
31
32
        $folder = $page->RootFolder();
33
34
        $this->assertEquals($page->URLSegment, $folder->Name, 'Page URLSegment and Folder Title should be the same');
35
        $path = $root = Config::inst()->get(RootFolder::class, 'folder_root') . '/'
0 ignored issues
show
$root 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...
$path 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...
36
                . $page->URLSegment . '/';
37
38
        $this->assertEquals(
39
            'create-page-test',
40
            $folder->getTitle(),
41
            'folder should be named "create-page-test"'
42
        );
43
44
        $parentFolder = $folder->Parent();
45
        $this->assertEquals(
46
            Config::inst()->get(RootFolder::class, 'folder_root'),
47
            $parentFolder->getTitle(),
48
            'parent folder should be folder_root config'
49
        );
50
    }
51
52
    /**
53
     * Checks if the folder will be updated when saving a page and changing the URLSegment
54
     */
55
    public function testUpdateFolder()
56
    {
57
        $page1 = $this->objFromFixture('Page', 'page1');
58
        $folder = $page1->RootFolder();
59
60
        $this->assertEquals(
61
            $page1->URLSegment,
62
            $folder->getTitle(),
63
            'Page URLSegment and Folder Title should be the same'
64
        );
65
66
        $page1->URLSegment = 'updatedpage';
67
        $page1->write();
68
69
        $folder = $page1->RootFolder(); //reload folder after saving
70
        $this->assertEquals('updatedpage', $folder->getTitle(), 'Folder name should be updated after saving a page');
71
        $this->assertEquals(
72
            $page1->URLSegment,
73
            $folder->Name,
74
            'Page URLSegment and Folder Title should be the same, even after updating'
75
        );
76
    }
77
78
    /**
79
     * Checks if no folder is created for ignored page types, e.g. VirtualPage or ErrorPage
80
     */
81
    public function testIgnoredPageTypes()
82
    {
83
        $ignoredPageTypes = Config::inst()->get(RootFolder::class, 'ignored_classes');
84
85
        foreach ($ignoredPageTypes as $type) {
86
            $page = $type::create();
87
88
            $page->write();
89
            $this->assertEquals(
90
                0,
91
                $page->RootFolderID,
92
                'Ignored page type ' . $type . ' should not have a RootFolderID'
93
            );
94
        }
95
    }
96
97
    /**
98
     * Check if subpage's folder is a subfolder of parent page
99
     */
100
    public function testHierarchy()
101
    {
102
        $parent = $this->objFromFixture('Page', 'parentpage');
103
        $child = $this->objFromFixture('Page', 'subpage');
104
105
        //test if fixtures are set up properly
106
        $this->assertEquals($parent->ID, $child->ParentID, 'subpage should be a child of parentpage');
107
108
        $this->assertEquals(
109
            $parent->RootFolderID,
110
            $child->RootFolder()->ParentID,
111
            'rootfolder2 should be a child of rootfolder 1'
112
        );
113
114
        $newPage = Page::create();
115
        $newPage->ParentID = $parent->ID;
116
        $newPage->Title = 'Hierarchy Test';
117
        $newPage->urlSegment = 'hierarchy-test';
118
        $newPage->write();
119
120
        $this->assertEquals(
121
            $parent->RootFolderID,
122
            $newPage->RootFolder()->ParentID,
123
            'new folder should be a child of page1 folder'
124
        );
125
    }
126
127
    /**
128
     * Checks if getRootFolderName() works properly
129
     */
130
    public function testGetRootFolderName()
131
    {
132
        $parent = $this->objFromFixture('Page', 'parentpage');
133
        $child = $this->objFromFixture('Page', 'subpage');
134
135
        //test if fixtures are set up properly
136
        $this->assertEquals($parent->ID, $child->ParentID, 'subpage should be a child of parentpage');
137
138
        $this->assertStringEndsWith(
139
            $child->RootFolder()->Name . '/',
140
            $child->getRootFolderName(),
141
            'FolderName should be at the end of getRootFolderName()'
142
        );
143
144
        $root = Config::inst()->get(RootFolder::class, 'folder_root');
145
        $this->assertStringStartsWith(
146
            $root . '/' . $parent->RootFolder()->Name,
147
            $child->getRootFolderName(),
148
            'Parents FolderName should be at the beginning of getRootFolderName()'
149
        );
150
151
        $this->assertStringStartsWith(
152
            ASSETS_DIR,
153
            $child->getRootFolderName(false),
154
            'ASSETS_DIR should be at the beginning of getRootFolderName(false)'
155
        );
156
    }
157
158
    /**
159
     * Check if a duplicated page has a new folder applied
160
     */
161
    public function testDuplicatePage()
162
    {
163
        $page = $this->objFromFixture('Page', 'page1');
164
165
//        $this->assertFileExists($page->RootFolder()->getFullPath(),
166
//            'root folder of original page should exist on file system');
167
168
        $duplicatedPage = $page->duplicate(true);
169
170
        //we have to re-load the duplicated page, cause the RootFolder is set in onAfterWrite and the current
171
        //object is not aware of it
172
173
        $duplicatedPage = Page::get()->byID($duplicatedPage->ID);
174
175
        $this->assertNotEquals(
176
            $page->URLSegment,
177
            $duplicatedPage->URLSegment,
178
            'The duplicated page must not have the same urlsegment'
179
        );
180
        $this->assertNotEquals(
181
            $page->RootFolderID,
182
            $duplicatedPage->RootFolderID,
183
            'The duplicated page must not have the same root folder'
184
        );
185
186
//        $this->assertFileExists($page->RootFolder()->getFullPath(),
187
//            'root folder of original page should still exist on file system after duplication');
188
//        $this->assertFileExists($duplicatedPage->RootFolder()->getFullPath(),
189
//            'root folder of duplicated page should exist on file system');
190
    }
191
}
192