[Pkg-owncloud-commits] [php-sabredav] 59/64: Missing unittests.
David Prévot
taffit at moszumanska.debian.org
Thu Dec 11 15:13:27 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to tag 2.2.0alpha1
in repository php-sabredav.
commit ae65aef9e8dd5fdadd74f5719b82bbb779ec5f10
Author: Evert Pot <me at evertpot.com>
Date: Sat Dec 6 23:13:19 2014 -0500
Missing unittests.
---
tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php | 18 +++++++-
.../Sabre/DAV/Auth/Backend/AbstractDigestTest.php | 16 +++++++
tests/Sabre/DAV/Auth/Backend/ApacheTest.php | 14 ++++++
tests/Sabre/DAV/Auth/Backend/Mock.php | 5 +++
tests/Sabre/DAV/Auth/PluginTest.php | 51 ++++++++++++++++++++++
5 files changed, 103 insertions(+), 1 deletion(-)
diff --git a/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php b/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php
index 8c7dbd4..23461b3 100644
--- a/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php
+++ b/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php
@@ -38,7 +38,7 @@ class AbstractBasicTest extends \PHPUnit_Framework_TestCase {
}
- function testAuthenticate() {
+ function testCheckSuccess() {
$request = HTTP\Sapi::createFromServerArray(array(
'PHP_AUTH_USER' => 'username',
@@ -54,6 +54,22 @@ class AbstractBasicTest extends \PHPUnit_Framework_TestCase {
}
+ function testRequireAuth() {
+
+ $request = new HTTP\Request();
+ $response = new HTTP\Response();
+
+ $backend = new AbstractBasicMock();
+ $backend->setRealm('writing unittests on a saturday night');
+ $backend->requireAuth($request, $response);
+
+ $this->assertEquals(
+ 'Basic realm="writing unittests on a saturday night"',
+ $response->getHeader('WWW-Authenticate')
+ );
+
+ }
+
}
diff --git a/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php b/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php
index 3a98b2b..790a9b5 100644
--- a/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php
+++ b/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php
@@ -109,6 +109,22 @@ class AbstractDigestTest extends \PHPUnit_Framework_TestCase {
}
+ function testRequireAuth() {
+
+ $request = new HTTP\Request();
+ $response = new HTTP\Response();
+
+ $backend = new AbstractDigestMock();
+ $backend->setRealm('writing unittests on a saturday night');
+ $backend->requireAuth($request, $response);
+
+ $this->assertStringStartsWith(
+ 'Digest realm="writing unittests on a saturday night"',
+ $response->getHeader('WWW-Authenticate')
+ );
+
+ }
+
}
diff --git a/tests/Sabre/DAV/Auth/Backend/ApacheTest.php b/tests/Sabre/DAV/Auth/Backend/ApacheTest.php
index 20be0ed..234cc94 100644
--- a/tests/Sabre/DAV/Auth/Backend/ApacheTest.php
+++ b/tests/Sabre/DAV/Auth/Backend/ApacheTest.php
@@ -55,4 +55,18 @@ class ApacheTest extends \PHPUnit_Framework_TestCase {
);
}
+
+ function testRequireAuth() {
+
+ $request = new HTTP\Request();
+ $response = new HTTP\Response();
+
+ $backend = new Apache();
+ $backend->requireAuth($request, $response);
+
+ $this->assertNull(
+ $response->getHeader('WWW-Authenticate')
+ );
+
+ }
}
diff --git a/tests/Sabre/DAV/Auth/Backend/Mock.php b/tests/Sabre/DAV/Auth/Backend/Mock.php
index 127aac4..9eaff69 100644
--- a/tests/Sabre/DAV/Auth/Backend/Mock.php
+++ b/tests/Sabre/DAV/Auth/Backend/Mock.php
@@ -11,6 +11,8 @@ class Mock implements BackendInterface {
public $fail = false;
+ public $invalidCheckResponse = false;
+
public $principal;
public $defaultPrincipal = 'principals/admin';
@@ -50,6 +52,9 @@ class Mock implements BackendInterface {
*/
function check(RequestInterface $request, ResponseInterface $response) {
+ if ($this->invalidCheckResponse) {
+ return 'incorrect!';
+ }
if ($this->fail) {
return [false, "fail!"];
}
diff --git a/tests/Sabre/DAV/Auth/PluginTest.php b/tests/Sabre/DAV/Auth/PluginTest.php
index 3bc59d8..b45b552 100644
--- a/tests/Sabre/DAV/Auth/PluginTest.php
+++ b/tests/Sabre/DAV/Auth/PluginTest.php
@@ -16,6 +16,7 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($plugin instanceof Plugin);
$fakeServer->addPlugin($plugin);
$this->assertEquals($plugin, $fakeServer->getPlugin('auth'));
+ $this->assertInternalType('array', $plugin->getPluginInfo());
}
@@ -52,6 +53,56 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testAuthenticate
*/
+ function testMultipleBackend() {
+
+ $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
+ $backend1 = new Backend\Mock();
+ $backend2 = new Backend\Mock();
+ $backend2->fail = true;
+
+ $plugin = new Plugin();
+ $plugin->addBackend($backend1);
+ $plugin->addBackend($backend2);
+
+ $fakeServer->addPlugin($plugin);
+ $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
+
+ $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal());
+
+ }
+
+ /**
+ * @depends testInit
+ * @expectedException Sabre\DAV\Exception
+ */
+ function testNoAuthBackend() {
+
+ $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
+
+ $plugin = new Plugin();
+ $fakeServer->addPlugin($plugin);
+ $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
+
+ }
+ /**
+ * @depends testInit
+ * @expectedException Sabre\DAV\Exception
+ */
+ function testInvalidCheckResponse() {
+
+ $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
+ $backend = new Backend\Mock();
+ $backend->invalidCheckResponse = true;
+
+ $plugin = new Plugin($backend);
+ $fakeServer->addPlugin($plugin);
+ $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]);
+
+ }
+
+ /**
+ * @depends testAuthenticate
+ */
function testGetCurrentPrincipal() {
$fakeServer = new DAV\Server( new DAV\SimpleCollection('bla'));
--
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