This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runTests.php
257 lines (228 loc) · 9.69 KB
/
runTests.php
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*
* Re-run the diagnostic tests
*/
/**
* If you want to run the tests, first comment this line!
* It is disabled for security purpose
*/
die("You are not allowed to see this page (comment first line of the file to access it!)");
require_once("base.conf.php");
function apiPost($baseData, $url, $parameters, $private){
$nonce = substr(md5(microtime()), 0, 6);
$url = $baseData["path"].$url;
$msg = "$url:$nonce:$private";
$hash = $nonce.":".hash_hmac("sha256", $msg, $parameters["auth_token"]);
$client = new HttpClient($baseData["host"]);
$parameters["auth_hash"] = $hash;
$res = $client->post($url, $parameters);
echo "Protocol: ".$baseData["protocol"]." (ignored!)<br>\n";
echo "URL: ".$baseData["host"].$url."<br>\n";
echo "Parameters: ".print_r($parameters, true)."<br>\n";
echo "Result: ".$res."<br>\n";
return $client;
}
if(isSet($_GET["api"])){
if(isSet($_POST["ws-alias"])){
$ws = $_POST["ws-alias"];
$user = $_POST["user"];
$password = $_POST["password"];
$host = $_POST["host"];
$protocol = $_POST["protocol"];
$path = $_POST["path"];
if($path == "/") $path = "";
$urlBaseData = array("host" => $host, "protocol" => $protocol, "path" => $path);
echo "<style>*{font-family: Arial,sans-serif;}</style>";
echo "<h3>Getting authentication token with user credentials</h3>";
flush();
$tokens = file_get_contents("${protocol}://${user}:${password}@${host}${path}/api/pydio/keystore_generate_auth_token/php_client");
$data = json_decode($tokens, true);
if(is_array($data)){
echo "\n\nData is correctly decoded as JSON.<br>\n";
var_dump($data);
}else{
echo "\n\nData returned is not JSON! There is something wrong with the API. Exiting.<br>\n";
var_dump($tokens);
exit();
}
// Now use tokens
$token = $data["t"];
$private = $data["p"];
$tokens = array("auth_token" => $token);
flush();
echo "<hr><h3>Now checking workspace root listing. We expect XML result</h3>";
flush();
$client = apiPost($urlBaseData, "/api/$ws/ls", array("auth_token" => $token), $private);
$crtListing = $client->getContent();
if(strpos($crtListing, '<?xml version="1.0"') !== FALSE){
echo "\n\nData is correctly received as XML.";
var_dump($crtListing);
}else{
echo "\n\nDid not receive XML data! Did you enter a correct workspace? Exiting.<br>\n";
var_dump($client->getHeaders());
echo "<br>\n";
var_dump($crtListing);
exit();
}
echo ("<script>window.scrollTo(0, 100000);</script>");
flush();
echo "<hr><h3>Checking indexation output</h3>";
flush();
$lastSeq = 0;
$client = apiPost($urlBaseData, "/api/$ws/changes/$lastSeq", array("auth_token" => $token, "flatten" => "true"), $private);
$headers = $client->getHeaders();
if($headers["content-type"] != "application/json; charset=UTF-8"){
echo "\n\n Seems like response header is not JSON. Did you correctly enable the Syncable feature on this workspace?<br>\n";
var_dump($headers);
echo "<br>\n";
var_dump($client->getContent());
exit();
}
$data = json_decode($client->getContent(), true);
if(is_array($data)){
$lastSeq = $data["last_seq"];
echo "\n\nData is correctly decoded as JSON. Saving Last Seq Id to ".$lastSeq."<br>\n";
var_dump($data["last_seq"]);
}else{
echo "\n\nData not decoded as JSON, normal?<br>\n";
var_dump($headers);
echo "<br>\n";
var_dump($data);
exit();
}
$nonce = substr(md5(microtime()), 0, 5);
$tmpFile = "test-pydio-".$nonce.".txt";
echo ("<script>window.scrollTo(0, 100000);</script>");
flush();
echo "<hr><h3>Creating a simple file inside workspace</h3>";
flush();
if(strpos($crtListing, 'filename="/'.$tmpFile.'"') !== FALSE){
echo "\n\n Skipping this step, file already exists. Is it normal?\n\n";
}else{
$client = apiPost($urlBaseData, "/api/$ws/mkfile/" . $tmpFile, array("auth_token" => $token, "content" => "my file content"), $private);
$data = $client->getContent();
if(strpos($data, '<?xml version="1.0"') !== FALSE){
echo "\n\nResponse is XML, see result:";
var_dump($data);
}else{
echo "\n\nDid not receive XML data! Did you enter a correct workspace? Exiting.";
var_dump($data);
exit();
}
}
echo ("<script>window.scrollTo(0, 100000);</script>");
flush();
echo "<hr><h3>Checking indexation output</h3>";
flush();
$client = apiPost($urlBaseData, "/api/$ws/changes/" . $lastSeq, array("auth_token" => $token), $private);
$headers = $client->getHeaders();
if($headers["content-type"] != "application/json; charset=UTF-8"){
echo "\n\n Seems like response header is not JSON";
var_dump($headers);
exit();
}
$data = json_decode($client->getContent(), true);
if(is_array($data)){
echo "\n\nData is correctly decoded as JSON. Looking for the new file in the last sequences";
$found = false;
foreach($data["changes"] as $change){
if($change["source"] == "NULL" && $change["target"] == "/".$tmpFile){
echo "<br> Found file creation event in recent changes:";
var_dump($change);
$found = true;
break;
}
}
if(!$found){
echo "\n\nNo change detected reflecting file creation, this is not normal, exiting.";
var_dump($data);
exit();
}
}else{
echo "\n\nData not decoded as JSON, normal?";
var_dump($data);
exit();
}
echo ("<script>window.scrollTo(0, 100000);</script>");
flush();
echo "<hr><h3>Deleting temporary file from the workspace</h3>";
flush();
$client = apiPost($urlBaseData, "/api/$ws/delete", array("auth_token" => $token, "file" => "/$tmpFile"), $private);
$data = $client->getContent();
if(strpos($data, '<?xml version="1.0"') !== FALSE){
echo "\n\nResponse is the following XML.";
var_dump($data);
}else{
echo "\n\nDid not receive XML data! Did you enter a correct workspace? Exiting.";
var_dump($client->getHeaders());
var_dump($data);
exit();
}
echo ("<script>window.scrollTo(0, 100000);</script>");
flush();
echo "<hr><h3>Rechecking indexation output</h3>";
flush();
$client = apiPost($urlBaseData, "/api/$ws/changes/" . $lastSeq, array("auth_token" => $token), $private);
$headers = $client->getHeaders();
if($headers["content-type"] != "application/json; charset=UTF-8"){
echo "\n\n Seems like response header is not JSON. Did you correctly enable the Syncable feature on this workspace?";
var_dump($headers);
exit();
}
$data = json_decode($client->getContent(), true);
if(is_array($data)){
echo "\n\nData is correctly decoded as JSON. Looking for the new file in the last sequences";
$found = false;
foreach($data["changes"] as $change){
if($change["source"] == "/".$tmpFile && $change["target"] == "NULL"){
echo "<br> Found file move to NULL in sequence!";
var_dump($change);
$found = true;
break;
}
}
if(!$found){
echo "\n\nNo change detected reflecting file deletion, this is not normal, exiting.";
var_dump($data);
exit();
}
}else{
echo "\n\nData not decoded as JSON, normal?";
var_dump($data);
exit();
}
echo ("<script>window.scrollTo(0, 100000);</script>");
//echo "</pre>";
}else{
$host = $_SERVER["HTTP_HOST"];
$protocol = $_SERVER["HTTPS"] === "on" ? "https" : "http";
$path = dirname($_SERVER["REQUEST_URI"]);
HTMLWriter::charsetHeader();
require(AJXP_TESTS_FOLDER."/api_test.phtml");
}
}else{
$outputArray = array();
$testedParams = array();
$passed = true;
$passed = AJXP_Utils::runTests($outputArray, $testedParams);
AJXP_Utils::testResultsToTable($outputArray, $testedParams, true);
AJXP_Utils::testResultsToFile($outputArray, $testedParams);
}