Skip to content

Commit

Permalink
#120 - Added key and checksum to some events (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
fidelix authored and ankitpokhrel committed Jan 6, 2019
1 parent be841b2 commit b339abb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Tus/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ protected function handlePost() : HttpResponse
'size' => $this->getRequest()->header('Upload-Length'),
'file_path' => $filePath,
'location' => $location,
])->setChecksum($checksum);
])->setKey($uploadKey)->setChecksum($checksum);

$this->cache->set($uploadKey, $file->details() + ['upload_type' => $uploadType]);

Expand Down Expand Up @@ -414,12 +414,13 @@ protected function handleConcatenation(string $fileName, string $filePath) : Htt
'size' => 0,
'file_path' => $filePath,
'location' => $location,
])->setFilePath($filePath);
])->setFilePath($filePath)->setKey($uploadKey);

$file->setOffset($file->merge($files));

// Verify checksum.
$checksum = $this->getServerChecksum($filePath);
$file->setChecksum($checksum);

if ($checksum !== $this->getClientChecksum()) {
return $this->response->send(null, self::HTTP_CHECKSUM_MISMATCH);
Expand Down
24 changes: 24 additions & 0 deletions tests/Tus/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,18 @@ public function it_handles_concatenation_request()
], true)
->andReturn(true);

$fileMock
->shouldReceive('setChecksum')
->once()
->with($checksum)
->andReturnSelf();

$fileMock
->shouldReceive('setKey')
->once()
->with($key)
->andReturnSelf();

$response = $this->tusServerMock->handleConcatenation($fileName, $filePath . $fileName);

$this->assertEquals(201, $response->getStatusCode());
Expand Down Expand Up @@ -1333,6 +1345,18 @@ public function it_throws_460_for_checksum_mismatch_in_concatenation_request()
->with($files)
->andReturn(30);

$fileMock
->shouldReceive('setKey')
->once()
->with($key)
->andReturnSelf();

$fileMock
->shouldReceive('setChecksum')
->once()
->with($checksum)
->andReturnSelf();

$response = $this->tusServerMock->handleConcatenation($fileName, $filePath . $fileName);

$this->assertEquals(460, $response->getStatusCode());
Expand Down

0 comments on commit b339abb

Please sign in to comment.