Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkeash committed Oct 15, 2017
0 parents commit 658ccbc
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
/.idea
.DS_Store
coverage.xml
composer.lock
28 changes: 28 additions & 0 deletions composer.json
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/"
}
}
}
32 changes: 32 additions & 0 deletions phpunit.xml
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>
28 changes: 28 additions & 0 deletions src/Zapier.php
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 [];
}
}
76 changes: 76 additions & 0 deletions tests/Unit/ServiceTest.php
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());
}
}

0 comments on commit 658ccbc

Please sign in to comment.