예제 #1
0
 public static function setUpBeforeClass()
 {
     Castle::setApiKey('secretkey');
     $_SERVER = array();
     $_SERVER['HTTP_USER_AGENT'] = 'TestAgent';
     $_SERVER['REMOTE_ADDR'] = '8.8.8.8';
 }
예제 #2
0
 public function send($method, $url, $body = null, $headers = array())
 {
     $curl = curl_init();
     $method = strtolower($method);
     switch ($method) {
         case 'post':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
             break;
         case 'get':
             curl_setopt($curl, CURLOPT_HTTPGET, true);
             break;
         case 'put':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
             break;
         case 'delete':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
             break;
         default:
             throw new Castle_RequestError();
     }
     $curlOptions = array();
     if (!empty($body)) {
         $curlOptions[CURLOPT_POSTFIELDS] = $body;
     }
     $curlOptions[CURLOPT_CAINFO] = self::caCerts();
     $curlOptions[CURLOPT_URL] = $url;
     $curlOptions[CURLOPT_USERPWD] = ":" . Castle::getApiKey();
     $curlOptions[CURLOPT_RETURNTRANSFER] = true;
     $curlOptions[CURLOPT_USERAGENT] = "Castle/v1 PHPBindings/" . Castle::VERSION;
     $curlOptions[CURLOPT_CONNECTTIMEOUT] = 3;
     $curlOptions[CURLOPT_TIMEOUT] = 10;
     $curlOptions[CURLOPT_HTTPHEADER] = $headers;
     $curlOptions[CURLOPT_HEADER] = true;
     curl_setopt_array($curl, $curlOptions);
     $this->setResponse($curl);
     curl_close($curl);
 }
예제 #3
0
 public static function setTokenStore($serializerClass)
 {
     self::$tokenStore = $serializerClass;
 }
예제 #4
0
 public static function setUpBeforeClass()
 {
     Castle::setApiKey('secretkey');
 }
예제 #5
0
 /**
  *
  */
 public function testRequestContextHeaders()
 {
     $_SERVER['HTTP_COOKIE'] = 'Should not be sent';
     Castle::track(array('name' => '$login.succeeded', 'user_id' => '1'));
     $this->assertRequest('post', '/events', array('X-Castle-Headers' => '{"User-Agent":"TestAgent"}'));
 }
예제 #6
0
 public function send($method, $url, $params = null)
 {
     $this->preFlightCheck();
     $client = self::clientUserAgent();
     $body = empty($params) ? null : json_encode($params);
     $cookies = Castle::getCookieStore();
     $requestHeaders = json_encode(self::getHeaders());
     $headers = array('X-Castle-Cookie-Id: ' . $cookies->read('__cid'), 'X-Castle-User-Agent: ' . self::getUserAgent(), 'X-Castle-Headers: ' . $requestHeaders, 'X-Castle-Ip: ' . self::getIp(), 'X-Castle-Client-User-Agent: ' . $client, 'Content-Type: application/json', 'Content-Length: ' . strlen($body));
     // Check if there is a current session and pass it along
     $session = Castle::getTokenStore()->getSession();
     if (isset($session)) {
         $headers[] = 'X-Castle-Session-Token: ' . $session;
     }
     $request = new Castle_RequestTransport();
     $request->send($method, self::apiUrl($url), $body, $headers);
     return $this->handleResponse($request);
 }
예제 #7
0
 public function testTrack()
 {
     Castle_RequestTransport::setResponse(204, '');
     Castle::track(array('name' => '$login.failed'));
     $this->assertRequest('post', '/events');
 }
예제 #8
0
<?php

/* Default Constants
 */
define('ROOT', getcwd());
/* Include config files and auto load the needed classes.
 */
include_once "Functions.php";
include_once ROOT . "/app/Config/config.php";
include_once "Constants.php";
spl_autoload_register(function ($class) {
    $path = __DIR__ . '/Classes/' . $class . '.php';
    if (file_exists($path)) {
        include_once $path;
    }
});
/* Added the BaseController here by default.
 * Because I think auto loading all controllers & models even if not used is waste of runtime.
 */
$base_controller = CONTROLLERS_PATH . 'BaseController.php';
if (file_exists($base_controller)) {
    include_once $base_controller;
}
/* Lets GO!
 */
session_start();
Castle::initialize();
예제 #9
0
 /**
  * @expectedException Castle_ConfigurationError
  */
 public function testConfiguration()
 {
     Castle::setApiKey(null);
     $this->request->send('GET', '/test');
 }
예제 #10
0
 public function setUp()
 {
     Castle::setApiKey('secret');
 }
예제 #11
0
 private static function init()
 {
     $king = new King();
     $king->init();
     self::$king = $king;
 }
예제 #12
0
 /**
  * Log out process: delete cookie, delete session
  */
 public static function logout()
 {
     if (Config::get('CASTLE_ENABLED')) {
         Castle::setApiKey(Config::get('CASTLE_SECRET'));
         Castle::logout();
         Castle::track(array('name' => '$logout.succeeded', 'user_id' => Session::get('user_id')));
     }
     self::deleteCookie();
     Session::destroy();
 }
예제 #13
0
 public function testApprove()
 {
     Castle_RequestTransport::setResponse(200, '{}');
     Castle::authentications(1)->approve();
     $this->assertRequest('post', '/authentications/1/approve');
 }