Skip to content

Commit

Permalink
Fix upload key issue for multi level api path (ankitpokhrel#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel authored Apr 13, 2018
1 parent 573033b commit f6138e4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ public function method() : string
return $this->request->method();
}

/**
* Get the current path info for the request.
*
* @return string
*/
public function path() : string
{
return $this->request->path();
}

/**
* Get upload key from url.
*
* @return null|string
* @return string
*/
public function key()
public function key() : string
{
return $this->request->segment(2);
return basename($this->request->path());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Tus/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ protected function handleGet()
{
$key = $this->request->key();

if (empty($key)) {
if ($this->request->path() === trim($this->getApiPath(), '/')) {
return $this->response->send('400 bad request.', HttpResponse::HTTP_BAD_REQUEST);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public function it_should_return_checksum_from_request_url()
$this->assertEquals($checksum, $this->request->key());
}

/**
* @test
*
* @covers ::path
*/
public function it_returns_url_path_info()
{
$this->request->getRequest()->server->set('REQUEST_URI', '/tus/files/');

$this->assertEquals('tus/files', $this->request->path());
}

/**
* @test
*
Expand Down
4 changes: 3 additions & 1 deletion tests/Tus/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1650,9 +1650,11 @@ public function it_returns_400_for_request_without_hash()
->server
->add([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/files',
'REQUEST_URI' => '/tus/files',
]);

$this->tusServerMock->setApiPath('/tus/files');

$response = $this->tusServerMock->handleGet();

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

0 comments on commit f6138e4

Please sign in to comment.