mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-16 18:19:47 +05:30
Updated unit tests
This commit is contained in:
parent
38c50c00b0
commit
6eeb7e13e4
@ -40,7 +40,7 @@ class OAuthdb implements Database
|
|||||||
return $this->clients[0];
|
return $this->clients[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newSession($clientId, $redirectUri, $type = 'user', $typeId = null, $authCode = null, $accessToken = null, $accessTokenExpire = null, $stage = 'requested')
|
public function newSession($clientId, $redirectUri, $type = 'user', $typeId = null, $authCode = null, $accessToken = null, $refreshToken = null, $accessTokenExpire = null, $stage = 'requested')
|
||||||
{
|
{
|
||||||
$id = count($this->sessions);
|
$id = count($this->sessions);
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ class OAuthdb implements Database
|
|||||||
'owner_id' => $typeId,
|
'owner_id' => $typeId,
|
||||||
'auth_code' => $authCode,
|
'auth_code' => $authCode,
|
||||||
'access_token' => $accessToken,
|
'access_token' => $accessToken,
|
||||||
|
'refresh_token' => $refreshToken,
|
||||||
'access_token_expire' => $accessTokenExpire,
|
'access_token_expire' => $accessTokenExpire,
|
||||||
'stage' => $stage
|
'stage' => $stage
|
||||||
);
|
);
|
||||||
@ -62,10 +63,11 @@ class OAuthdb implements Database
|
|||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateSession($sessionId, $authCode = null, $accessToken = null, $accessTokenExpire = null, $stage = 'requested')
|
public function updateSession($sessionId, $authCode = null, $accessToken = null, $refreshToken = null, $accessTokenExpire = null, $stage = 'requested')
|
||||||
{
|
{
|
||||||
$this->sessions[$sessionId]['auth_code'] = $authCode;
|
$this->sessions[$sessionId]['auth_code'] = $authCode;
|
||||||
$this->sessions[$sessionId]['access_token'] = $accessToken;
|
$this->sessions[$sessionId]['access_token'] = $accessToken;
|
||||||
|
$this->sessions[$sessionId]['refresh_token'] = $accessToken;
|
||||||
$this->sessions[$sessionId]['access_token_expire'] = $accessTokenExpire;
|
$this->sessions[$sessionId]['access_token_expire'] = $accessTokenExpire;
|
||||||
$this->sessions[$sessionId]['stage'] = $stage;
|
$this->sessions[$sessionId]['stage'] = $stage;
|
||||||
|
|
||||||
@ -81,6 +83,11 @@ class OAuthdb implements Database
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function refreshToken($currentRefreshToken, $newAccessToken, $newRefreshToken, $accessTokenExpires)
|
||||||
|
{
|
||||||
|
die('not implemented refreshToken');
|
||||||
|
}
|
||||||
|
|
||||||
public function validateAuthCode($clientId, $redirectUri, $authCode)
|
public function validateAuthCode($clientId, $redirectUri, $authCode)
|
||||||
{
|
{
|
||||||
$key = $clientId . ':' . $redirectUri . ':' . $authCode;
|
$key = $clientId . ':' . $redirectUri . ':' . $authCode;
|
||||||
|
@ -4,8 +4,8 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
require 'src/OAuth2/Authentication/Server.php';
|
require_once 'src/OAuth2/Authentication/Server.php';
|
||||||
require 'src/OAuth2/Authentication/Database.php';
|
require_once 'src/OAuth2/Authentication/Database.php';
|
||||||
|
|
||||||
$this->oauth = new Oauth2\Authentication\Server();
|
$this->oauth = new Oauth2\Authentication\Server();
|
||||||
|
|
||||||
@ -49,6 +49,12 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase
|
|||||||
$expect = array(
|
$expect = array(
|
||||||
'client_id' => 'test',
|
'client_id' => 'test',
|
||||||
'redirect_uri' => 'http://example.com/test',
|
'redirect_uri' => 'http://example.com/test',
|
||||||
|
'client_details' => array(
|
||||||
|
'client_id' => 'test',
|
||||||
|
'client_secret' => 'test',
|
||||||
|
'redirect_uri' => 'http://example.com/test',
|
||||||
|
'name' => 'Test Client'
|
||||||
|
),
|
||||||
'response_type' => 'code',
|
'response_type' => 'code',
|
||||||
'scopes' => array(
|
'scopes' => array(
|
||||||
0 => array(
|
0 => array(
|
||||||
@ -82,6 +88,12 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
'client_id' => 'test',
|
'client_id' => 'test',
|
||||||
'redirect_uri' => 'http://example.com/test',
|
'redirect_uri' => 'http://example.com/test',
|
||||||
|
'client_details' => array(
|
||||||
|
'client_id' => 'test',
|
||||||
|
'client_secret' => 'test',
|
||||||
|
'redirect_uri' => 'http://example.com/test',
|
||||||
|
'name' => 'Test Client'
|
||||||
|
),
|
||||||
'response_type' => 'code',
|
'response_type' => 'code',
|
||||||
'scopes' => array(0 => array(
|
'scopes' => array(0 => array(
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
@ -216,10 +228,12 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$result = $this->oauth->issueAccessToken();
|
$result = $this->oauth->issueAccessToken();
|
||||||
|
|
||||||
$this->assertCount(3, $result);
|
$this->assertCount(5, $result);
|
||||||
$this->assertArrayHasKey('access_token', $result);
|
$this->assertArrayHasKey('access_token', $result);
|
||||||
$this->assertArrayHasKey('token_type', $result);
|
$this->assertArrayHasKey('token_type', $result);
|
||||||
$this->assertArrayHasKey('expires_in', $result);
|
$this->assertArrayHasKey('expires_in', $result);
|
||||||
|
$this->assertArrayHasKey('expires', $result);
|
||||||
|
$this->assertArrayHasKey('refresh_token', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_issueAccessToken_PassedParams()
|
public function test_issueAccessToken_PassedParams()
|
||||||
@ -243,10 +257,12 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$result = $this->oauth->issueAccessToken($params);
|
$result = $this->oauth->issueAccessToken($params);
|
||||||
|
|
||||||
$this->assertCount(3, $result);
|
$this->assertCount(5, $result);
|
||||||
$this->assertArrayHasKey('access_token', $result);
|
$this->assertArrayHasKey('access_token', $result);
|
||||||
$this->assertArrayHasKey('token_type', $result);
|
$this->assertArrayHasKey('token_type', $result);
|
||||||
$this->assertArrayHasKey('expires_in', $result);
|
$this->assertArrayHasKey('expires_in', $result);
|
||||||
|
$this->assertArrayHasKey('expires', $result);
|
||||||
|
$this->assertArrayHasKey('refresh_token', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user