Issues (399)

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/DMSTest.php (20 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
class DMSTest extends FunctionalTest
3
{
4
    protected static $fixture_file = 'dmstest.yml';
5
6
    /**
7
     * Stub PDF files for testing
8
     *
9
     * @var string
10
     */
11
    public static $testFile = 'dms/tests/DMS-test-lorum-file.pdf';
12
    public static $testFile2 = 'dms/tests/DMS-test-document-2.pdf';
13
14
    /**
15
     * The test folder to write assets into
16
     *
17
     * @var string
18
     */
19
    protected $testDmsPath = 'assets/_dms-assets-test-1234';
20
21
    /**
22
     * @var DMSInterace
23
     */
24
    protected $dms;
25
26
    /**
27
     * Use a test DMS folder, so we don't overwrite the live one, and clear it out in case of previous broken tests
28
     *
29
     * {@inheritDoc}
30
     */
31
    public function setUp()
32
    {
33
        parent::setUp();
34
        Config::inst()->update('DMS', 'folder_name', $this->testDmsPath);
35
        DMSFilesystemTestHelper::delete($this->testDmsPath);
36
        $this->dms = DMS::inst();
0 ignored issues
show
Documentation Bug introduced by
It seems like \DMS::inst() of type object<DMSInterface> is incompatible with the declared type object<DMSInterace> of property $dms.

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...
37
    }
38
39
    /**
40
     * Delete the test folder after the test runs
41
     *
42
     * {@inheritDoc}
43
     */
44
    public function tearDown()
45
    {
46
        parent::tearDown();
47
        DMSFilesystemTestHelper::delete($this->testDmsPath);
48
    }
49
50
    public function testDMSStorage()
51
    {
52
        $file = self::$testFile;
53
        $document = $this->dms->storeDocument($file);
54
55
        $this->assertNotNull($document, "Document object created");
0 ignored issues
show
The method assertNotNull() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
        $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
            file_exists(
58
                DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder
59
                . DIRECTORY_SEPARATOR . $document->Filename
60
            ),
61
            "Document file copied into DMS folder"
62
        );
63
    }
64
65
    public function testDMSFolderSpanning()
66
    {
67
        Config::inst()->update('DMS', 'folder_size', 5);
68
        $file = self::$testFile;
69
70
        $documents = array();
71
        for ($i = 0; $i <= 16; $i++) {
72
            $document = $this->dms->storeDocument($file);
73
            $this->assertNotNull($document, "Document object created on run number: $i");
0 ignored issues
show
The method assertNotNull() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
            $this->assertTrue(file_exists($document->getFullPath()));
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
            $documents[] = $document;
76
        }
77
78
        // Test document objects have their folders set
79
        $folders = array();
80
        for ($i = 0; $i <= 16; $i++) {
81
            $folderName = $documents[$i]->Folder;
82
            $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
                strpos($documents[$i]->getFullPath(), DIRECTORY_SEPARATOR . $folderName . DIRECTORY_SEPARATOR) !== false,
84
                "Correct folder name for the documents. Document path contains reference to folder name '$folderName'"
85
            );
86
            $folders[] = $folderName;
87
        }
88
89
        // Test we created 4 folder to contain the 17 files
90
        foreach ($folders as $f) {
91
            $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
                is_dir(DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $f),
93
                "Document folder '$f' exists"
94
            );
95
        }
96
    }
97
98
    public function testReplaceDocument()
99
    {
100
        // Store the first document
101
        $document = $this->dms->storeDocument(self::$testFile);
102
        $document->Title = "My custom title";
103
        $document->Description = "My custom description";
104
        $document->write();
105
106
        // Then overwrite with a second document
107
        $document = $document->replaceDocument(self::$testFile2);
108
109
        $this->assertNotNull($document, "Document object created");
0 ignored issues
show
The method assertNotNull() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
        $this->assertTrue(
0 ignored issues
show
The method assertTrue() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
            file_exists(
112
                DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder
113
                . DIRECTORY_SEPARATOR . $document->Filename
114
            ),
115
            "Document file copied into DMS folder"
116
        );
117
        $this->assertContains(
118
            "DMS-test-document-2",
119
            $document->Filename,
120
            "Original document filename is contain in the new filename"
121
        );
122
        $this->assertEquals("My custom title", $document->Title, "Custom title not modified");
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
        $this->assertEquals("My custom description", $document->Description, "Custom description not modified");
0 ignored issues
show
The method assertEquals() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
    }
125
126
    /**
127
     * Test that documents can be returned by a given page
128
     */
129 View Code Duplication
    public function testGetByPageWithoutEmbargoes()
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...
130
    {
131
        $pageWithEmbargoes = $this->objFromFixture('SiteTree', 's3');
132
        $documents = $this->dms->getByPage($pageWithEmbargoes);
133
        // Fixture: 6 documents in set, 1 is embargoed
134
        $this->assertCount(5, $documents, 'Embargoed documents are excluded by default');
0 ignored issues
show
The method assertCount() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
135
        $this->assertContainsOnlyInstancesOf('DMSDocument', $documents);
0 ignored issues
show
The method assertContainsOnlyInstancesOf() does not exist on DMSTest. Did you maybe mean assertContains()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
136
    }
137
138
    /**
139
     * Test that embargoed documents are excluded from getByPage
140
     */
141 View Code Duplication
    public function testGetByPageWithEmbargoedDocuments()
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...
142
    {
143
        $pageWithEmbargoes = $this->objFromFixture('SiteTree', 's3');
144
        $documents = $this->dms->getByPage($pageWithEmbargoes, true);
145
        // Fixture: 6 documents in set, 1 is embargoed
146
        $this->assertCount(6, $documents, 'Embargoed documents can be included');
0 ignored issues
show
The method assertCount() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
        $this->assertContainsOnlyInstancesOf('DMSDocument', $documents);
0 ignored issues
show
The method assertContainsOnlyInstancesOf() does not exist on DMSTest. Did you maybe mean assertContains()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
148
    }
149
150
    /**
151
     * Ensure the shortcode handler key is configurable
152
     */
153
    public function testShortcodeHandlerKeyIsConfigurable()
154
    {
155
        Config::inst()->update('DMS', 'shortcode_handler_key', 'testing');
156
        $this->assertSame('testing', DMS::inst()->getShortcodeHandlerKey());
0 ignored issues
show
The method assertSame() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
157
    }
158
159
    /**
160
     * Test that document sets can be retrieved for a given page
161
     */
162
    public function testGetDocumentSetsByPage()
163
    {
164
        $page = $this->objFromFixture('SiteTree', 's1');
165
        $sets = $this->dms->getDocumentSetsByPage($page);
166
        $this->assertCount(2, $sets);
0 ignored issues
show
The method assertCount() does not seem to exist on object<DMSTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
        $this->assertContainsOnlyInstancesOf('DMSDocumentSet', $sets);
0 ignored issues
show
The method assertContainsOnlyInstancesOf() does not exist on DMSTest. Did you maybe mean assertContains()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
168
    }
169
170
    /**
171
     * Ensure that assets/* folders are not included in filesystem sync operations
172
     */
173
    public function testFolderExcludedFromFilesystemSync()
174
    {
175
        // Undo setup config changes
176
        Config::unnest();
177
        Config::nest();
178
179
        $result = Filesystem::config()->get('sync_blacklisted_patterns');
180
        $folderName = substr(DMS::config()->get('folder_name'), 7);
181
        $this->assertContains('/^' . $folderName . '$/i', $result);
182
    }
183
}
184