-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 658ccbc
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/vendor | ||
/.idea | ||
.DS_Store | ||
coverage.xml | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "laravel-shield/zapier", | ||
"description": "A zapier service for shield", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Ashley Clarke", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"laravel-shield/shield": "^1.0" | ||
}, | ||
"require-dev": { | ||
"laravel-shield/testing": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Shield\\Zapier\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Shield\\Zapier\\Test\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
|
||
<testsuite name="Unit Tests"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
|
||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="QUEUE_DRIVER" value="sync"/> | ||
</php> | ||
<logging> | ||
<log type="coverage-clover" target="coverage.xml" showUncoveredFiles="true"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Shield\Zapier; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Collection; | ||
use Shield\Shield\Contracts\Service; | ||
use Shield\Shield\Support\BasicAuth; | ||
|
||
/** | ||
* Class Zapier | ||
* | ||
* @package \Shield\Zapier | ||
*/ | ||
class Zapier implements Service | ||
{ | ||
use BasicAuth; | ||
|
||
public function verify(Request $request, Collection $config): bool | ||
{ | ||
return $this->checkBasic($request, $config->get('username'), $config->get('password')); | ||
} | ||
|
||
public function headers(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Shield\Zapier\Test\Unit; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use Shield\Shield\Contracts\Service; | ||
use Shield\Testing\TestCase; | ||
use Shield\Zapier\Zapier; | ||
|
||
/** | ||
* Class ServiceTest | ||
* | ||
* @package \Shield\Zapier\Test\Unit | ||
*/ | ||
class ServiceTest extends TestCase | ||
{ | ||
/** | ||
* @var \Shield\Zapier\Zapier | ||
*/ | ||
protected $service; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->service = new Zapier; | ||
} | ||
|
||
/** @test */ | ||
public function it_is_a_service() | ||
{ | ||
Assert::assertInstanceOf(Service::class, new Zapier); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_verify_a_valid_request() | ||
{ | ||
$this->app['config']['shield.services.zapier.options.username'] = 'username'; | ||
$this->app['config']['shield.services.zapier.options.password'] = 'password'; | ||
|
||
$request = $this->request(); | ||
|
||
$headers = [ | ||
'PHP-AUTH-USER' => 'username', | ||
'PHP-AUTH-PW' => 'password', | ||
]; | ||
|
||
$request->headers->add($headers); | ||
|
||
Assert::assertTrue($this->service->verify($request, collect($this->app['config']['shield.services.zapier.options']))); | ||
} | ||
|
||
/** @test */ | ||
public function it_will_not_verify_a_bad_request() | ||
{ | ||
$this->app['config']['shield.services.zapier.options.username'] = 'user'; | ||
$this->app['config']['shield.services.zapier.options.password'] = 'pass'; | ||
|
||
$request = $this->request(); | ||
|
||
$headers = [ | ||
'PHP-AUTH-USER' => 'user', | ||
'PHP-AUTH-PW' => 'wrong-pass', | ||
]; | ||
|
||
$request->headers->add($headers); | ||
|
||
Assert::assertFalse($this->service->verify($request, collect($this->app['config']['shield.services.zapier.options']))); | ||
} | ||
|
||
/** @test */ | ||
public function the_headers_are_not_important() | ||
{ | ||
Assert::assertArraySubset([], $this->service->headers()); | ||
} | ||
} |