public function setUp()
 {
     $ioStub = $this->getMockBuilder('fkooman\\IO\\IO')->getMock();
     $ioStub->method('getRandom')->will($this->onConsecutiveCalls(2, 3, 5, 7));
     $db = new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']);
     $md = new MetadataStorage($db, '', $ioStub);
     $md->initDatabase();
     $tempFile = tempnam(sys_get_temp_dir(), '');
     if (file_exists($tempFile)) {
         @unlink($tempFile);
     }
     mkdir($tempFile);
     $this->tempFile = $tempFile;
     $document = new DocumentStorage($tempFile);
     $remoteStorage = new RemoteStorage($md, $document);
     $approvalManagementStorage = new ApprovalManagementStorage($db);
     $userAuth = new TestAuthentication();
     $apiAuth = new BearerAuthentication(new TestTokenValidator());
     $authenticationPlugin = new AuthenticationPlugin();
     $authenticationPlugin->register($userAuth, 'user');
     $authenticationPlugin->register($apiAuth, 'api');
     $this->r = new RemoteStorageService($remoteStorage, $approvalManagementStorage, new TestTemplateManager(), new RemoteStorageClientStorage(), new RemoteStorageResourceServer(), new TestApproval(), new TestAuthorizationCode(), new TestAccessToken(), array('server_mode' => 'production'), $ioStub);
     $this->r->getPluginRegistry()->registerDefaultPlugin($authenticationPlugin);
 }
Beispiel #2
0
    $templateManager->setDefault(array('rootFolder' => $request->getUrl()->getRoot(), 'serverMode' => $serverMode));
    $md = new MetadataStorage($db);
    $approvalStorage = new PdoApprovalStorage($db);
    $authorizationCodeStorage = new PdoAuthorizationCodeStorage($db);
    $accessTokenStorage = new PdoAccessTokenStorage($db);
    if ($initDb) {
        $md->initDatabase();
        $approvalStorage->initDatabase();
        $authorizationCodeStorage->initDatabase();
        $accessTokenStorage->initDatabase();
    }
    $remoteStorage = new RemoteStorage($md, $document);
    $session = new Session('php-remote-storage', array('secure' => 'development' !== $serverMode));
    $userAuth = new FormAuthentication(function ($userId) use($configReader) {
        $userList = $configReader->v('Users');
        if (null === $userList || !array_key_exists($userId, $userList)) {
            return false;
        }
        return $userList[$userId];
    }, $templateManager, $session);
    $apiAuth = new BearerAuthentication(new DbTokenValidator($db), array('realm' => 'remoteStorage'));
    $authenticationPlugin = new AuthenticationPlugin();
    $authenticationPlugin->register($userAuth, 'user');
    $authenticationPlugin->register($apiAuth, 'api');
    $service = new RemoteStorageService($remoteStorage, new ApprovalManagementStorage($db), $templateManager, new RemoteStorageClientStorage(), new RemoteStorageResourceServer(), $approvalStorage, $authorizationCodeStorage, $accessTokenStorage, array('disable_token_endpoint' => true, 'disable_introspect_endpoint' => true, 'route_prefix' => '/_oauth', 'require_state' => false, 'server_mode' => $serverMode));
    $service->getPluginRegistry()->registerDefaultPlugin($authenticationPlugin);
    $service->run($request)->send();
} catch (Exception $e) {
    error_log($e->getMessage());
    die(sprintf('ERROR: %s', $e->getMessage()));
}