/**
  *
  */
 public function __construct()
 {
     $app = App::getInstance();
     $config = $app->get('Config');
     $this->proxyconfig = $config->get('jmapproxy');
     $this->logger = Logger::get('jmapproxy');
 }
示例#2
0
 /**
  *
  */
 public function init(Controller $controller)
 {
     $this->ctrl = $controller;
     // register route /jmap to controller
     $controller->routes['jmap'] = [$this, 'process'];
     // register myself as provider for some JMAP commands
     $this->methodmap['getAccounts'] = [$this];
     $app = App::getInstance();
     $config = $app->get('Config');
     // load providers from config
     foreach ((array) $config->get('jmap.providers') as $providerclass) {
         try {
             $provider = $app->get($providerclass);
             if ($provider instanceof JmapProvider) {
                 $this->addProvider($provider);
             } else {
                 throw new \RuntimeException("The provider class {$providerclass} doesn't implement Roundcube\\JMAP\\Provider");
             }
         } catch (\RuntimeException $e) {
             // TODO: log this
         }
     }
     // allow plugins to register JMAP providers
     $controller->emit('jmap:init', [$this]);
 }
 public function setUp()
 {
     $app = App::getInstance();
     $this->server = $app->get('Server\\Controller');
     $this->server->sapi = new \Mock\SapiMock();
     $this->server->httpResponse = new JMAP\Response();
     $this->server->debugExceptions = true;
     // fake authenticated session
     $this->session = $app->get('Session');
     $this->session->start();
     $this->session->set('Auth\\authenticated', time());
 }
 public function testRefetchUrls()
 {
     // fake authenticated session
     $session = App::getInstance()->get('Session');
     $session->start();
     $session->set('Auth\\authenticated', time());
     $session->set('Auth\\identity', new Auth\AuthenticatedIdentity(['username' => 'test']));
     $response = $this->sendRequest(null, '/auth', ['Authorization' => 'X-JMAP ' . $session->key]);
     $jsondata = json_decode($response->getBody(), true);
     $this->assertEquals(200, $response->getStatus());
     $this->assertEquals('application/json', $response->getHeader('content-type'));
     $this->assertArrayHasKey('apiUrl', $jsondata);
 }
 public function setUp()
 {
     if ($this->initialized) {
         return;
     }
     $app = App::getInstance();
     // force the plugin to be loaded
     $app->loadPlugin('Roundcube\\Plugins\\NFactorAuthPlugin', ['code' => 'xxxxxx'], true);
     $this->server = $app->get('Server\\Controller');
     $this->server->sapi = new \Mock\SapiMock();
     $this->server->debugExceptions = true;
     // register a Mock JMAP auth provider
     $config = $app->get('Config');
     $config->set('auth', ['providers' => ['Mock\\JmapAuthProviderMock']]);
     $this->server->addProcessor(new Processor\Auth());
     $this->initialized = true;
 }
<?php

/**
 * PHPUnit bootstrapping routine
 *
 * This file is part of the Roundcube server test suite
 *
 * @author Thomas Bruederli <*****@*****.**>
 *
 * Copyright (C) 2015, Roundcube Dev Team
 *
 * Licensed under the GNU General Public License version 3 or
 * any later version as published by the Free Software Foundation.
 * For full license information see http://www.gnu.org/licenses/gpl-3.0
 */
date_default_timezone_set('UTC');
ini_set('error_reporting', E_ALL | E_STRICT | E_DEPRECATED);
define('ROUNDCUBE_INSTALL_ROOT', realpath('../'));
define('ROUNDCUBE_ENV', 'test');
// Composer autoloader
$loader = (require ROUNDCUBE_INSTALL_ROOT . '/vendor/autoload.php');
$loader->add('Roundcube\\', ROUNDCUBE_INSTALL_ROOT . '/lib');
$loader->add('Mock\\', __DIR__);
// create server app instance
\Roundcube\Server\App::getInstance(ROUNDCUBE_ENV);
示例#7
0
 /**
  *
  */
 public static function checkJmapAuth(Request $request, AuthenticatedIdentity &$identity = null)
 {
     // check authentication status
     $token = $request->getHeader('Authorization');
     if (empty($token)) {
         return 401;
     }
     // cut off authorization scheme
     $token = preg_replace('/^X-JMAP\\s+/', '', $token);
     // load session data for the given auth token
     $session = App::getInstance()->get('Session');
     $session->start($token);
     if (empty($session->get('Auth\\authenticated'))) {
         return 401;
     }
     // load identity from session
     $identity = $session->get('Auth\\identity');
     return 200;
 }
示例#8
0
    define('ROUNDCUBE_CONFIG_DIR', ROUNDCUBE_INSTALL_ROOT . 'config');
}
if (!defined('ROUNDCUBE_LOCALIZATION_DIR')) {
    define('ROUNDCUBE_LOCALIZATION_DIR', ROUNDCUBE_INSTALL_ROOT . 'locale/');
}
if (!defined('ROUNDCUBE_ENV')) {
    define('ROUNDCUBE_ENV', 'prod');
}
// use composer's autoloader for both dependencies and local lib
$loader = (require_once ROUNDCUBE_INSTALL_ROOT . '/vendor/autoload.php');
$loader->set('Roundcube', [ROUNDCUBE_INSTALL_ROOT . '/lib']);
// register Roundcube namespace
use Roundcube\Logger;
use Roundcube\Server;
// create server app instance
$app = Server\App::getInstance(ROUNDCUBE_ENV);
$server = $app->get('Server\\Controller');
if (php_sapi_name() !== 'cli-server' && isset($_SERVER['DOCUMENT_ROOT']) && isset($_SERVER['SCRIPT_FILENAME'])) {
    $server->httpRequest->setBaseUrl(substr(dirname($_SERVER['SCRIPT_FILENAME']), strlen($_SERVER['DOCUMENT_ROOT'])) . '/');
}
// attach debug logger
$server->on('process:before', function ($e) {
    $request = $e['request'];
    $request->setBody($request->getBodyAsString());
    // read stdin as string and write back
    Logger::get('http')->debug('process:before', ['request' => strval($request)]);
});
$server->on('process:after', function ($e) {
    Logger::get('http')->debug('process:after', ['response' => strval($e['response'])]);
});
foreach (['jmap:auth:init', 'jmap:auth:more', 'jmap:auth:continue', 'jmap:query', 'jmap:response'] as $eventname) {