[Pkg-owncloud-commits] [php-sabredav] 10/80: add bearer unittest

David Prévot taffit at moszumanska.debian.org
Thu Jan 7 02:56:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 4c5dccaa8fa1cd604ae9593c2703d7a8187ac0de
Author: François Kooman <fkooman at tuxed.net>
Date:   Sat Aug 29 14:51:56 2015 +0200

    add bearer unittest
---
 .../Sabre/DAV/Auth/Backend/AbstractBearerTest.php  | 91 ++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/tests/Sabre/DAV/Auth/Backend/AbstractBearerTest.php b/tests/Sabre/DAV/Auth/Backend/AbstractBearerTest.php
new file mode 100644
index 0000000..bb850b5
--- /dev/null
+++ b/tests/Sabre/DAV/Auth/Backend/AbstractBearerTest.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Sabre\DAV\Auth\Backend;
+
+use Sabre\DAV;
+use Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class AbstractBearerTest extends \PHPUnit_Framework_TestCase {
+
+    function testCheckNoHeaders() {
+
+        $request = new HTTP\Request();
+        $response = new HTTP\Response();
+
+        $backend = new AbstractBearerMock();
+
+        $this->assertFalse(
+            $backend->check($request, $response)[0]
+        );
+
+    }
+
+    function testCheckInvalidToken() {
+
+        $request = HTTP\Sapi::createFromServerArray(array(
+            'HTTP_AUTHORIZATION' => 'Bearer foo',
+        ));
+        $response = new HTTP\Response();
+
+        $backend = new AbstractBearerMock();
+
+        $this->assertFalse(
+            $backend->check($request, $response)[0]
+        );
+
+    }
+
+    function testCheckSuccess() {
+
+        $request = HTTP\Sapi::createFromServerArray(array(
+            'HTTP_AUTHORIZATION' => 'Bearer valid',
+        ));
+        $response = new HTTP\Response();
+
+        $backend = new AbstractBearerMock();
+        $this->assertEquals(
+            [true, 'principals/username'],
+            $backend->check($request, $response)
+        );
+
+    }
+
+    function testRequireAuth() {
+
+        $request = new HTTP\Request();
+        $response = new HTTP\Response();
+
+        $backend = new AbstractBearerMock();
+        $backend->setRealm('writing unittests on a saturday night');
+        $backend->challenge($request, $response);
+
+        $this->assertEquals(
+            'Bearer realm="writing unittests on a saturday night"',
+            $response->getHeader('WWW-Authenticate')
+        );
+
+    }
+
+}
+
+
+class AbstractBearerMock extends AbstractBearer {
+
+    /**
+     * Validates a bearer token
+     *
+     * This method should return true or false depending on if login
+     * succeeded.
+     *
+     * @param string $bearerToken
+     * @return bool
+     */
+    function validateBearerToken($bearerToken) {
+
+        return 'valid' === $bearerToken ? 'username' : false;
+
+    }
+
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list