aboutsummaryrefslogtreecommitdiff
path: root/engines/testbed/webserver.cpp
blob: d46cea5585c858565081139f06759de2dce68c03 (plain)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "testbed/webserver.h"
#include "backends/networking/sdl_net/localwebserver.h"
#include "common/config-manager.h"

namespace Testbed {

WebserverTestSuite::WebserverTestSuite() {
	addTest("ResolveIP", &WebserverTests::testIP, true);
	addTest("IndexPage", &WebserverTests::testIndexPage, true);
	addTest("FilesPage", &WebserverTests::testFilesPageInvalidParameterValue, true);
	addTest("CreateDirectory", &WebserverTests::testFilesPageCreateDirectory, true);
	addTest("UploadFile", &WebserverTests::testFilesPageUploadFile, true);
	addTest("UploadDirectory", &WebserverTests::testFilesPageUploadDirectory, true);
	addTest("DownloadFile", &WebserverTests::testFilesPageDownloadFile, true);
}

///// TESTS GO HERE /////

/** This test calls Storage::info(). */

bool WebserverTests::startServer() {
	Common::Point pt;
	pt.x = 10; pt.y = 10;
	Testsuite::writeOnScreen("Starting webserver...", pt);
	LocalServer.start();
	g_system->delayMillis(500);
	Testsuite::clearScreen();
	return LocalServer.isRunning();
}

TestExitStatus WebserverTests::testIP() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Welcome to the Webserver test suite!\n"
		"You would be visiting different server's pages and saying whether they work like they should.\n\n"
		"Testing Webserver's IP resolving.\n"
		"In this test we'll try to resolve server's IP.";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : IP resolving\n");
		return kTestSkipped;
	}

	if (Testsuite::handleInteractiveInput(
			Common::String::format("Is this your machine's IP?\n%s", LocalServer.getAddress().c_str()),
			"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! IP was not resolved!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("IP was resolved\n");
	return kTestPassed;
}

TestExitStatus WebserverTests::testIndexPage() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Testing Webserver's index page.\n"
		"In this test we'll try to open server's index page.";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : index page\n");
		return kTestSkipped;
	}

	g_system->openUrl(LocalServer.getAddress());
	if (Testsuite::handleInteractiveInput(
		Common::String::format("The %s page opens well?", LocalServer.getAddress().c_str()),
		"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! Couldn't open server's index page!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("Server's index page is OK\n");
	return kTestPassed;
}

TestExitStatus WebserverTests::testFilesPageInvalidParameterValue() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Testing Webserver's files page.\n"
		"In this test we'll try to pass invalid parameter to files page.";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : files page (invalid parameter)\n");
		return kTestSkipped;
	}

	g_system->openUrl(LocalServer.getAddress()+"files?path=error");
	if (Testsuite::handleInteractiveInput(
		Common::String::format("The %sfiles?path=error page displays error message?", LocalServer.getAddress().c_str()),
		"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! No error message on invalid parameter in '/files'!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("Server's files page detects invalid paramters fine\n");
	return kTestPassed;
}

TestExitStatus WebserverTests::testFilesPageCreateDirectory() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Testing Webserver's files page Create Directory feature.\n"
		"In this test you'll try to create directory.";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : files page create directory\n");
		return kTestSkipped;
	}

	g_system->openUrl(LocalServer.getAddress() + "files?path=/root/");
	if (Testsuite::handleInteractiveInput(
		Common::String::format("You could go to %sfiles page, navigate to some directory with write access and create a directory there?", LocalServer.getAddress().c_str()),
		"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! Create Directory is not working!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("Create Directory is OK\n");
	return kTestPassed;
}

TestExitStatus WebserverTests::testFilesPageUploadFile() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Testing Webserver's files page Upload Files feature.\n"
		"In this test you'll try to upload a file.";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : files page file upload\n");
		return kTestSkipped;
	}

	g_system->openUrl(LocalServer.getAddress() + "files?path=/root/");
	if (Testsuite::handleInteractiveInput(
		Common::String::format("You're able to upload a file in some directory with write access through %sfiles page?", LocalServer.getAddress().c_str()),
		"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! Upload Files is not working!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("Upload Files is OK\n");
	return kTestPassed;
}

TestExitStatus WebserverTests::testFilesPageUploadDirectory() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Testing Webserver's files page Upload Directory feature.\n"
		"In this test you'll try to upload a directory (works in Chrome only).";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : files page directory upload\n");
		return kTestSkipped;
	}

	g_system->openUrl(LocalServer.getAddress() + "files?path=/root/");
	if (Testsuite::handleInteractiveInput(
		Common::String::format("You're able to upload a directory into some directory with write access through %sfiles page using Chrome?", LocalServer.getAddress().c_str()),
		"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! Upload Directory is not working!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("Upload Directory is OK\n");
	return kTestPassed;
}

TestExitStatus WebserverTests::testFilesPageDownloadFile() {
	if (!startServer()) {
		Testsuite::logPrintf("Error! Can't start local webserver!\n");
		return kTestFailed;
	}

	Common::String info = "Testing Webserver's files downloading feature.\n"
		"In this test you'll try to download a file.";

	if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
		Testsuite::logPrintf("Info! Skipping test : files page download\n");
		return kTestSkipped;
	}

	g_system->openUrl(LocalServer.getAddress() + "files?path=/root/");
	if (Testsuite::handleInteractiveInput(
		Common::String::format("You're able to download a file through %sfiles page?", LocalServer.getAddress().c_str()),
		"Yes", "No", kOptionRight)) {
		Testsuite::logDetailedPrintf("Error! Files downloading is not working!\n");
		return kTestFailed;
	}

	Testsuite::logDetailedPrintf("Files downloading is OK\n");
	return kTestPassed;
}

} // End of namespace Testbed