Skip to content

Commit cff8e4a

Browse files
committed
[SOAP-13] Fix tests (failures and warnings)
1 parent db2a666 commit cff8e4a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/Requests/Verifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ public function getContent($asResource = false)
161161
*/
162162
public function isValid(string $key) : bool
163163
{
164-
if (!$this->headers->has($this->algorithmHeader)) {
164+
if (!$this->algorithmHeader || !$this->headers->has($this->algorithmHeader)) {
165165
return false;
166166
}
167167

168-
if (!$this->headers->has($this->signatureHeader)) {
168+
if (!$this->signatureHeader || !$this->headers->has($this->signatureHeader)) {
169169
return false;
170170
}
171171

tests/Middlewares/Laravel/VerifySignatureTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use SoapBox\SignedRequests\Requests\Payload;
1414
use Illuminate\Contracts\Cache\Repository as Cache;
1515
use Illuminate\Contracts\Config\Repository as Configurations;
16+
use SoapBox\SignedRequests\Exceptions\ExpiredRequestException;
17+
use SoapBox\SignedRequests\Exceptions\InvalidConfigurationException;
18+
use SoapBox\SignedRequests\Exceptions\InvalidSignatureException;
1619
use SoapBox\SignedRequests\Middlewares\Laravel\VerifySignature;
1720

1821
class VerifySignatureTest extends TestCase
@@ -70,10 +73,11 @@ public function it_can_be_constructed()
7073

7174
/**
7275
* @test
73-
* @expectedException \SoapBox\SignedRequests\Exceptions\InvalidSignatureException
7476
*/
7577
public function it_throws_an_invalid_signature_exception_if_the_request_is_not_valid()
7678
{
79+
$this->expectException(InvalidSignatureException::class);
80+
7781
$this->configurations->shouldReceive('get')
7882
->with('signed-requests.default.headers.signature')
7983
->andReturn('HTTP_SIGNATURE');
@@ -190,10 +194,11 @@ public function it_should_set_the_key_when_one_is_passed()
190194

191195
/**
192196
* @test
193-
* @expectedException \SoapBox\SignedRequests\Exceptions\InvalidConfigurationException
194197
*/
195198
public function it_should_throw_an_exception_when_it_cannot_find_the_key()
196199
{
200+
$this->expectException(InvalidConfigurationException::class);
201+
197202
$id = (string) Uuid::uuid4();
198203

199204
$query = [];
@@ -217,10 +222,11 @@ public function it_should_throw_an_exception_when_it_cannot_find_the_key()
217222

218223
/**
219224
* @test
220-
* @expectedException \SoapBox\SignedRequests\Exceptions\ExpiredRequestException
221225
*/
222226
public function it_throws_an_expired_request_exception_if_the_timestamp_on_the_request_is_outside_of_the_tolerance_allowed_for_requests()
223227
{
228+
$this->expectException(ExpiredRequestException::class);
229+
224230
$id = (string) Uuid::uuid4();
225231

226232
$this->configurations->shouldReceive('get')
@@ -302,10 +308,11 @@ public function it_should_call_our_callback_if_the_id_has_not_previously_been_se
302308

303309
/**
304310
* @test
305-
* @expectedException \SoapBox\SignedRequests\Exceptions\ExpiredRequestException
306311
*/
307312
public function it_should_throw_an_expired_request_exception_if_the_request_id_has_previously_been_seen()
308313
{
314+
$this->expectException(ExpiredRequestException::class);
315+
309316
$id = (string) Uuid::uuid4();
310317

311318
$this->configurations->shouldReceive('get')
@@ -348,10 +355,11 @@ public function it_should_throw_an_expired_request_exception_if_the_request_id_h
348355

349356
/**
350357
* @test
351-
* @expectedException \SoapBox\SignedRequests\Exceptions\ExpiredRequestException
352358
*/
353359
public function it_should_throw_an_expired_request_exception_if_the_same_request_is_played_multiple_times()
354360
{
361+
$this->expectException(ExpiredRequestException::class);
362+
355363
$id = (string) Uuid::uuid4();
356364

357365
$this->configurations->shouldReceive('get')
@@ -395,10 +403,11 @@ public function it_should_throw_an_expired_request_exception_if_the_same_request
395403

396404
/**
397405
* @test
398-
* @expectedException \SoapBox\SignedRequests\Exceptions\ExpiredRequestException
399406
*/
400407
public function it_throws_an_expired_request_exception_if_the_timestamp_on_the_request_does_not_have_the_correct_format()
401408
{
409+
$this->expectException(ExpiredRequestException::class);
410+
402411
$id = (string) Uuid::uuid4();
403412

404413
$this->configurations->shouldReceive('get')

0 commit comments

Comments
 (0)