Skip to content

Commit

Permalink
Merge branch '6.x' into 8.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Illuminate/Routing/UrlGenerator.php
  • Loading branch information
driesvints committed Aug 3, 2021
2 parents f997521 + 732c0e0 commit 259b934
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Reflector;
use Illuminate\Support\Stringable;
Expand Down Expand Up @@ -322,7 +321,7 @@ public function runsInMaintenanceMode()
*/
protected function expressionPasses()
{
$date = Carbon::now();
$date = Date::now();

if ($this->timezone) {
$date->setTimezone($this->timezone);
Expand Down
31 changes: 24 additions & 7 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,9 @@ public function formatScheme($secure = null)
*/
public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true)
{
$parameters = Arr::wrap($parameters);

if (array_key_exists('signature', $parameters)) {
throw new InvalidArgumentException(
'"Signature" is a reserved parameter when generating signed routes. Please rename your route parameter.'
);
}
$this->ensureSignedRouteParametersAreNotReserved(
$parameters = $this->formatParameters($parameters)
);

if ($expiration) {
$parameters = $parameters + ['expires' => $this->availableAt($expiration)];
Expand All @@ -339,6 +335,27 @@ public function signedRoute($name, $parameters = [], $expiration = null, $absolu
], $absolute);
}

/**
* Ensure the given signed route parameters are not reserved.
*
* @param mixed $parameters
* @return void
*/
protected function ensureSignedRouteParametersAreNotReserved($parameters)
{
if (array_key_exists('signature', $parameters)) {
throw new InvalidArgumentException(
'"Signature" is a reserved parameter when generating signed routes. Please rename your route parameter.'
);
}

if (array_key_exists('expires', $parameters)) {
throw new InvalidArgumentException(
'"Expires" is a reserved parameter when generating signed routes. Please rename your route parameter.'
);
}
}

/**
* Create a temporary signed route URL for a named route.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/Routing/UrlSigningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;
use InvalidArgumentException;
use Orchestra\Testbench\TestCase;

/**
Expand Down Expand Up @@ -50,6 +51,18 @@ public function testTemporarySignedUrls()
$this->assertSame('invalid', $this->get($url)->original);
}

public function testTemporarySignedUrlsWithExpiresParameter()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('reserved');

Route::get('/foo/{id}', function (Request $request, $id) {
return $request->hasValidSignature() ? 'valid' : 'invalid';
})->name('foo');

URL::temporarySignedRoute('foo', now()->addMinutes(5), ['id' => 1, 'expires' => 253402300799]);
}

public function testSignedUrlWithUrlWithoutSignatureParameter()
{
Route::get('/foo/{id}', function (Request $request, $id) {
Expand Down
21 changes: 21 additions & 0 deletions tests/Routing/RoutingUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,27 @@ public function testSignedUrlParameterCannotBeNamedSignature()

Request::create($url->signedRoute('foo', ['signature' => 'bar']));
}

public function testSignedUrlParameterCannotBeNamedExpires()
{
$url = new UrlGenerator(
$routes = new RouteCollection,
$request = Request::create('http://www.foo.com/')
);
$url->setKeyResolver(function () {
return 'secret';
});

$route = new Route(['GET'], 'foo/{expires}', ['as' => 'foo', function () {
//
}]);
$routes->add($route);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('reserved');

Request::create($url->signedRoute('foo', ['expires' => 253402300799]));
}
}

class RoutableInterfaceStub implements UrlRoutable
Expand Down

0 comments on commit 259b934

Please sign in to comment.