From ec14621e7c48c5c6146b58ca505f49375da2d625 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 13 Oct 2014 21:46:34 -0400 Subject: [PATCH] Tweaked unit tests --- src/Resource.php | 13 +--- tests/Pickles/AuthTest.php | 38 ------------ tests/Pickles/ResourceTest.php | 110 +-------------------------------- tests/Pickles/RouterTest.php | 5 +- 4 files changed, 4 insertions(+), 162 deletions(-) delete mode 100644 tests/Pickles/AuthTest.php diff --git a/src/Resource.php b/src/Resource.php index 51e6565..9857cb2 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -91,24 +91,15 @@ class Resource extends Object throw new \Exception('HTTPS is required.', 400); } - // Check auth if flag is explicitly true or is true for the method - /* + // Check auth if flag is explicitly true or is true for the method if ($this->auth === true || (isset($this->auth[$method]) && $this->auth[$method])) { - if (!$this->config['auth'][$_SERVER['__version']]) + if (!isset($this->config['oauth2'][$_SERVER['__version']])) { throw new \Exception('Authentication is not configured properly.', 401); } - - switch ($this->config['auth'][$_SERVER['__version']]['strategy']) - { - default: - throw new \Exception('Invalid authentication strategy.', 401); - break; - } } - */ // Hack together some new globals if (in_array($method, ['PUT', 'DELETE'])) diff --git a/tests/Pickles/AuthTest.php b/tests/Pickles/AuthTest.php deleted file mode 100644 index c399202..0000000 --- a/tests/Pickles/AuthTest.php +++ /dev/null @@ -1,38 +0,0 @@ - [ - "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/Pickles/ResourceTest.php b/tests/Pickles/ResourceTest.php index 4a23713..a80c4a3 100644 --- a/tests/Pickles/ResourceTest.php +++ b/tests/Pickles/ResourceTest.php @@ -1,6 +1,6 @@ [ - "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 = []; - - $_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' => 405, - 'message' => 'Method not allowed.', - ], - ]); - - $this->expectOutputString($response); - - $_SERVER['REQUEST_METHOD'] = 'DELETE'; - $_REQUEST['request'] = 'v1/resource/1'; - - new Pickles\Router(); - } - public function testMethodNotAllowed() { $response = json_encode([ diff --git a/tests/Pickles/RouterTest.php b/tests/Pickles/RouterTest.php index 57f7ab8..b7993d1 100644 --- a/tests/Pickles/RouterTest.php +++ b/tests/Pickles/RouterTest.php @@ -1,6 +1,6 @@ "127.0.0.1", "production" => "123.456.789.0", ], - "pickles" => [ - "namespace" => "", - ], "datasources" => [], ]; ');