-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathInstallerTest.php
More file actions
209 lines (177 loc) · 5.61 KB
/
Copy pathInstallerTest.php
File metadata and controls
209 lines (177 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* Copyright (c) 2014 Georg Ehrke <georg@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace Test;
use OC\Installer;
class InstallerTest extends TestCase {
private static $appid = 'testapp';
protected function setUp(): void {
parent::setUp();
Installer::removeApp(self::$appid);
\OC::$server->getConfig()->deleteAppValues(self::$appid);
}
protected function tearDown(): void {
Installer::removeApp(self::$appid);
\OC::$server->getConfig()->deleteAppValues(self::$appid);
parent::tearDown();
}
public function testInstallApp() {
$pathOfTestApp = __DIR__;
$pathOfTestApp .= '/../data/';
$pathOfTestApp .= 'testapp.zip';
$tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfTestApp, $tmp);
$data = [
'path' => $tmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
];
Installer::installApp($data);
$isInstalled = Installer::isInstalled(self::$appid);
$this->assertTrue($isInstalled);
}
public function testUpdateApp() {
$pathOfOldTestApp = __DIR__;
$pathOfOldTestApp .= '/../data/';
$pathOfOldTestApp .= 'testapp.zip';
$oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
$oldData = [
'path' => $oldTmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
];
$pathOfNewTestApp = __DIR__;
$pathOfNewTestApp .= '/../data/';
$pathOfNewTestApp .= 'testapp2.zip';
$newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfNewTestApp, $newTmp);
$newData = [
'path' => $newTmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
];
Installer::installApp($oldData);
$oldVersionNumber = \OC_App::getAppVersion(self::$appid);
Installer::updateApp($newData);
$newVersionNumber = \OC_App::getAppVersion(self::$appid);
$this->assertNotEquals($oldVersionNumber, $newVersionNumber);
}
/**
* Tests that updating with an archive whose top-level directory is not
* named after the app id fails with a clear error message and, crucially,
* does not destroy the already-installed app.
*/
public function testUpdateWithInvalidArchiveKeepsInstalledApp() {
// Install the valid app first
$pathOfOldTestApp = __DIR__ . '/../data/testapp.zip';
$oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
$oldData = [
'path' => $oldTmp,
'source' => 'path',
'appdata' => [
'id' => 'testapp',
'level' => 100,
]
];
Installer::installApp($oldData);
$this->assertTrue(Installer::isInstalled(self::$appid));
$appPath = \OC_App::getAppPath(self::$appid);
$this->assertNotFalse($appPath);
$this->assertTrue(\is_dir($appPath));
// Attempt to update with an invalid archive: its top-level directory is
// "wrongname" although info.xml declares the id "testapp".
$pathOfInvalidTestApp = __DIR__ . '/../data/testapp_invalid.zip';
$invalidTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfInvalidTestApp, $invalidTmp);
$invalidData = [
'path' => $invalidTmp,
'source' => 'path',
'appdata' => [
'id' => 'testapp',
'level' => 100,
]
];
$thrown = false;
try {
Installer::updateApp($invalidData);
} catch (\Exception $e) {
$thrown = true;
$this->assertStringStartsWith('Archive does not contain a directory named', $e->getMessage());
}
$this->assertTrue($thrown, 'updateApp() should throw for an invalid archive');
// The previously installed app must still be present and untouched.
$this->assertTrue(\is_dir($appPath), 'The installed app directory must not be deleted on invalid update');
}
/**
* Tests that update is installed into writable app dir if the original app dir is not writable
*/
public function testUpdateIntoWritableAppDir() {
$oldAppRoots = \OC::$APPSROOTS;
$relativePath = "/anotherdir";
// Install old version
$pathOfOldTestApp = __DIR__ . '/../data/testapp.zip';
$oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
$oldData = [
'path' => $oldTmp,
'source' => 'path',
'appdata' => [
'id' => 'testapp',
'level' => 100,
]
];
$installResult = Installer::installApp($oldData);
$this->assertEquals('testapp', $installResult);
$oldAppPath = \OC_App::getAppPath(self::$appid);
// Mark the first app as dir non-writable and create the second as writable
$firstAppDir = \array_shift(\OC::$APPSROOTS);
$firstAppDir['writable'] = false;
$path = \dirname($firstAppDir['path']) . $relativePath;
\mkdir($path);
\clearstatcache();
\OC::$APPSROOTS = [
$firstAppDir,
[
'path' => $path,
'url' => $relativePath,
'writable' => true
]
];
\OC::$server->getAppManager()->clearAppsCache();
// Update app
$pathOfNewTestApp = __DIR__ . '/../data/testapp2.zip';
$newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfNewTestApp, $newTmp);
$newData = [
'path' => $newTmp,
'source' => 'path',
'appdata' => [
'id' => 'testapp',
'level' => 100,
]
];
$updateResult = Installer::updateApp($newData);
$this->assertTrue($updateResult);
$newAppPath = \OC_App::getAppPath(self::$appid);
$this->assertNotEquals($oldAppPath, $newAppPath);
$this->assertStringStartsWith($path, $newAppPath);
\OC_Helper::rmdirr($path);
\OC::$APPSROOTS = $oldAppRoots;
\OC::$server->getAppManager()->clearAppsCache();
}
}