mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-22 13:09:44 +05:30
CryptTrait tests
This commit is contained in:
parent
c2e83ff359
commit
890fdeba16
@ -16,11 +16,11 @@ class AccessTokenEntity implements AccessTokenEntityInterface
|
|||||||
/**
|
/**
|
||||||
* Generate a JWT from the access token
|
* Generate a JWT from the access token
|
||||||
*
|
*
|
||||||
* @param string $pathToPrivateKey
|
* @param string $privateKeyPath
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function convertToJWT($pathToPrivateKey)
|
public function convertToJWT($privateKeyPath)
|
||||||
{
|
{
|
||||||
return (new Builder())
|
return (new Builder())
|
||||||
->setAudience($this->getClient()->getIdentifier())
|
->setAudience($this->getClient()->getIdentifier())
|
||||||
@ -30,7 +30,7 @@ class AccessTokenEntity implements AccessTokenEntityInterface
|
|||||||
->setExpiration($this->getExpiryDateTime()->getTimestamp())
|
->setExpiration($this->getExpiryDateTime()->getTimestamp())
|
||||||
->setSubject($this->getUserIdentifier())
|
->setSubject($this->getUserIdentifier())
|
||||||
->set('scopes', $this->getScopes())
|
->set('scopes', $this->getScopes())
|
||||||
->sign(new Sha256(), new Key($pathToPrivateKey))
|
->sign(new Sha256(), new Key($privateKeyPath))
|
||||||
->getToken();
|
->getToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ interface AccessTokenEntityInterface extends TokenInterface
|
|||||||
/**
|
/**
|
||||||
* Generate a JWT from the access token
|
* Generate a JWT from the access token
|
||||||
*
|
*
|
||||||
* @param string $pathToPrivateKey
|
* @param string $privateKeyPath
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function convertToJWT($pathToPrivateKey);
|
public function convertToJWT($privateKeyPath);
|
||||||
}
|
}
|
||||||
|
@ -89,14 +89,14 @@ interface GrantTypeInterface extends EmitterAwareInterface
|
|||||||
/**
|
/**
|
||||||
* Set the path to the private key.
|
* Set the path to the private key.
|
||||||
*
|
*
|
||||||
* @param string $pathToPrivateKey
|
* @param string $privateKeyPath
|
||||||
*/
|
*/
|
||||||
public function setPrivateKeyPath($pathToPrivateKey);
|
public function setPrivateKeyPath($privateKeyPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the path to the public key.
|
* Set the path to the public key.
|
||||||
*
|
*
|
||||||
* @param string $pathToPublicKey
|
* @param string $publicKeyPath
|
||||||
*/
|
*/
|
||||||
public function setPublicKeyPath($pathToPublicKey);
|
public function setPublicKeyPath($publicKeyPath);
|
||||||
}
|
}
|
||||||
|
46
tests/CryptTraitTest.php
Normal file
46
tests/CryptTraitTest.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LeagueTests\Utils;
|
||||||
|
|
||||||
|
use LeagueTests\Stubs\CryptTraitStub;
|
||||||
|
|
||||||
|
class CryptTraitTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* CryptTrait stub
|
||||||
|
*/
|
||||||
|
protected $cryptStub;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->cryptStub = new CryptTraitStub;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEncryptDecrypt()
|
||||||
|
{
|
||||||
|
$payload = 'alex loves whisky';
|
||||||
|
$encrypted = $this->cryptStub->doEncrypt($payload);
|
||||||
|
$plainText = $this->cryptStub->doDecrypt($encrypted);
|
||||||
|
|
||||||
|
$this->assertNotEquals($payload, $encrypted);
|
||||||
|
$this->assertEquals($payload, $plainText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LogicException
|
||||||
|
*/
|
||||||
|
public function testBadPrivateKey()
|
||||||
|
{
|
||||||
|
$this->cryptStub->setPrivateKeyPath(__DIR__ . '/Stubs/public.key');
|
||||||
|
$this->cryptStub->doEncrypt('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LogicException
|
||||||
|
*/
|
||||||
|
public function testBadPublicKey()
|
||||||
|
{
|
||||||
|
$this->cryptStub->setPublicKeyPath(__DIR__ . '/Stubs/private.key');
|
||||||
|
$this->cryptStub->doDecrypt('');
|
||||||
|
}
|
||||||
|
}
|
@ -23,8 +23,8 @@ class AbstractGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
/** @var AbstractGrant $grantMock */
|
/** @var AbstractGrant $grantMock */
|
||||||
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
||||||
$grantMock->setPathToPrivateKey('./private.key');
|
$grantMock->setPrivateKeyPath('./private.key');
|
||||||
$grantMock->setPathToPublicKey('./public.key');
|
$grantMock->setPublicKeyPath('./public.key');
|
||||||
$grantMock->setEmitter(new Emitter());
|
$grantMock->setEmitter(new Emitter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
|||||||
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
|
use LeagueTests\Stubs\CryptTraitStub;
|
||||||
use LeagueTests\Stubs\ScopeEntity;
|
use LeagueTests\Stubs\ScopeEntity;
|
||||||
use LeagueTests\Stubs\StubResponseType;
|
use LeagueTests\Stubs\StubResponseType;
|
||||||
use LeagueTests\Stubs\UserEntity;
|
use LeagueTests\Stubs\UserEntity;
|
||||||
@ -22,6 +22,16 @@ use Zend\Diactoros\ServerRequest;
|
|||||||
|
|
||||||
class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* CryptTrait stub
|
||||||
|
*/
|
||||||
|
protected $cryptStub;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->cryptStub = new CryptTraitStub;
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetIdentifier()
|
public function testGetIdentifier()
|
||||||
{
|
{
|
||||||
$grant = new AuthCodeGrant(
|
$grant = new AuthCodeGrant(
|
||||||
@ -78,8 +88,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -92,9 +102,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -133,8 +143,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -147,9 +157,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -193,8 +203,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -207,9 +217,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -244,8 +254,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -258,9 +268,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -299,8 +309,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -313,9 +323,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -360,8 +370,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -410,8 +420,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -424,9 +434,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => null]),
|
json_encode(['user_id' => null]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -464,8 +474,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -478,9 +488,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => null]),
|
json_encode(['user_id' => null]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -520,8 +530,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
new \DateInterval('PT10M')
|
new \DateInterval('PT10M')
|
||||||
);
|
);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -534,9 +544,9 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -587,8 +597,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -603,7 +613,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => KeyCrypt::encrypt(
|
'code' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'auth_code_id' => uniqid(),
|
'auth_code_id' => uniqid(),
|
||||||
@ -614,7 +624,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -646,8 +656,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -692,8 +702,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -743,8 +753,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -759,7 +769,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => KeyCrypt::encrypt(
|
'code' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'auth_code_id' => uniqid(),
|
'auth_code_id' => uniqid(),
|
||||||
@ -770,7 +780,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -813,8 +823,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -829,7 +839,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => KeyCrypt::encrypt(
|
'code' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'auth_code_id' => uniqid(),
|
'auth_code_id' => uniqid(),
|
||||||
@ -840,7 +850,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -880,8 +890,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
@ -896,7 +906,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'grant_type' => 'authorization_code',
|
'grant_type' => 'authorization_code',
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
'code' => KeyCrypt::encrypt(
|
'code' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'auth_code_id' => uniqid(),
|
'auth_code_id' => uniqid(),
|
||||||
@ -907,7 +917,7 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'redirect_uri' => 'http://foo/bar',
|
'redirect_uri' => 'http://foo/bar',
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -947,8 +957,8 @@ class AuthCodeGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
$grant->setRefreshTokenRepository($refreshTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[],
|
[],
|
||||||
|
@ -7,7 +7,6 @@ use League\OAuth2\Server\Grant\ImplicitGrant;
|
|||||||
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
|
||||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
use LeagueTests\Stubs\StubResponseType;
|
use LeagueTests\Stubs\StubResponseType;
|
||||||
use LeagueTests\Stubs\UserEntity;
|
use LeagueTests\Stubs\UserEntity;
|
||||||
@ -16,6 +15,16 @@ use Zend\Diactoros\ServerRequest;
|
|||||||
|
|
||||||
class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* CryptTrait stub
|
||||||
|
*/
|
||||||
|
protected $cryptStub;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->cryptStub = new CryptTraitStub;
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetIdentifier()
|
public function testGetIdentifier()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
@ -60,8 +69,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new ImplicitGrant($userRepositoryMock);
|
$grant = new ImplicitGrant($userRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -99,8 +108,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testRespondToAuthorizationRequestMissingClientId()
|
public function testRespondToAuthorizationRequestMissingClientId()
|
||||||
{
|
{
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -113,9 +122,9 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -141,8 +150,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -155,9 +164,9 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -191,8 +200,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -205,9 +214,9 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -247,8 +256,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -292,8 +301,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -306,9 +315,9 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => null]),
|
json_encode(['user_id' => null]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -341,8 +350,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -355,9 +364,9 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -389,8 +398,8 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
$grant = new ImplicitGrant($this->getMock(UserRepositoryInterface::class));
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$request = new ServerRequest(
|
$request = new ServerRequest(
|
||||||
[
|
[
|
||||||
@ -403,9 +412,9 @@ class ImplicitGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'php://input',
|
'php://input',
|
||||||
[],
|
[],
|
||||||
[
|
[
|
||||||
'oauth_authorize_request' => KeyCrypt::encrypt(
|
'oauth_authorize_request' => $this->cryptStub->doEncrypt(
|
||||||
json_encode(['user_id' => 123]),
|
json_encode(['user_id' => 123]),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -9,7 +9,6 @@ use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
|||||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
||||||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
|
||||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
|
||||||
use LeagueTests\Stubs\ClientEntity;
|
use LeagueTests\Stubs\ClientEntity;
|
||||||
use LeagueTests\Stubs\ScopeEntity;
|
use LeagueTests\Stubs\ScopeEntity;
|
||||||
use LeagueTests\Stubs\StubResponseType;
|
use LeagueTests\Stubs\StubResponseType;
|
||||||
@ -17,6 +16,16 @@ use Zend\Diactoros\ServerRequest;
|
|||||||
|
|
||||||
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* CryptTrait stub
|
||||||
|
*/
|
||||||
|
protected $cryptStub;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->cryptStub = new CryptTraitStub;
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetIdentifier()
|
public function testGetIdentifier()
|
||||||
{
|
{
|
||||||
$refreshTokenRepositoryMock = $this->getMock(RefreshTokenRepositoryInterface::class);
|
$refreshTokenRepositoryMock = $this->getMock(RefreshTokenRepositoryInterface::class);
|
||||||
@ -47,10 +56,10 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = KeyCrypt::encrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
@ -61,7 +70,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'expire_time' => time() + 3600,
|
'expire_time' => time() + 3600,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
@ -103,10 +112,10 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = KeyCrypt::encrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
@ -117,7 +126,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'expire_time' => time() + 3600,
|
'expire_time' => time() + 3600,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
@ -164,10 +173,10 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setScopeRepository($scopeRepositoryMock);
|
$grant->setScopeRepository($scopeRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = KeyCrypt::encrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
@ -178,7 +187,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'expire_time' => time() + 3600,
|
'expire_time' => time() + 3600,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
@ -213,8 +222,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
$serverRequest = $serverRequest->withParsedBody(
|
$serverRequest = $serverRequest->withParsedBody(
|
||||||
@ -246,8 +255,8 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = 'foobar';
|
$oldRefreshToken = 'foobar';
|
||||||
|
|
||||||
@ -286,10 +295,10 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = KeyCrypt::encrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'client_id' => 'bar',
|
'client_id' => 'bar',
|
||||||
@ -300,7 +309,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'expire_time' => time() + 3600,
|
'expire_time' => time() + 3600,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
@ -334,10 +343,10 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = KeyCrypt::encrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
@ -348,7 +357,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'expire_time' => time() - 3600,
|
'expire_time' => time() - 3600,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
@ -383,10 +392,10 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
$grant = new RefreshTokenGrant($refreshTokenRepositoryMock);
|
||||||
$grant->setClientRepository($clientRepositoryMock);
|
$grant->setClientRepository($clientRepositoryMock);
|
||||||
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
$grant->setAccessTokenRepository($accessTokenRepositoryMock);
|
||||||
$grant->setPathToPublicKey('file://' . __DIR__ . '/../Utils/public.key');
|
$grant->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');
|
||||||
$grant->setPathToPrivateKey('file://' . __DIR__ . '/../Utils/private.key');
|
$grant->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key');
|
||||||
|
|
||||||
$oldRefreshToken = KeyCrypt::encrypt(
|
$oldRefreshToken = $this->cryptStub->doEncrypt(
|
||||||
json_encode(
|
json_encode(
|
||||||
[
|
[
|
||||||
'client_id' => 'foo',
|
'client_id' => 'foo',
|
||||||
@ -397,7 +406,7 @@ class RefreshTokenGrantTest extends \PHPUnit_Framework_TestCase
|
|||||||
'expire_time' => time() + 3600,
|
'expire_time' => time() + 3600,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
'file://' . __DIR__ . '/../Utils/private.key'
|
'file://' . __DIR__ . '/../Stubs/private.key'
|
||||||
);
|
);
|
||||||
|
|
||||||
$serverRequest = new ServerRequest();
|
$serverRequest = new ServerRequest();
|
||||||
|
@ -20,8 +20,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
||||||
|
|
||||||
$responseType = new BearerTokenResponse(
|
$responseType = new BearerTokenResponse(
|
||||||
'file://' . __DIR__ . '/../Utils/private.key',
|
'file://' . __DIR__ . '/../Stubs/private.key',
|
||||||
'file://' . __DIR__ . '/../Utils/public.key',
|
'file://' . __DIR__ . '/../Stubs/public.key',
|
||||||
$accessTokenRepositoryMock
|
$accessTokenRepositoryMock
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -66,8 +66,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
||||||
|
|
||||||
$responseType = new BearerTokenResponse(
|
$responseType = new BearerTokenResponse(
|
||||||
'file://' . __DIR__ . '/../Utils/private.key',
|
'file://' . __DIR__ . '/../Stubs/private.key',
|
||||||
'file://' . __DIR__ . '/../Utils/public.key',
|
'file://' . __DIR__ . '/../Stubs/public.key',
|
||||||
$accessTokenRepositoryMock
|
$accessTokenRepositoryMock
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -108,8 +108,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
||||||
|
|
||||||
$responseType = new BearerTokenResponse(
|
$responseType = new BearerTokenResponse(
|
||||||
'file://' . __DIR__ . '/../Utils/private.key',
|
'file://' . __DIR__ . '/../Stubs/private.key',
|
||||||
'file://' . __DIR__ . '/../Utils/public.key',
|
'file://' . __DIR__ . '/../Stubs/public.key',
|
||||||
$accessTokenRepositoryMock
|
$accessTokenRepositoryMock
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -154,8 +154,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
|
|
||||||
$responseType = new BearerTokenResponse(
|
$responseType = new BearerTokenResponse(
|
||||||
'file://' . __DIR__ . '/../Utils/private.key',
|
'file://' . __DIR__ . '/../Stubs/private.key',
|
||||||
'file://' . __DIR__ . '/../Utils/public.key',
|
'file://' . __DIR__ . '/../Stubs/public.key',
|
||||||
$accessTokenRepositoryMock
|
$accessTokenRepositoryMock
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -198,8 +198,8 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
|
||||||
|
|
||||||
$responseType = new BearerTokenResponse(
|
$responseType = new BearerTokenResponse(
|
||||||
'file://' . __DIR__ . '/../Utils/private.key',
|
'file://' . __DIR__ . '/../Stubs/private.key',
|
||||||
'file://' . __DIR__ . '/../Utils/public.key',
|
'file://' . __DIR__ . '/../Stubs/public.key',
|
||||||
$accessTokenRepositoryMock
|
$accessTokenRepositoryMock
|
||||||
);
|
);
|
||||||
|
|
||||||
|
26
tests/Stubs/CryptTraitStub.php
Normal file
26
tests/Stubs/CryptTraitStub.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LeagueTests\Stubs;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\CryptTrait;
|
||||||
|
|
||||||
|
class CryptTraitStub
|
||||||
|
{
|
||||||
|
use CryptTrait;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->setPrivateKeyPath('file://' . __DIR__ . '/private.key');
|
||||||
|
$this->setPublicKeyPath('file://' . __DIR__ . '/public.key');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doEncrypt($unencryptedData)
|
||||||
|
{
|
||||||
|
return $this->encrypt($unencryptedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doDecrypt($encryptedData)
|
||||||
|
{
|
||||||
|
return $this->decrypt($encryptedData);
|
||||||
|
}
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace LeagueTests\Utils;
|
|
||||||
|
|
||||||
use League\OAuth2\Server\Utils\KeyCrypt;
|
|
||||||
|
|
||||||
class KeyCryptTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
|
||||||
public function testEncryptDecrypt()
|
|
||||||
{
|
|
||||||
$payload = 'alex loves whisky';
|
|
||||||
$encrypted = KeyCrypt::encrypt($payload, 'file://' . __DIR__ . '/private.key');
|
|
||||||
$plainText = KeyCrypt::decrypt($encrypted, 'file://' . __DIR__ . '/public.key');
|
|
||||||
|
|
||||||
$this->assertNotEquals($payload, $encrypted);
|
|
||||||
$this->assertEquals($payload, $plainText);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testBadPrivateKey()
|
|
||||||
{
|
|
||||||
KeyCrypt::encrypt('', 'file://' . __DIR__ . '/public.key');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \LogicException
|
|
||||||
*/
|
|
||||||
public function testBadPublicKey()
|
|
||||||
{
|
|
||||||
KeyCrypt::decrypt('', 'file://' . __DIR__ . '/private.key');
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user