Move last legacy API tests & adapt phpunit.xml
This commit is contained in:
parent
732663ea6b
commit
fbefb599dc
7 changed files with 173 additions and 304 deletions
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Test\src\Core;
|
||||
|
||||
use Friendica\Core\ACL;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Test\FixtureTest;
|
||||
|
||||
class ACLTest extends FixtureTest
|
||||
|
@ -34,7 +33,7 @@ class ACLTest extends FixtureTest
|
|||
*/
|
||||
public function testCheckAclInput()
|
||||
{
|
||||
$result = ACL::isValidContact('<aclstring>', BaseApi::getCurrentUserID());
|
||||
$result = ACL::isValidContact('<aclstring>', '42');
|
||||
self::assertFalse($result);
|
||||
}
|
||||
|
||||
|
@ -45,7 +44,7 @@ class ACLTest extends FixtureTest
|
|||
*/
|
||||
public function testCheckAclInputWithEmptyAclString()
|
||||
{
|
||||
$result = ACL::isValidContact('', BaseApi::getCurrentUserID());
|
||||
$result = ACL::isValidContact('', '42');
|
||||
self::assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Test\src\Module;
|
||||
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Test\src\Module\Api\ApiTest;
|
||||
|
||||
class BaseApiTest extends ApiTest
|
||||
|
@ -47,4 +48,14 @@ class BaseApiTest extends ApiTest
|
|||
);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_user() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiUser()
|
||||
{
|
||||
self::assertEquals(parent::SELF_USER['id'], BaseApi::getCurrentUserID());
|
||||
}
|
||||
}
|
||||
|
|
112
tests/src/Security/BasicAuthTest.php
Normal file
112
tests/src/Security/BasicAuthTest.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Test\src\Security;
|
||||
|
||||
use Friendica\Security\BasicAuth;
|
||||
use Friendica\Test\src\Module\Api\ApiTest;
|
||||
|
||||
class BasicAuthTest extends ApiTest
|
||||
{
|
||||
/**
|
||||
* Test the api_source() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiSource()
|
||||
{
|
||||
self::assertEquals('api', BasicAuth::getCurrentApplicationToken()['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_source() function with a Twidere user agent.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiSourceWithTwidere()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Twidere';
|
||||
self::assertEquals('Twidere', BasicAuth::getCurrentApplicationToken()['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_source() function with a GET parameter.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiSourceWithGet()
|
||||
{
|
||||
$_REQUEST['source'] = 'source_name';
|
||||
self::assertEquals('source_name', BasicAuth::getCurrentApplicationToken()['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BasicAuth::getCurrentUserID() function without any login.
|
||||
*/
|
||||
public function testApiLoginWithoutLogin()
|
||||
{
|
||||
self::markTestIncomplete('Needs Refactoring of BasicAuth first.');
|
||||
/*
|
||||
BasicAuth::setCurrentUserID();
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
BasicAuth::getCurrentUserID(true);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BasicAuth::getCurrentUserID() function with a bad login.
|
||||
*/
|
||||
public function testApiLoginWithBadLogin()
|
||||
{
|
||||
self::markTestIncomplete('Needs Refactoring of BasicAuth first.');
|
||||
/*
|
||||
BasicAuth::setCurrentUserID();
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
$_SERVER['PHP_AUTH_USER'] = 'user@server';
|
||||
BasicAuth::getCurrentUserID(true);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BasicAuth::getCurrentUserID() function with a correct login.
|
||||
*/
|
||||
public function testApiLoginWithCorrectLogin()
|
||||
{
|
||||
BasicAuth::setCurrentUserID();
|
||||
$_SERVER['PHP_AUTH_USER'] = 'Test user';
|
||||
$_SERVER['PHP_AUTH_PW'] = 'password';
|
||||
self::assertEquals(parent::SELF_USER['id'], BasicAuth::getCurrentUserID(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the BasicAuth::getCurrentUserID() function with a remote user.
|
||||
*/
|
||||
public function testApiLoginWithRemoteUser()
|
||||
{
|
||||
self::markTestIncomplete('Needs Refactoring of BasicAuth first.');
|
||||
/*
|
||||
BasicAuth::setCurrentUserID();
|
||||
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
|
||||
$_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
|
||||
BasicAuth::getCurrentUserID(true);
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -127,4 +127,42 @@ class ArraysTest extends TestCase
|
|||
$str = Arrays::recursiveImplode([[1], [2, [3]]], ',');
|
||||
self::assertSame($str, '{1},{2,{3}}');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Arrays::walkRecursive() function.
|
||||
*/
|
||||
public function testApiWalkRecursive()
|
||||
{
|
||||
$array = ['item1'];
|
||||
self::assertEquals(
|
||||
$array,
|
||||
Arrays::walkRecursive(
|
||||
$array,
|
||||
function () {
|
||||
// Should we test this with a callback that actually does something?
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Arrays::walkRecursive() function with an array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiWalkRecursiveWithArray()
|
||||
{
|
||||
$array = [['item1'], ['item2']];
|
||||
self::assertEquals(
|
||||
$array,
|
||||
Arrays::walkRecursive(
|
||||
$array,
|
||||
function () {
|
||||
// Should we test this with a callback that actually does something?
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,4 +77,14 @@ class DateTimeFormatTest extends MockedTest
|
|||
|
||||
self::assertEquals($assert, $dtFormat->isYearMonth($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api_date() function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testApiDate()
|
||||
{
|
||||
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue