3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
* Test ZipCart Download functionality
26
* @author Alan Harder <alan.harder@sun.com>
27
* @version $Revision: 15513 $
29
class ZipCartDownloadTest extends GalleryTestCase {
31
function ZipCartDownloadTest($methodName) {
32
$this->GalleryTestCase($methodName);
39
list ($ret, $this->_view) = GalleryView::loadView('zipcart.Download');
41
print $ret->getAsHtml();
42
return $this->failWithStatus($ret);
45
$gallery->_phpVm = new ZipCartDownloadPhpVm($this);
46
$gallery->setConfig('data.gallery.tmp', '/data/tmp/');
49
function testDownloadIE() {
51
$platform = new UnitTestPlatform();
52
$platform->setReply('is_readable', array('/data/tmp/test.zip'), true);
53
$platform->setReply('filesize', array('/data/tmp/test.zip'), 123);
54
$platform->setReply('fopen', array('/data/tmp/test.zip', 'rb', 0), 'testfd');
55
$platform->setReply('fread', array('testfd', 65535), 'zipdata');
56
$platform->setReply('fread', array('testfd', 65535), '');
57
$platform->setReply('fclose', array('testfd'), true);
58
$platform->setReply('unlink', array('/data/tmp/test.zip'), true);
59
$platform->setReply('unlink', array('/data/tmp/test'), true);
60
$gallery->setPlatform($platform);
62
GalleryUtilities::putRequestVariable('file', 'test');
63
$_SERVER['HTTP_USER_AGENT'] = 'This is MSIE 6 browser';
66
$ret = $this->_view->renderImmediate(array(), array());
68
return $this->failWithStatus($ret);
70
$output = ob_get_contents();
74
array('Content-Type: application/zip',
75
'Content-Disposition: inline; filename="G2cart.zip"',
76
'Content-Length: 123'), $this->_header, 'header');
77
$this->assertEquals('zipdata', $output, 'output');
80
function testDownloadMultipart() {
82
$platform = new UnitTestPlatform();
83
$platform->setReply('is_readable', array('/data/tmp/test.zip'), true);
84
$platform->setReply('filesize', array('/data/tmp/test.zip'), 123);
85
$platform->setReply('fopen', array('/data/tmp/test.zip', 'rb', 0), 'testfd');
86
$platform->setReply('fread', array('testfd', 65535), 'zipdata');
87
$platform->setReply('fread', array('testfd', 65535), '');
88
$platform->setReply('fclose', array('testfd'), true);
89
$platform->setReply('unlink', array('/data/tmp/test.zip'), true);
90
$platform->setReply('unlink', array('/data/tmp/test'), true);
91
$gallery->setPlatform($platform);
93
GalleryUtilities::putRequestVariable('file', 'test');
94
$_SERVER['HTTP_USER_AGENT'] = 'This is some Gecko browser';
97
$ret = $this->_view->renderImmediate(array(), array());
99
return $this->failWithStatus($ret);
101
$output = ob_get_contents();
105
array('Content-Type: multipart/mixed; boundary=G2ZipCart'), $this->_header, 'header');
106
$this->assertEquals("--G2ZipCart\nContent-Type: application/zip\nContent-Disposition: " .
107
"inline; filename=\"G2cart.zip\"\nContent-Length: 123\n\nzipdata\n--G2ZipCart\n" .
108
"Content-Type: text/html\nPragma: No-cache\n\n<html><body onload=\"location" .
109
".reload()\"></body></html>\n\n--G2ZipCart--\n", $output, 'output');
112
function testCartRedirect() {
114
$platform = new UnitTestPlatform();
115
$platform->setReply('is_readable', array('/data/tmp/test.zip'), false);
116
$gallery->setPlatform($platform);
118
GalleryUtilities::putRequestVariable('file', 'test');
121
$ret = $this->_view->renderImmediate(array(), array());
123
return $this->failWithStatus($ret);
125
$output = ob_get_contents();
128
$this->assertEquals(1, count($this->_header), 'header lines');
129
$this->assertEquals('Location:', substr($this->_header[0], 0, 9), 'header');
130
$this->assertEquals('', $output, 'output');
133
function testBadFile() {
135
$platform = new UnitTestPlatform();
136
$platform->setReply('is_readable', array('/data/tmp/passwd.zip'), false);
137
$gallery->setPlatform($platform);
139
/* Verify a malicious file param can't get out of the tmp dir */
140
GalleryUtilities::putRequestVariable('file', '../../etc/passwd');
143
$ret = $this->_view->renderImmediate(array(), array());
145
return $this->failWithStatus($ret);
147
$output = ob_get_contents();
150
$this->assertEquals(1, count($this->_header), 'header lines');
151
$this->assertEquals('Location:', substr($this->_header[0], 0, 9), 'header');
152
$this->assertEquals('', $output, 'output');
157
* ZipCartDownloadPhpVm for header() calls
159
* @subpackage PHPUnit
161
class ZipCartDownloadPhpVm extends GalleryPhpVm {
162
function ZipCartDownloadPhpVm(&$test) {
163
$this->_test =& $test;
166
function header($string) {
167
$this->_test->_header[] = $string;
170
function ini_set($varname, $newvalue) {