mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-07-09 18:08:49 +00:00
Initial Release of the calendar plugin
This commit is contained in:
parent
45cc9885fc
commit
7115197a33
561 changed files with 189494 additions and 0 deletions
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class Sabre_DAV_Auth_Backend_AbstractBasicTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_NotAuthenticated
|
||||
*/
|
||||
public function testAuthenticateNoHeaders() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractBasicMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_NotAuthenticated
|
||||
*/
|
||||
public function testAuthenticateUnknownUser() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'PHP_AUTH_USER' => 'username',
|
||||
'PHP_AUTH_PW' => 'wrongpassword',
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractBasicMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
public function testAuthenticate() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'PHP_AUTH_USER' => 'username',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractBasicMock();
|
||||
$this->assertTrue($backend->authenticate($server,'myRealm'));
|
||||
|
||||
$result = $backend->getCurrentUser();
|
||||
|
||||
$this->assertEquals('username', $result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Sabre_DAV_Auth_Backend_AbstractBasicMock extends Sabre_DAV_Auth_Backend_AbstractBasic {
|
||||
|
||||
/**
|
||||
* Validates a username and password
|
||||
*
|
||||
* This method should return true or false depending on if login
|
||||
* succeeded.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
function validateUserPass($username, $password) {
|
||||
|
||||
return ($username == 'username' && $password == 'password');
|
||||
|
||||
}
|
||||
|
||||
}
|
150
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php
Normal file
150
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class Sabre_DAV_Auth_Backend_AbstractDigestTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_NotAuthenticated
|
||||
*/
|
||||
public function testAuthenticateNoHeaders() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractDigestMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception
|
||||
*/
|
||||
public function testAuthenticateBadGetUserInfoResponse() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$header = 'username=null, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractDigestMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception
|
||||
*/
|
||||
public function testAuthenticateBadGetUserInfoResponse2() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$header = 'username=array, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractDigestMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_NotAuthenticated
|
||||
*/
|
||||
public function testAuthenticateUnknownUser() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$header = 'username=false, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractDigestMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_NotAuthenticated
|
||||
*/
|
||||
public function testAuthenticateBadPassword() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractDigestMock();
|
||||
$backend->authenticate($server,'myRealm');
|
||||
|
||||
}
|
||||
|
||||
public function testAuthenticate() {
|
||||
|
||||
$response = new Sabre_HTTP_ResponseMock();
|
||||
$tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('bla'));
|
||||
$server = new Sabre_DAV_Server($tree);
|
||||
$server->httpResponse = $response;
|
||||
|
||||
$digestHash = md5('HELLO:12345:1:1:auth:' . md5('GET:/'));
|
||||
$header = 'username=user, realm=myRealm, nonce=12345, uri=/, response='.$digestHash.', opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
'REQUEST_URI' => '/',
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_AbstractDigestMock();
|
||||
$this->assertTrue($backend->authenticate($server,'myRealm'));
|
||||
|
||||
$result = $backend->getCurrentUser();
|
||||
|
||||
$this->assertEquals('user', $result);
|
||||
$this->assertEquals('HELLO', $backend->getDigestHash('myRealm', $result));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class Sabre_DAV_Auth_Backend_AbstractDigestMock extends Sabre_DAV_Auth_Backend_AbstractDigest {
|
||||
|
||||
function getDigestHash($realm, $userName) {
|
||||
|
||||
switch($userName) {
|
||||
case 'null' : return null;
|
||||
case 'false' : return false;
|
||||
case 'array' : return array();
|
||||
case 'user' : return 'HELLO';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
abstract class Sabre_DAV_Auth_Backend_AbstractPDOTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
abstract function getPDO();
|
||||
|
||||
function testConstruct() {
|
||||
|
||||
$pdo = $this->getPDO();
|
||||
$backend = new Sabre_DAV_Auth_Backend_PDO($pdo);
|
||||
$this->assertTrue($backend instanceof Sabre_DAV_Auth_Backend_PDO);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstruct
|
||||
*/
|
||||
function testUserInfo() {
|
||||
|
||||
$pdo = $this->getPDO();
|
||||
$backend = new Sabre_DAV_Auth_Backend_PDO($pdo);
|
||||
|
||||
$this->assertNull($backend->getDigestHash('realm','blabla'));
|
||||
|
||||
$expected = 'hash';
|
||||
|
||||
$this->assertEquals($expected, $backend->getDigestHash('realm','user'));
|
||||
|
||||
}
|
||||
|
||||
}
|
40
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/ApacheTest.php
Normal file
40
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/ApacheTest.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
class Sabre_DAV_Auth_Backend_ApacheTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function testConstruct() {
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_Apache();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception
|
||||
*/
|
||||
function testNoHeader() {
|
||||
|
||||
$server = new Sabre_DAV_Server();
|
||||
$backend = new Sabre_DAV_Auth_Backend_Apache();
|
||||
$backend->authenticate($server,'Realm');
|
||||
|
||||
}
|
||||
|
||||
function testRemoteUser() {
|
||||
|
||||
$backend = new Sabre_DAV_Auth_Backend_Apache();
|
||||
|
||||
$server = new Sabre_DAV_Server();
|
||||
$request = new Sabre_HTTP_Request(array(
|
||||
'REMOTE_USER' => 'username',
|
||||
));
|
||||
$server->httpRequest = $request;
|
||||
|
||||
$this->assertTrue($backend->authenticate($server, 'Realm'));
|
||||
|
||||
$userInfo = 'username';
|
||||
|
||||
$this->assertEquals($userInfo, $backend->getCurrentUser());
|
||||
|
||||
}
|
||||
|
||||
}
|
40
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/FileTest.php
Normal file
40
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/FileTest.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
class Sabre_DAV_Auth_Backend_FileTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
function tearDown() {
|
||||
|
||||
if (file_exists(SABRE_TEMPDIR . '/filebackend')) unlink(SABRE_TEMPDIR .'/filebackend');
|
||||
|
||||
}
|
||||
|
||||
function testConstruct() {
|
||||
|
||||
$file = new Sabre_DAV_Auth_Backend_File();
|
||||
$this->assertTrue($file instanceof Sabre_DAV_Auth_Backend_File);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception
|
||||
*/
|
||||
function testLoadFileBroken() {
|
||||
|
||||
file_put_contents(SABRE_TEMPDIR . '/backend','user:realm:hash');
|
||||
$file = new Sabre_DAV_Auth_Backend_File();
|
||||
$file->loadFile(SABRE_TEMPDIR .'/backend');
|
||||
|
||||
}
|
||||
|
||||
function testLoadFile() {
|
||||
|
||||
file_put_contents(SABRE_TEMPDIR . '/backend','user:realm:' . md5('user:realm:password'));
|
||||
$file = new Sabre_DAV_Auth_Backend_File();
|
||||
$file->loadFile(SABRE_TEMPDIR . '/backend');
|
||||
|
||||
$this->assertFalse($file->getDigestHash('realm','blabla'));
|
||||
$this->assertEquals(md5('user:realm:password'), $file->getDigesthash('realm','user'));
|
||||
|
||||
}
|
||||
|
||||
}
|
24
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest
Normal file
24
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
class Sabre_DAV_Auth_Backend_PDOSQLiteTest extends Sabre_DAV_Auth_Backend_AbstractPDOTest {
|
||||
|
||||
function tearDown() {
|
||||
|
||||
if (file_exists(SABRE_TEMPDIR . '/pdobackend')) unlink(SABRE_TEMPDIR . '/pdobackend');
|
||||
if (file_exists(SABRE_TEMPDIR . '/pdobackend2')) unlink(SABRE_TEMPDIR . '/pdobackend2');
|
||||
|
||||
}
|
||||
|
||||
function getPDO() {
|
||||
|
||||
if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
|
||||
$pdo = new PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend');
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->query('CREATE TABLE users (username TEXT, digesta1 TEXT)');
|
||||
$pdo->query('INSERT INTO users VALUES ("user","hash")');
|
||||
|
||||
return $pdo;
|
||||
|
||||
}
|
||||
|
||||
}
|
29
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php
Normal file
29
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_DAV_Auth_Backend_PDOMySQLTest extends Sabre_DAV_Auth_Backend_AbstractPDOTest {
|
||||
|
||||
function getPDO() {
|
||||
|
||||
if (!SABRE_HASMYSQL) $this->markTestSkipped('MySQL driver is not available, or not properly configured');
|
||||
$pdo = Sabre_TestUtil::getMySQLDB();
|
||||
if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database');
|
||||
$pdo->query("DROP TABLE IF EXISTS users");
|
||||
$pdo->query("
|
||||
create table users (
|
||||
id integer unsigned not null primary key auto_increment,
|
||||
username varchar(50),
|
||||
digesta1 varchar(32),
|
||||
email varchar(80),
|
||||
displayname varchar(80),
|
||||
unique(username)
|
||||
);");
|
||||
|
||||
$pdo->query("INSERT INTO users (username,digesta1,email,displayname) VALUES ('user','hash','user@example.org','User')");
|
||||
|
||||
return $pdo;
|
||||
|
||||
}
|
||||
|
||||
}
|
26
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php
Normal file
26
dav/SabreDAV/tests/Sabre/DAV/Auth/Backend/PDOSqliteTest.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/DAV/Auth/Backend/AbstractPDOTest.php';
|
||||
|
||||
class Sabre_DAV_Auth_Backend_PDOSQLiteTest extends Sabre_DAV_Auth_Backend_AbstractPDOTest {
|
||||
|
||||
function tearDown() {
|
||||
|
||||
if (file_exists(SABRE_TEMPDIR . '/pdobackend')) unlink(SABRE_TEMPDIR . '/pdobackend');
|
||||
if (file_exists(SABRE_TEMPDIR . '/pdobackend2')) unlink(SABRE_TEMPDIR . '/pdobackend2');
|
||||
|
||||
}
|
||||
|
||||
function getPDO() {
|
||||
|
||||
if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
|
||||
$pdo = new PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend');
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->query('CREATE TABLE users (username TEXT, digesta1 TEXT, email VARCHAR(80), displayname VARCHAR(80))');
|
||||
$pdo->query('INSERT INTO users VALUES ("user","hash","user@example.org","User")');
|
||||
|
||||
return $pdo;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue