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/DMSEmbargoTest.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
class DMSEmbargoTest extends SapphireTest
3
{
4
    protected static $fixture_file = 'dmsembargotest.yml';
5
6
    public function createFakeHTTPRequest($id)
7
    {
8
        $r = new SS_HTTPRequest('GET', 'index/'.$id);
9
        $r->match('index/$ID');
10
        return $r;
11
    }
12
13
    public function testBasicEmbargo()
14
    {
15
        $oldTestMode = DMSDocument_Controller::$testMode;
16
        Config::inst()->update('DMS', 'folder_name', 'assets/_unit-test-123');
17
18
        $doc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
19
        $doc->CanViewType = 'LoggedInUsers';
20
        $docID = $doc->write();
21
22
        //fake a request for a document
23
        $controller = new DMSDocument_Controller();
24
        DMSDocument_Controller::$testMode = true;
25
        $result = $controller->index($this->createFakeHTTPRequest($docID));
26
        $this->assertEquals($doc->getFullPath(), $result, 'Correct underlying file returned (in test mode)');
27
28
        $doc->embargoIndefinitely();
29
30
        $this->logInWithPermission('ADMIN');
31
        $result = $controller->index($this->createFakeHTTPRequest($docID));
32
        $this->assertEquals($doc->getFullPath(), $result, 'Admins can still download embargoed files');
33
34
        $this->logInWithPermission('random-user-group');
35
        $result = $controller->index($this->createFakeHTTPRequest($docID));
36
        $this->assertNotEquals(
37
            $doc->getFullPath(),
38
            $result,
39
            'File no longer returned (in test mode) when switching to other user group'
40
        );
41
42
        DMSDocument_Controller::$testMode = $oldTestMode;
43
        DMSFilesystemTestHelper::delete('assets/_unit-test-123');
44
    }
45
46
    public function testEmbargoIndefinitely()
47
    {
48
        $doc = new DMSDocument();
49
        $doc->Filename = "DMS-test-lorum-file.pdf";
50
        $doc->Folder = "tests";
51
        $doc->write();
52
53
        $doc->embargoIndefinitely();
54
        $this->assertTrue($doc->isHidden(), "Document is hidden");
55
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
56
        $this->assertFalse($doc->isExpired(), "Document is not expired");
57
58
        $doc->clearEmbargo();
59
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
60
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
61
        $this->assertFalse($doc->isExpired(), "Document is not expired");
62
    }
63
64 View Code Duplication
    public function testExpireAtDate()
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...
65
    {
66
        $doc = new DMSDocument();
67
        $doc->Filename = "DMS-test-lorum-file.pdf";
68
        $doc->Folder = "tests";
69
        $doc->write();
70
71
        $doc->expireAtDate(strtotime('-1 second'));
72
        $this->assertTrue($doc->isHidden(), "Document is hidden");
73
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
74
        $this->assertTrue($doc->isExpired(), "Document is expired");
75
76
        $expireTime = "2069-12-12 17:10:13";
77
        $doc->expireAtDate($expireTime);
78
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
79
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
80
        $this->assertFalse($doc->isExpired(), "Document is not expired");
81
82
        SS_Datetime::set_mock_now($expireTime);
83
        $this->assertTrue($doc->isHidden(), "Document is hidden");
84
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
85
        $this->assertTrue($doc->isExpired(), "Document is expired");
86
        SS_Datetime::clear_mock_now();
87
88
        $doc->expireAtDate(strtotime('-1 second'));
89
        $this->assertTrue($doc->isHidden(), "Document is hidden");
90
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
91
        $this->assertTrue($doc->isExpired(), "Document is expired");
92
93
        $doc->clearExpiry();
94
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
95
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
96
        $this->assertFalse($doc->isExpired(), "Document is not expired");
97
    }
98
99 View Code Duplication
    public function testEmbargoUntilDate()
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...
100
    {
101
        $doc = new DMSDocument();
102
        $doc->Filename = "DMS-test-lorum-file.pdf";
103
        $doc->Folder = "tests";
104
        $doc->write();
105
106
        $doc->embargoUntilDate(strtotime('+1 minute'));
107
        $this->assertTrue($doc->isHidden(), "Document is hidden");
108
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
109
110
        $this->assertFalse($doc->isExpired(), "Document is not expired");
111
112
        $doc->embargoUntilDate(strtotime('-1 second'));
113
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
114
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
115
        $this->assertFalse($doc->isExpired(), "Document is not expired");
116
117
        $embargoTime = "2069-12-12 17:10:13";
118
        $doc->embargoUntilDate($embargoTime);
119
        $this->assertTrue($doc->isHidden(), "Document is hidden");
120
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
121
        $this->assertFalse($doc->isExpired(), "Document is not expired");
122
123
        SS_Datetime::set_mock_now($embargoTime);
124
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
125
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
126
        $this->assertFalse($doc->isExpired(), "Document is not expired");
127
128
        SS_Datetime::clear_mock_now();
129
130
        $doc->clearEmbargo();
131
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
132
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
133
        $this->assertFalse($doc->isExpired(), "Document is not expired");
134
    }
135
136
    public function testEmbargoUntilPublished()
137
    {
138
        $s1 = $this->objFromFixture('SiteTree', 's1');
139
140
        $doc = new DMSDocument();
141
        $doc->Filename = "test file";
142
        $doc->Folder = "0";
143
        $dID = $doc->write();
144
145
        $s1->getDocumentSets()->first()->getDocuments()->add($doc);
146
147
        $s1->publish('Stage', 'Live');
148
        $s1->doPublish();
149
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
150
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
151
        $this->assertFalse($doc->isExpired(), "Document is not expired");
152
153
        $doc->embargoUntilPublished();
154
        $this->assertTrue($doc->isHidden(), "Document is hidden");
155
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
156
        $this->assertFalse($doc->isExpired(), "Document is not expired");
157
158
        $s1->publish('Stage', 'Live');
159
        $s1->doPublish();
160
        $doc = DataObject::get_by_id("DMSDocument", $dID);
161
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
162
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
163
        $this->assertFalse($doc->isExpired(), "Document is not expired");
164
165
        $doc->embargoUntilPublished();
166
        $doc = DataObject::get_by_id("DMSDocument", $dID);
167
        $this->assertTrue($doc->isHidden(), "Document is hidden");
168
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
169
        $this->assertFalse($doc->isExpired(), "Document is not expired");
170
171
        $doc->embargoIndefinitely();
172
        $doc = DataObject::get_by_id("DMSDocument", $dID);
173
        $this->assertTrue($doc->isHidden(), "Document is hidden");
174
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
175
        $this->assertFalse($doc->isExpired(), "Document is not expired");
176
177
        $s1->publish('Stage', 'Live');
178
        $s1->doPublish();
179
        $doc = DataObject::get_by_id("DMSDocument", $dID);
180
        $this->assertTrue(
181
            $doc->isHidden(),
182
            "Document is still hidden because although the untilPublish flag is cleared, the indefinitely flag is there"
183
        );
184
        $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
185
        $this->assertFalse($doc->isExpired(), "Document is not expired");
186
187
        $doc->clearEmbargo();
188
        $doc = DataObject::get_by_id("DMSDocument", $dID);
189
        $this->assertFalse($doc->isHidden(), "Document is not hidden");
190
        $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
191
        $this->assertFalse($doc->isExpired(), "Document is not expired");
192
    }
193
}
194