Added auth test, cleaned up directory

This commit is contained in:
Josh Sherman 2014-10-04 07:24:57 -04:00
parent a866a1a61b
commit e45e1251e1
25 changed files with 134 additions and 15 deletions

View file

@ -0,0 +1,38 @@
<?php
class AuthTest extends PHPUnit_Framework_TestCase
{
private $auth;
public function setUp()
{
Pickles\Object::$instances = [];
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_NAME'] = '127.0.0.1';
file_put_contents('/tmp/pickles.php', '<?php
$config = [
"environments" => [
"local" => "127.0.0.1",
"production" => "123.456.789.0",
],
];
');
Pickles\Config::getInstance('/tmp/pickles.php');
$this->auth = new Pickles\Auth();
}
public function testBasic()
{
$this->assertFalse($this->auth->basic());
}
public function testOAuth2()
{
$this->assertFalse($this->auth->oauth2());
}
}

View file

@ -63,6 +63,28 @@ namespace Resources\v1
}
}
namespace Classes
{
class Auth extends \Pickles\Auth
{
private static $count = 0;
public function basic()
{
self::$count++;
if (self::$count % 2)
{
return false;
}
else
{
return true;
}
}
}
}
namespace
{
class ResourceTest extends PHPUnit_Framework_TestCase
@ -213,6 +235,49 @@ namespace
new Pickles\Router();
}
public function testBasicAuthBadCredentials()
{
Pickles\Object::$instances = [];
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['SERVER_NAME'] = '127.0.0.1';
file_put_contents('/tmp/pickles.php', '<?php
$config = [
"environments" => [
"local" => "127.0.0.1",
"production" => "123.456.789.0",
],
"pickles" => [
"namespace" => "",
"datasource" => "mysql",
"auth" => "basic",
],
"datasources" => [
"mysql" => [
"driver" => "pdo_mysql",
],
],
];
');
Pickles\Config::getInstance('/tmp/pickles.php');
$response = json_encode([
'meta' => [
'status' => 401,
'message' => 'Invalid authentication credentials.',
],
]);
$this->expectOutputString($response);
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$_REQUEST['request'] = 'v1/resource/1';
new Pickles\Router();
}
public function testBasicAuth()
{
Pickles\Object::$instances = [];