more test stuff
This commit is contained in:
parent
7027d4a077
commit
df6d7cd560
@ -82,7 +82,9 @@ class Cockpit_Auth extends Crunchbutton_Auth_Base {
|
|||||||
$this->session()->id_admin = $this->user()->id_admin;
|
$this->session()->id_admin = $this->user()->id_admin;
|
||||||
$this->session()->date_active = date('Y-m-d H:i:s');
|
$this->session()->date_active = date('Y-m-d H:i:s');
|
||||||
$this->session()->generateAndSaveToken();
|
$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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -267,7 +267,7 @@ class Crunchbutton_App extends Cana_App {
|
|||||||
if ($admin !== null) {
|
if ($admin !== null) {
|
||||||
$this->_admin = $admin;
|
$this->_admin = $admin;
|
||||||
}
|
}
|
||||||
if (!$admin && getenv('CLI')) {
|
if (!$admin && !$this->_admin && getenv('CLI')) {
|
||||||
$this->_admin = new Admin;
|
$this->_admin = new Admin;
|
||||||
}
|
}
|
||||||
return $this->_admin;
|
return $this->_admin;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class Crunchbutton_Controller_Rest extends Cana_Controller_Rest {
|
class Crunchbutton_Controller_Rest extends Cana_Controller_Rest {
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$headers = getallheaders();
|
$headers = getallheaders();
|
||||||
$this->headerErrors = $headers['X-Requested-With'] == 'XMLHttpRequest' || $headers['Http-Error'] ? true : false;
|
$this->headerErrors = $headers['X-Requested-With'] == 'XMLHttpRequest' || $headers['Http-Error'] ? true : false;
|
||||||
|
|
||||||
@ -23,9 +23,9 @@ class Crunchbutton_Controller_Rest extends Cana_Controller_Rest {
|
|||||||
case E_USER_ERROR:
|
case E_USER_ERROR:
|
||||||
case E_USER_NOTICE:
|
case E_USER_NOTICE:
|
||||||
case E_RECOVERABLE_ERROR:
|
case E_RECOVERABLE_ERROR:
|
||||||
header('PHP-Fatal-Error: '. json_encode($e));
|
header('PHP-Fatal-Error: '. json_encode($e));
|
||||||
header('HTTP/1.0 500 Server Error');
|
header('HTTP/1.0 500 Server Error');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,14 +50,16 @@ class Crunchbutton_Controller_Rest extends Cana_Controller_Rest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$find = '/(api\.|log\.)/';
|
$find = '/(api\.|log\.)/';
|
||||||
if (preg_match($find, $_SERVER['SERVER_NAME'])) {
|
if (preg_match($find, $_SERVER['SERVER_NAME'])) {
|
||||||
$allow = preg_replace($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-Origin: http'.($_SERVER['HTTPS'] == 'on' ? 's' : '').'://'.$allow);
|
||||||
header('Access-Control-Allow-Credentials: true');
|
header('Access-Control-Allow-Credentials: true');
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
if (! headers_sent ()) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
}
|
||||||
Cana::view()->layout('layout/ajax');
|
Cana::view()->layout('layout/ajax');
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|||||||
43
travis/Tests/CockpitAuthTest.php
Normal file
43
travis/Tests/CockpitAuthTest.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test authentication and keep it in the db for the next tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CockpitAuthTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
protected static $login = 'root';
|
||||||
|
protected static $password = 'password';
|
||||||
|
|
||||||
|
public static function setUpBeforeClass() {
|
||||||
|
|
||||||
|
if (!getenv('TRAVIS')) {
|
||||||
|
$a = Admin::login(self::$login);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$a || !$a->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
class SayTest extends PHPUnit_Framework_TestCase { //ExampleTest
|
class SayTest extends PHPUnit_Framework_TestCase { //ExampleTest
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user