This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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( |
||
0 ignored issues
–
show
|
|||
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() |
|
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() |
|
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( |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<DMSEmbargoTest> .
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. ![]() |
|||
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 |
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.