From df6d7cd56035a30a8e1ef924181648b77c629290 Mon Sep 17 00:00:00 2001 From: Devin Smith Date: Tue, 14 Jul 2015 17:56:57 -0700 Subject: [PATCH] more test stuff --- include/library/Cockpit/Auth.php | 4 +- include/library/Crunchbutton/App.php | 2 +- .../library/Crunchbutton/Controller/Rest.php | 24 ++++++----- travis/Tests/CockpitAuthTest.php | 43 +++++++++++++++++++ travis/Tests/SayOrderTest.php | 1 - 5 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 travis/Tests/CockpitAuthTest.php diff --git a/include/library/Cockpit/Auth.php b/include/library/Cockpit/Auth.php index ef34c49df..5589d4c13 100644 --- a/include/library/Cockpit/Auth.php +++ b/include/library/Cockpit/Auth.php @@ -82,7 +82,9 @@ class Cockpit_Auth extends Crunchbutton_Auth_Base { $this->session()->id_admin = $this->user()->id_admin; $this->session()->date_active = date('Y-m-d H:i:s'); $this->session()->generateAndSaveToken(); - setcookie('token', $this->session()->token, (new DateTime('3000-01-01'))->getTimestamp(), '/'); + if (!headers_sent()) { + setcookie('token', $this->session()->token, (new DateTime('3000-01-01'))->getTimestamp(), '/'); + } return true; } return false; diff --git a/include/library/Crunchbutton/App.php b/include/library/Crunchbutton/App.php index bb9ab48b6..c395ebc8f 100755 --- a/include/library/Crunchbutton/App.php +++ b/include/library/Crunchbutton/App.php @@ -267,7 +267,7 @@ class Crunchbutton_App extends Cana_App { if ($admin !== null) { $this->_admin = $admin; } - if (!$admin && getenv('CLI')) { + if (!$admin && !$this->_admin && getenv('CLI')) { $this->_admin = new Admin; } return $this->_admin; diff --git a/include/library/Crunchbutton/Controller/Rest.php b/include/library/Crunchbutton/Controller/Rest.php index f376786c2..24d16b661 100644 --- a/include/library/Crunchbutton/Controller/Rest.php +++ b/include/library/Crunchbutton/Controller/Rest.php @@ -1,11 +1,11 @@ headerErrors = $headers['X-Requested-With'] == 'XMLHttpRequest' || $headers['Http-Error'] ? true : false; - + if ($this->headerErrors) { ini_set('display_errors', 0); @@ -23,9 +23,9 @@ class Crunchbutton_Controller_Rest extends Cana_Controller_Rest { case E_USER_ERROR: case E_USER_NOTICE: case E_RECOVERABLE_ERROR: - header('PHP-Fatal-Error: '. json_encode($e)); - header('HTTP/1.0 500 Server Error'); - break; + header('PHP-Fatal-Error: '. json_encode($e)); + header('HTTP/1.0 500 Server Error'); + break; } }); @@ -50,14 +50,16 @@ class Crunchbutton_Controller_Rest extends Cana_Controller_Rest { }); } - $find = '/(api\.|log\.)/'; - if (preg_match($find, $_SERVER['SERVER_NAME'])) { - $allow = preg_replace($find,'',$_SERVER['SERVER_NAME']); + $find = '/(api\.|log\.)/'; + if (preg_match($find, $_SERVER['SERVER_NAME'])) { + $allow = preg_replace($find,'',$_SERVER['SERVER_NAME']); header('Access-Control-Allow-Origin: http'.($_SERVER['HTTPS'] == 'on' ? 's' : '').'://'.$allow); header('Access-Control-Allow-Credentials: true'); - } + } - header('Content-Type: application/json'); + if (! headers_sent ()) { + header('Content-Type: application/json'); + } Cana::view()->layout('layout/ajax'); parent::__construct(); diff --git a/travis/Tests/CockpitAuthTest.php b/travis/Tests/CockpitAuthTest.php new file mode 100644 index 000000000..99f1a57fc --- /dev/null +++ b/travis/Tests/CockpitAuthTest.php @@ -0,0 +1,43 @@ +id_admin) { + $a = new Admin([ + 'name' => self::$login, + 'login' => self::$login, + 'active' => true, + 'pass' => Crunchbutton_Admin_Auth::passwordEncrypt(self::$password) + ]); + $a->save(); + + $p = new Crunchbutton_Admin_Permission([ + 'id_admin' => $a->id_admin, + 'permission' => 'global', + 'allow' => true + ]); + $p->save(); + } + } + + public function testAuth() { + $res = c::auth()->doAuthByLocalUser(['email' => self::$login, 'password' => self::$password]); + $this->assertTrue($res ? true : false); + $this->assertTrue(c::admin()->id_admin ? true : false); + $this->assertTrue(c::user()->id_admin ? true : false); + } +} + diff --git a/travis/Tests/SayOrderTest.php b/travis/Tests/SayOrderTest.php index ad59c004c..dffd0583a 100644 --- a/travis/Tests/SayOrderTest.php +++ b/travis/Tests/SayOrderTest.php @@ -1,4 +1,3 @@ -