public static function setUpBeforeClass() { Castle::setApiKey('secretkey'); $_SERVER = array(); $_SERVER['HTTP_USER_AGENT'] = 'TestAgent'; $_SERVER['REMOTE_ADDR'] = '8.8.8.8'; }
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); }
public static function setTokenStore($serializerClass) { self::$tokenStore = $serializerClass; }
public static function setUpBeforeClass() { Castle::setApiKey('secretkey'); }
/** * */ 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"}')); }
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); }
public function testTrack() { Castle_RequestTransport::setResponse(204, ''); Castle::track(array('name' => '$login.failed')); $this->assertRequest('post', '/events'); }
<?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();
/** * @expectedException Castle_ConfigurationError */ public function testConfiguration() { Castle::setApiKey(null); $this->request->send('GET', '/test'); }
public function setUp() { Castle::setApiKey('secret'); }
private static function init() { $king = new King(); $king->init(); self::$king = $king; }
/** * 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(); }
public function testApprove() { Castle_RequestTransport::setResponse(200, '{}'); Castle::authentications(1)->approve(); $this->assertRequest('post', '/authentications/1/approve'); }