Skip to content

Commit 3a63085

Browse files
author
Isaac Andrade
authored
Merge pull request #27 from Soapbox/change/SOAP-13-make-tests-pass
Make tests pass
2 parents 26df2bd + 2cf1ef7 commit 3a63085

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ script:
1313
after_script:
1414
- mkdir -p build/logs
1515
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
16-
- php vendor/bin/coveralls -v
16+
- vendor/bin/php-coveralls --exclude-no-stmt -v

composer.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@
99
"email": "[email protected]"
1010
}
1111
],
12+
"repositories": [
13+
{
14+
"type": "vcs",
15+
"url": "https://github.com/Soapbox/fake-requests"
16+
}
17+
],
1218
"minimum-stability": "stable",
1319
"require": {
1420
"php": ">=7.2",
1521
"guzzlehttp/guzzle": "^6.2",
16-
"illuminate/http": "^6.0",
17-
"illuminate/support": "^6.0",
22+
"illuminate/http": "^7.0",
23+
"illuminate/support": "^7.0",
1824
"nesbot/carbon": "^2.0",
1925
"ramsey/uuid": "^3.6"
2026
},
2127
"require-dev": {
22-
"jshayes/fake-requests": "^3.0",
28+
"jshayes/fake-requests": "dev-master",
2329
"mockery/mockery": "^1.0",
24-
"orchestra/testbench": "^4.0",
30+
"orchestra/testbench": "^5.0",
2531
"phpunit/phpunit": "^8.0",
26-
"satooshi/php-coveralls": "^1.0"
32+
"php-coveralls/php-coveralls": "^2.0"
2733
},
2834
"autoload": {
2935
"psr-4": {

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Tests\Exceptions;
4+
5+
use Tests\TestCase;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use SoapBox\SignedRequests\Exceptions\InvalidConfigurationException;
8+
9+
class InvalidConfigurationExceptionTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
*/
14+
public function an_invalid_configuration_exception_is_constructed_with_a_default_message()
15+
{
16+
$exception = new InvalidConfigurationException();
17+
$this->assertEquals(InvalidConfigurationException::MESSAGE, $exception->getMessage());
18+
}
19+
20+
/**
21+
* @test
22+
*/
23+
public function the_message_for_the_exception_can_be_overwritten_during_construction()
24+
{
25+
$message = "So broken";
26+
$exception = new InvalidConfigurationException($message);
27+
$this->assertNotEquals(InvalidConfigurationException::MESSAGE, $exception->getMessage());
28+
$this->assertEquals($message, $exception->getMessage());
29+
}
30+
31+
/**
32+
* @test
33+
*/
34+
public function it_returns_a_bad_request_status_code()
35+
{
36+
$exception = new InvalidConfigurationException();
37+
$this->assertEquals(Response::HTTP_UNPROCESSABLE_ENTITY, $exception->getStatusCode());
38+
}
39+
40+
/**
41+
* @test
42+
*/
43+
public function it_returns_an_empty_set_of_response_headers()
44+
{
45+
$exception = new InvalidConfigurationException();
46+
$this->assertEmpty($exception->getHeaders());
47+
}
48+
}

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)