| 238 | } |
| 239 | |
| 240 | void SC::HttpAsyncFileServerTest::uploadsDisabled() |
| 241 | { |
| 242 | StringView webServerFolder = report.applicationRootDirectory.view(); |
| 243 | AsyncEventLoop eventLoop; |
| 244 | SC_TEST_EXPECT(eventLoop.create()); |
| 245 | |
| 246 | using HttpConnectionType = HttpAsyncConnection<2, 2, 8 * 1024, 8 * 1024>; |
| 247 | |
| 248 | HttpConnectionType connections[1]; |
| 249 | HttpAsyncFileServer::StreamQueue<2> streams[1]; |
| 250 | HttpAsyncServer httpServer; |
| 251 | HttpAsyncFileServer fileServer; |
| 252 | ThreadPool threadPool; |
| 253 | const uint16_t serverPort = report.mapPort(26121); |
| 254 | |
| 255 | if (eventLoop.needsThreadPoolForFileOperations()) |
| 256 | { |
| 257 | SC_TEST_EXPECT(threadPool.create(2)); |
| 258 | } |
| 259 | SC_TEST_EXPECT(httpServer.init(Span<HttpConnectionType>(connections))); |
| 260 | SC_TEST_EXPECT(httpServer.start(eventLoop, "127.0.0.1", serverPort)); |
| 261 | SC_TEST_EXPECT(fileServer.init(threadPool, eventLoop, webServerFolder)); |
| 262 | |
| 263 | HttpAsyncFileServerOptions options; |
| 264 | options.enableUploads = false; |
| 265 | SC_TEST_EXPECT(fileServer.setOptions(options)); |
| 266 | |
| 267 | httpServer.onRequest = [&](HttpConnection& connection) |
| 268 | { SC_ASSERT_RELEASE(fileServer.handleRequest(streams[connection.getConnectionID().getIndex()], connection)); }; |
| 269 | |
| 270 | FileSystem fs; |
| 271 | SC_TEST_EXPECT(fs.init(webServerFolder)); |
| 272 | |
| 273 | HttpTestClient putClient; |
| 274 | HttpTestClient multipartClient; |
| 275 | String putURL = StringEncoding::Ascii; |
| 276 | String multipartURL = StringEncoding::Ascii; |
| 277 | SC_TEST_EXPECT(StringBuilder::format(putURL, "http://127.0.0.1:{}/disabled-upload.txt", serverPort)); |
| 278 | SC_TEST_EXPECT(StringBuilder::format(multipartURL, "http://127.0.0.1:{}/upload", serverPort)); |
| 279 | struct UploadsDisabledContext |
| 280 | { |
| 281 | HttpAsyncFileServerTest* test; |
| 282 | HttpAsyncServer* httpServer; |
| 283 | FileSystem* fs; |
| 284 | AsyncEventLoop* loop; |
| 285 | HttpTestClient* multipartClient; |
| 286 | String* multipartURL; |
| 287 | } context = {this, &httpServer, &fs, &eventLoop, &multipartClient, &multipartURL}; |
| 288 | putClient.callback = [&context](HttpTestClient& result) |
| 289 | { |
| 290 | const StringView response(result.getResponse()); |
| 291 | context.test->recordExpectation("PUT 403 response", response.containsString("403 Forbidden")); |
| 292 | context.test->recordExpectation("disabled PUT file missing", |
| 293 | not context.fs->existsAndIsFile("disabled-upload.txt")); |
| 294 | context.test->recordExpectation("start disabled multipart upload", |
| 295 | context.multipartClient->postMultipart(*context.loop, |
| 296 | context.multipartURL->view(), "file", |
| 297 | "disabled-multipart.txt", "blocked")); |
nothing calls this directly
no test coverage detected