From af1865cb64d0e1b774f3b7cfd6256c54de748bcc Mon Sep 17 00:00:00 2001 From: butschster Date: Thu, 23 Jun 2022 15:36:51 +0400 Subject: [PATCH] Fixes problem with signing url with expiration time. It won't be part of signature --- src/UrlGenerator.php | 2 +- tests/src/UrlGeneratorTest.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/UrlGenerator.php b/src/UrlGenerator.php index 287acdd..4a64fa7 100644 --- a/src/UrlGenerator.php +++ b/src/UrlGenerator.php @@ -37,7 +37,7 @@ public function signedUrl( return $uri->withQuery(\http_build_query( \array_merge($parameters, [ - 'signature' => $this->signature->generate($this->prepareUri($uri)), + 'signature' => $this->signature->generate($this->prepareUri($uri->withQuery(\http_build_query($parameters)))) ]) )); } diff --git a/tests/src/UrlGeneratorTest.php b/tests/src/UrlGeneratorTest.php index 08a01ee..fd53981 100644 --- a/tests/src/UrlGeneratorTest.php +++ b/tests/src/UrlGeneratorTest.php @@ -42,7 +42,8 @@ public function testSignUrlWithExpiration(): void { $expiration = new \DateTime('2011-01-01T15:03:01.012345Z'); - $this->signature->shouldReceive('generate')->once()->with('/category/1?bar=baz') + $this->signature->shouldReceive('generate')->once() + ->with('/category/1?bar=baz&expires='.$expiration->getTimestamp()) ->andReturn('hashed_string'); $uri = $this->generator->signedUrl(new Uri('http://site.com/category/1?bar=baz'), $expiration); @@ -77,7 +78,9 @@ public function testSignedRouteWithExpiration(): void ->with('foo', ['bar' => 'baz', 'zoo' => 'zaz']) ->andReturn(new Uri('http://site.com/category/1?bar=baz')); - $this->signature->shouldReceive('generate')->once()->with('/category/1?bar=baz') + $this->signature->shouldReceive('generate') + ->once() + ->with('/category/1?bar=baz&expires='.$expiration->getTimestamp()) ->andReturn('hashed_string'); $uri = $this->generator->signedRoute('foo', ['zoo' => 'zaz', 'bar' => 'baz'], $expiration);