diff --git a/composer.json b/composer.json index 31156bc..4bbdbbd 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "picklesphp/pickles", - "description": "The Pickles SOA Framework", + "description": "Pickles is a PHP framework for building kick-ass services", "type": "library", "keywords": ["framework", "api", "soa", "oauth"], "homepage": "http://picklesphp.com", diff --git a/composer.lock b/composer.lock index 64198c9..4f7de01 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "16033f40d01b3ada4064b0b7488d4cb7", + "hash": "90c06945853fd0c6910bfd5e6f9c1e13", "packages": [], "packages-dev": [ { @@ -1068,12 +1068,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "93d237c3da7565a9ad2b4b6a74af73f4e3c0c305" + "reference": "e133748fd9165e24f8e9498ef5862f8bd37004e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/93d237c3da7565a9ad2b4b6a74af73f4e3c0c305", - "reference": "93d237c3da7565a9ad2b4b6a74af73f4e3c0c305", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/e133748fd9165e24f8e9498ef5862f8bd37004e5", + "reference": "e133748fd9165e24f8e9498ef5862f8bd37004e5", "shasum": "" }, "require": { @@ -1117,7 +1117,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "http://symfony.com", - "time": "2014-10-01 05:53:11" + "time": "2014-10-04 06:08:58" }, { "name": "symfony/filesystem", diff --git a/phpunit.xml b/phpunit.xml index 016e823..2d7ea10 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,13 +2,13 @@ - - ./tests/ + + ./tests/Pickles diff --git a/src/Auth.php b/src/Auth.php index 315f62f..aaf757e 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -1,7 +1,7 @@ config['pickles']['namespace'] . '\\Classes\\Auth'; + + // Strips preceding slashs when there is no namespace + if (strpos($auth, '\\\\') === 0) + { + $auth = substr($auth, 2); + } + $auth = new $auth(); + // @todo Remove when switch is implemented + if (!$auth->basic()) + { + throw new \Exception('Invalid authentication credentials.', 401); + } + + // @todo Not yet implemented + /* switch ($this->config['pickles']['auth']) { case 'basic': @@ -112,7 +127,6 @@ class Resource extends Object throw new \Exception('Invalid authentication credentials.', 401); } break; - case 'oauth2': $auth->oauth2(); break; @@ -121,6 +135,7 @@ class Resource extends Object throw new \Exception('Invalid authentication scheme.', 401); break; } + */ } // Hack together some new globals diff --git a/src/Router.php b/src/Router.php index 018e28d..5eb9e76 100644 --- a/src/Router.php +++ b/src/Router.php @@ -63,6 +63,7 @@ class Router extends Object array_unshift($nouns, '', $this->config['pickles']['namespace'], 'Resources', $version); $class = implode('\\', $nouns); + // @todo Make namespace mandatory // Strips preceding slashs when there is no namespace if (strpos($class, '\\\\') === 0) { diff --git a/tests/Pickles/AuthTest.php b/tests/Pickles/AuthTest.php new file mode 100644 index 0000000..c399202 --- /dev/null +++ b/tests/Pickles/AuthTest.php @@ -0,0 +1,38 @@ + [ + "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()); + } +} + diff --git a/tests/BrowserTest.php b/tests/Pickles/BrowserTest.php similarity index 100% rename from tests/BrowserTest.php rename to tests/Pickles/BrowserTest.php diff --git a/tests/CacheTest.php b/tests/Pickles/CacheTest.php similarity index 100% rename from tests/CacheTest.php rename to tests/Pickles/CacheTest.php diff --git a/tests/ConfigTest.php b/tests/Pickles/ConfigTest.php similarity index 100% rename from tests/ConfigTest.php rename to tests/Pickles/ConfigTest.php diff --git a/tests/ConvertTest.php b/tests/Pickles/ConvertTest.php similarity index 100% rename from tests/ConvertTest.php rename to tests/Pickles/ConvertTest.php diff --git a/tests/DatabaseTest.php b/tests/Pickles/DatabaseTest.php similarity index 100% rename from tests/DatabaseTest.php rename to tests/Pickles/DatabaseTest.php diff --git a/tests/DateTest.php b/tests/Pickles/DateTest.php similarity index 100% rename from tests/DateTest.php rename to tests/Pickles/DateTest.php diff --git a/tests/DistanceTest.php b/tests/Pickles/DistanceTest.php similarity index 100% rename from tests/DistanceTest.php rename to tests/Pickles/DistanceTest.php diff --git a/tests/FileTest.php b/tests/Pickles/FileTest.php similarity index 100% rename from tests/FileTest.php rename to tests/Pickles/FileTest.php diff --git a/tests/ModelTest.php b/tests/Pickles/ModelTest.php similarity index 100% rename from tests/ModelTest.php rename to tests/Pickles/ModelTest.php diff --git a/tests/NumberTest.php b/tests/Pickles/NumberTest.php similarity index 100% rename from tests/NumberTest.php rename to tests/Pickles/NumberTest.php diff --git a/tests/ObjectTest.php b/tests/Pickles/ObjectTest.php similarity index 100% rename from tests/ObjectTest.php rename to tests/Pickles/ObjectTest.php diff --git a/tests/ProfilerTest.php b/tests/Pickles/ProfilerTest.php similarity index 100% rename from tests/ProfilerTest.php rename to tests/Pickles/ProfilerTest.php diff --git a/tests/ResourceTest.php b/tests/Pickles/ResourceTest.php similarity index 85% rename from tests/ResourceTest.php rename to tests/Pickles/ResourceTest.php index 987ddb0..4a23713 100644 --- a/tests/ResourceTest.php +++ b/tests/Pickles/ResourceTest.php @@ -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', ' [ + "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 = []; diff --git a/tests/RouterTest.php b/tests/Pickles/RouterTest.php similarity index 100% rename from tests/RouterTest.php rename to tests/Pickles/RouterTest.php diff --git a/tests/SortTest.php b/tests/Pickles/SortTest.php similarity index 100% rename from tests/SortTest.php rename to tests/Pickles/SortTest.php diff --git a/tests/StringTest.php b/tests/Pickles/StringTest.php similarity index 100% rename from tests/StringTest.php rename to tests/Pickles/StringTest.php diff --git a/tests/TimeTest.php b/tests/Pickles/TimeTest.php similarity index 100% rename from tests/TimeTest.php rename to tests/Pickles/TimeTest.php diff --git a/tests/Bootstrap.php b/tests/bootstrap.php similarity index 100% rename from tests/Bootstrap.php rename to tests/bootstrap.php