Added test_issueAccessToken_HTTP_auth(). Fixes #22

This commit is contained in:
Alex Bilbie 2013-03-22 11:08:52 +00:00
parent 0bf2a5333a
commit fe6ecb1dcf

View File

@ -706,6 +706,41 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']);
} }
public function test_issueAccessToken_HTTP_auth()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('updateSession')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode($a));
$_POST['grant_type'] = 'authorization_code';
$_SERVER['PHP_AUTH_USER'] = 1234;
$_SERVER['PHP_AUTH_PW'] = 5678;
$_POST['redirect_uri'] = 'http://foo/redirect';
$_POST['code'] = 'foobar';
$request = new OAuth2\Util\Request(array(), $_POST, array(), array(), $_SERVER);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a->getExpiresIn(), $v['expires']);
}
public function tearDown() { public function tearDown() {
M::close(); M::close();
} }