namespace OCA\DAV\BulkUpload;
use OCP\AppFramework\Http;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\LengthRequired;
/**
* @throws BadRequest
*/
- public function __construct(RequestInterface $request) {
+ public function __construct(
+ RequestInterface $request,
+ protected LoggerInterface $logger,
+ ) {
$stream = $request->getBody();
$contentType = $request->getHeader('Content-Type');
$boundaryValue = trim($boundaryValue);
// Remove potential quotes around boundary value.
- if (substr($boundaryValue, 0, 1) == '"' && substr($boundaryValue, -1) == '"') {
+ if (substr($boundaryValue, 0, 1) === '"' && substr($boundaryValue, -1) === '"') {
$boundaryValue = substr($boundaryValue, 1, -1);
}
throw new Exception('An error occurred while reading headers of a part');
}
+ if (!str_contains($line, ':')) {
+ $this->logger->error('Header missing ":" on bulk request: ' . json_encode($line));
+ throw new Exception('An error occurred while reading headers of a part', Http::STATUS_BAD_REQUEST);
+ }
+
try {
[$key, $value] = explode(':', $line, 2);
$headers[strtolower(trim($key))] = trim($value);
namespace OCA\DAV\Tests\unit\DAV;
use \OCA\DAV\BulkUpload\MultipartRequestParser;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class MultipartRequestParserTest extends TestCase {
+
+ protected LoggerInterface $logger;
+
+ protected function setUp(): void {
+ $this->logger = $this->createMock(LoggerInterface::class);
+ }
+
private function getValidBodyObject() {
return [
[
->method('getBody')
->willReturn($stream);
- return new MultipartRequestParser($request);
+ return new MultipartRequestParser($request, $this->logger);
}
->willReturn($bodyStream);
$this->expectExceptionMessage('Body should be of type resource');
- new MultipartRequestParser($request);
+ new MultipartRequestParser($request, $this->logger);
}
/**