public function testCreateClient()
 {
     $container = ContainerLoader::buildTestContainer();
     $command = new CreateClientCommand();
     $command->setContainer($container);
     $client_id = 'Client-ID-' . rand();
     $redirectUris = 'http://brentertainment.com';
     $grantTypes = 'authorization_code,client_credentials';
     $scope = 'scope1';
     // ensure the scope exists
     $scopeStorage = $container->get('oauth2.storage.scope');
     if (!$scopeStorage->scopeExists($scope)) {
         $scopeManager = $container->get('oauth2.scope_manager');
         $scopeManager->createScope($scope, 'test scope');
     }
     $input = new ArgvInput(array('command', $client_id, $redirectUris, $grantTypes, $scope));
     $output = new BufferedOutput();
     $statusCode = $command->run($input, $output);
     $this->assertEquals(0, $statusCode, $output->fetch());
     // verify client details have been stored
     $storage = $container->get('oauth2.storage.client_credentials');
     $client = $storage->getClientDetails($client_id);
     $this->assertNotNull($client);
     $this->assertEquals($redirectUris, $client['redirect_uri']);
     $this->assertEquals(explode(',', $grantTypes), $client['grant_types']);
     // verify client scope has been stored
     $clientScope = $storage->getClientScope($client_id);
     $this->assertEquals($scope, $clientScope);
 }
 public function testCreate()
 {
     $container = ContainerLoader::buildTestContainer();
     $em = $container->get('doctrine.orm.entity_manager');
     $client = new Client();
     $client->setClientId($token = 'test-client-' . rand());
     $client->setClientSecret('very-secure');
     $client->setRedirectUri(array('http://brentertainment.com'));
     $em->persist($client);
     $em->flush();
     $public_key = new ClientPublicKey();
     $public_key->setClient($client);
     // create and set the public key
     $res = openssl_pkey_new();
     // Extract the public key from $res to $pubKey
     $pubKeyDetails = openssl_pkey_get_details($res);
     $pubKey = $pubKeyDetails['key'];
     $public_key->setPublicKey($pubKey);
     $em->persist($public_key);
     $em->flush();
     // test direct access
     $stored = $em->find('OAuth2\\ServerBundle\\Entity\\ClientPublicKey', array('client_id' => $client->getClientId()));
     $this->assertNotNull($stored);
     $this->assertEquals($pubKey, $stored->getPublicKey());
 }
    public function testOpenIdConfig()
    {
        $openIdConfig = <<<EOF
<?xml version="1.0"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <parameters>
        <parameter key="oauth2.server.config" type="collection">
            <parameter key="use_openid_connect">true</parameter>
            <parameter key="issuer">oauth2-server-bundle</parameter>
        </parameter>
    </parameters>
</container>
EOF;
        file_put_contents($tmpFile = tempnam(sys_get_temp_dir(), 'openid-config'), $openIdConfig);
        $container = ContainerLoader::buildTestContainer(array(__DIR__ . '/../vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml', $tmpFile));
        $config = $container->getParameter('oauth2.server.config');
        $server = $container->get('oauth2.server');
        $this->assertTrue($server->getConfig('use_openid_connect'));
        $this->assertNotNull($server->getStorage('public_key'));
        $clientId = 'test-client-' . rand();
        $server->getStorage('public_key')->keys['public_key'] = file_get_contents(__DIR__ . '/../vendor/bshaffer/oauth2-server-php/test/config/keys/id_rsa.pub');
        $server->getStorage('public_key')->keys['private_key'] = file_get_contents(__DIR__ . '/../vendor/bshaffer/oauth2-server-php/test/config/keys/id_rsa');
        $server->getStorage('client_credentials')->setClientDetails($clientId, 'test-client-secret');
        $request = new Request(array('client_id' => $clientId, 'redirect_uri' => 'http://brentertainment.com', 'response_type' => 'code', 'scope' => 'openid', 'state' => 'xyz'));
        $response = new Response();
        $server->handleAuthorizeRequest($request, $response, true);
        $parts = parse_url($response->getHttpHeader('Location'));
        parse_str($parts['query'], $query);
        $code = $server->getStorage('authorization_code')->getAuthorizationCode($query['code']);
        $this->assertArrayHasKey('id_token', $code);
    }
예제 #4
0
 public function testCreate()
 {
     $container = ContainerLoader::buildTestContainer();
     $em = $container->get('doctrine.orm.entity_manager');
     $scope = new Scope();
     $scope->setScope($name = 'test-scope-' . rand());
     $scope->setDescription('A Scope for Testing');
     $em->persist($scope);
     $em->flush();
     $stored = $em->find('OAuth2\\ServerBundle\\Entity\\Scope', array('scope' => $name));
     $this->assertNotNull($stored);
     $this->assertEquals($name, $stored->getScope());
     $this->assertEquals($scope->getDescription(), $stored->getDescription());
 }
 public function testCreate()
 {
     $container = ContainerLoader::buildTestContainer();
     $em = $container->get('doctrine.orm.entity_manager');
     $refresh_token = new RefreshToken();
     $refresh_token->setToken($token = 'test-token-' . rand());
     $refresh_token->setExpires(new \DateTime('+10 minutes'));
     // ten minutes from now
     $em->persist($refresh_token);
     $em->flush();
     $stored = $em->find('OAuth2\\ServerBundle\\Entity\\RefreshToken', array('token' => $token));
     $this->assertNotNull($stored);
     $this->assertEquals($token, $stored->getToken());
     $this->assertEquals($refresh_token->getExpires(), $stored->getExpires());
 }
예제 #6
0
 public function testCreate()
 {
     $container = ContainerLoader::buildTestContainer();
     $em = $container->get('doctrine.orm.entity_manager');
     $client = new Client();
     $client->setClientId($client_id = 'This Is My Client ID ' . rand());
     $client->setClientSecret('very-secure');
     $client->setRedirectUri(array('http://brentertainment.com'));
     $em->persist($client);
     $em->flush();
     $stored = $em->find('OAuth2\\ServerBundle\\Entity\\Client', array('client_id' => $client_id));
     $this->assertNotNull($stored);
     $this->assertEquals($client_id, $stored->getClientId());
     $this->assertEquals($client->getClientSecret(), $stored->getClientSecret());
     $this->assertEquals($client->getRedirectUri(), $stored->getRedirectUri());
 }
예제 #7
0
 public function testCreate()
 {
     $container = ContainerLoader::buildTestContainer();
     $em = $container->get('doctrine.orm.entity_manager');
     $user = new User();
     $user->setUsername($name = 'test-user-' . rand());
     $user->setPassword('very-secure');
     $user->setSalt(sha1(time()));
     $em->persist($user);
     $em->flush();
     $stored = $em->find('OAuth2\\ServerBundle\\Entity\\User', array('username' => $name));
     $this->assertNotNull($stored);
     $this->assertEquals($name, $stored->getUsername());
     $this->assertEquals($user->getPassword(), $stored->getPassword());
     $this->assertEquals($user->getSalt(), $stored->getSalt());
 }
 public function testCreate()
 {
     $container = ContainerLoader::buildTestContainer();
     $em = $container->get('doctrine.orm.entity_manager');
     $authcode = new AuthorizationCode();
     $authcode->setCode($code = 'test-code-' . rand());
     $authcode->setExpires(new \DateTime('+10 minutes'));
     // ten minutes from now
     $authcode->setRedirectUri('http://brentertainment.com');
     $em->persist($authcode);
     $em->flush();
     $stored = $em->find('OAuth2\\ServerBundle\\Entity\\AuthorizationCode', array('code' => $code));
     $this->assertNotNull($stored);
     $this->assertEquals($code, $stored->getCode());
     $this->assertEquals($authcode->getExpires(), $stored->getExpires());
     $this->assertEquals($authcode->getRedirectUri(), $stored->getRedirectUri());
 }
 public function testOpenIdConfig()
 {
     $container = ContainerLoader::buildTestContainer(array(__DIR__ . '/../../vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml'));
     $controller = new AuthorizeController();
     $controller->setContainer($container);
     $clientId = 'test-client-' . rand();
     $server = $container->get('oauth2.server');
     $server->getStorage('client_credentials')->setClientDetails($clientId, 'test-client-secret', 'http://brentertainment.com');
     $request = new Request(array('client_id' => $clientId, 'response_type' => 'code', 'scope' => 'openid', 'state' => 'xyz', 'foo' => 'bar', 'nonce' => '123'));
     $container->set('oauth2.request', $request);
     $params = $controller->validateAuthorizeAction();
     $this->assertArrayHasKey('nonce', $params['qs'], 'optional included param');
     $this->assertArrayNotHasKey('foo', $params['qs'], 'invalid included param');
     $this->assertArrayNotHasKey('redirect_uri', $params['qs'], 'optional excluded param');
     $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../Resources/views');
     $twig = new \Twig_Environment($loader);
     $template = $twig->loadTemplate('Authorize/authorize.html.twig');
     $html = $template->render($params);
     $this->assertContains(htmlentities(http_build_query($params['qs'])), $html);
 }
예제 #10
0
<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;
use OAuth2\ServerBundle\Tests\ContainerLoader;
// autoloading, etc
require_once __DIR__ . '/bootstrap.php';
// create "test" service container
$container = ContainerLoader::buildTestContainer();
$entityManager = $container->get('doctrine.orm.entity_manager');
return ConsoleRunner::createHelperSet($entityManager);