diff --git a/tests/authorization/AuthServerTest.php b/tests/authorization/AuthServerTest.php index 5b3d3a08..0158b887 100644 --- a/tests/authorization/AuthServerTest.php +++ b/tests/authorization/AuthServerTest.php @@ -706,6 +706,41 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $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() { M::close(); }