aboutsummaryrefslogtreecommitdiffstats
path: root/library/oauth2/test/OAuth2/RequestTest.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-12-23 10:09:46 +0100
committerMario Vavti <mario@mariovavti.com>2016-12-23 10:09:46 +0100
commit3b9b03cf86979b28e7fa249133176bed84b0105c (patch)
tree336dc8b8b9627e7f4a93e5c35fe3e98555274616 /library/oauth2/test/OAuth2/RequestTest.php
parent2e5a993f880d619aedf3693927e7b3e164fbfcc0 (diff)
parentef39c1e94b5149a3019d417d08dc7c16c8aef9c1 (diff)
downloadvolse-hubzilla-3b9b03cf86979b28e7fa249133176bed84b0105c.tar.gz
volse-hubzilla-3b9b03cf86979b28e7fa249133176bed84b0105c.tar.bz2
volse-hubzilla-3b9b03cf86979b28e7fa249133176bed84b0105c.zip
Merge branch '2.0RC'
Diffstat (limited to 'library/oauth2/test/OAuth2/RequestTest.php')
-rw-r--r--library/oauth2/test/OAuth2/RequestTest.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/library/oauth2/test/OAuth2/RequestTest.php b/library/oauth2/test/OAuth2/RequestTest.php
new file mode 100644
index 000000000..10db3215c
--- /dev/null
+++ b/library/oauth2/test/OAuth2/RequestTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace OAuth2;
+
+use OAuth2\Request\TestRequest;
+use OAuth2\Storage\Bootstrap;
+use OAuth2\GrantType\AuthorizationCode;
+
+class RequestTest extends \PHPUnit_Framework_TestCase
+{
+ public function testRequestOverride()
+ {
+ $request = new TestRequest();
+ $server = $this->getTestServer();
+
+ // Smoke test for override request class
+ // $server->handleTokenRequest($request, $response = new Response());
+ // $this->assertInstanceOf('Response', $response);
+ // $server->handleAuthorizeRequest($request, $response = new Response(), true);
+ // $this->assertInstanceOf('Response', $response);
+ // $response = $server->verifyResourceRequest($request, $response = new Response());
+ // $this->assertTrue(is_bool($response));
+
+ /*** make some valid requests ***/
+
+ // Valid Token Request
+ $request->setPost(array(
+ 'grant_type' => 'authorization_code',
+ 'client_id' => 'Test Client ID',
+ 'client_secret' => 'TestSecret',
+ 'code' => 'testcode',
+ ));
+ $server->handleTokenRequest($request, $response = new Response());
+ $this->assertEquals($response->getStatusCode(), 200);
+ $this->assertNull($response->getParameter('error'));
+ $this->assertNotNUll($response->getParameter('access_token'));
+ }
+
+ public function testHeadersReturnsValueByKey()
+ {
+ $request = new Request(
+ array(),
+ array(),
+ array(),
+ array(),
+ array(),
+ array(),
+ array(),
+ array('AUTHORIZATION' => 'Basic secret')
+ );
+
+ $this->assertEquals('Basic secret', $request->headers('AUTHORIZATION'));
+ }
+
+ public function testHeadersReturnsDefaultIfHeaderNotPresent()
+ {
+ $request = new Request();
+
+ $this->assertEquals('Bearer', $request->headers('AUTHORIZATION', 'Bearer'));
+ }
+
+ public function testHeadersIsCaseInsensitive()
+ {
+ $request = new Request(
+ array(),
+ array(),
+ array(),
+ array(),
+ array(),
+ array(),
+ array(),
+ array('AUTHORIZATION' => 'Basic secret')
+ );
+
+ $this->assertEquals('Basic secret', $request->headers('Authorization'));
+ }
+
+ public function testRequestReturnsPostParamIfNoQueryParamAvailable()
+ {
+ $request = new Request(
+ array(),
+ array('client_id' => 'correct')
+ );
+
+ $this->assertEquals('correct', $request->query('client_id', $request->request('client_id')));
+ }
+
+ private function getTestServer($config = array())
+ {
+ $storage = Bootstrap::getInstance()->getMemoryStorage();
+ $server = new Server($storage, $config);
+
+ // Add the two types supported for authorization grant
+ $server->addGrantType(new AuthorizationCode($storage));
+
+ return $server;
+ }
+}