1
0
Fork 0

Merge pull request #10987 from annando/api4

API: moved classes / unified user array creation
This commit is contained in:
Hypolite Petovan 2021-11-19 06:13:52 -05:00 committed by GitHub
commit 0b6e0566d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 433 additions and 925 deletions

File diff suppressed because it is too large Load diff

View file

@ -32,6 +32,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Photo;
use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Object\Image;
use Friendica\Util\Images;
use Friendica\Util\Strings;
@ -55,8 +56,7 @@ function wall_upload_post(App $a, $desktopmode = true)
return;
}
} else {
$user_info = api_get_user();
$user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $user_info['screen_name'], 'blocked' => false]);
$user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['uid' => BaseApi::getCurrentUserID(), 'blocked' => false]);
}
} else {
if ($r_json) {

View file

@ -52,4 +52,9 @@ class User extends BaseFactory
return new \Friendica\Object\Api\Twitter\User($publicContact, $apcontact, $userContact, $skip_status, $include_user_entities);
}
public function createFromUserId(int $uid, $skip_status = false, $include_user_entities = true)
{
return $this->createFromContactId(Contact::getPublicIdByUserId($uid), $uid, $skip_status, $include_user_entities);
}
}

View file

@ -24,7 +24,6 @@ namespace Friendica\Module\Api\Friendica\Profile;
use Friendica\Profile\ProfileField\Collection\ProfileFields;
use Friendica\Content\Text\BBCode;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
@ -55,13 +54,10 @@ class Show extends BaseApi
$profiles[] = $profile;
}
// return settings, authenticated user and profiles data
$self = Contact::selectFirst(['nurl'], ['uid' => $uid, 'self' => true]);
$result = [
'multi_profiles' => false,
'global_dir' => $directory,
'friendica_owner' => self::getUser($self['nurl']),
'friendica_owner' => DI::twitterUser()->createFromUserId($uid),
'profiles' => $profiles
];

View file

@ -48,7 +48,7 @@ class RateLimitStatus extends BaseApi
'reset_time_in_seconds' => strtotime('now + 1 hour'),
'remaining_hits' => '150',
'hourly_limit' => '150',
'reset_time' => api_date(DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM)),
'reset_time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::API),
];
}

View file

@ -19,10 +19,11 @@
*
*/
namespace Friendica\Module\Api\Twitter;
namespace Friendica\Module\Api\Twitter\Followers;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Module\Api\Twitter\ContactEndpoint;
/**
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids
@ -47,6 +48,8 @@ class FollowersIds extends ContactEndpoint
'default' => 1,
]]);
// @todo Use Model\Contact\Relation::listFollowers($cid, $condition, $count);
System::jsonExit(self::ids(
[Contact::FOLLOWER, Contact::FRIEND],
self::getUid($contact_id, $screen_name),

View file

@ -19,10 +19,11 @@
*
*/
namespace Friendica\Module\Api\Twitter;
namespace Friendica\Module\Api\Twitter\Followers;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Module\Api\Twitter\ContactEndpoint;
/**
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-list
@ -49,6 +50,7 @@ class FollowersList extends ContactEndpoint
'default' => 1,
]]);
// @todo Use Model\Contact\Relation::listFollowers($cid, $condition, $count);
System::jsonExit(self::list(
[Contact::FOLLOWER, Contact::FRIEND],

View file

@ -19,15 +19,16 @@
*
*/
namespace Friendica\Module\Api\Twitter;
namespace Friendica\Module\Api\Twitter\Friends;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Module\Api\Twitter\ContactEndpoint;
/**
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids
*/
class FriendsIds extends ContactEndpoint
class Ids extends ContactEndpoint
{
public function rawContent()
{
@ -47,6 +48,8 @@ class FriendsIds extends ContactEndpoint
'default' => 1,
]]);
// @todo Use Model\Contact\Relation::listFollows($cid, $condition, $count);
System::jsonExit(self::ids(
[Contact::SHARING, Contact::FRIEND],
self::getUid($contact_id, $screen_name),

View file

@ -19,15 +19,16 @@
*
*/
namespace Friendica\Module\Api\Twitter;
namespace Friendica\Module\Api\Twitter\Friends;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Module\Api\Twitter\ContactEndpoint;
/**
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-list
*/
class FriendsList extends ContactEndpoint
class Lists extends ContactEndpoint
{
public function rawContent()
{
@ -49,6 +50,8 @@ class FriendsList extends ContactEndpoint
'default' => 1,
]]);
// @todo Use Model\Contact\Relation::listFollows($cid, $condition, $count);
System::jsonExit(self::list(
[Contact::SHARING, Contact::FRIEND],
self::getUid($contact_id, $screen_name),

View file

@ -25,16 +25,13 @@ use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Security\BasicAuth;
use Friendica\Security\OAuth;
use Friendica\Util\Arrays;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPInputData;
use Friendica\Util\XML;
require_once __DIR__ . '/../../include/api.php';
class BaseApi extends BaseModule
{
@ -295,18 +292,14 @@ class BaseApi extends BaseModule
}
}
/**
* Get user info array.
*
* @param int|string $contact_id Contact ID or URL
* @return array|bool
* @throws HTTPException\BadRequestException
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\UnauthorizedException
* @throws \ImagickException
*/
protected static function getUser($contact_id = null)
public static function getContactIDForSearchterm($searchterm)
{
return api_get_user($contact_id);
if (intval($searchterm) == 0) {
$cid = Contact::getIdForURL($searchterm, 0, false);
} else {
$cid = intval($searchterm);
}
return $cid;
}
}

View file

@ -24,6 +24,10 @@ namespace Friendica\Object\Api\Twitter;
use Friendica\BaseDataTransferObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol;
use Friendica\Model\Contact;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy;
/**
* @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
@ -79,6 +83,14 @@ class User extends BaseDataTransferObject
/** @var string */
protected $withheld_scope;
/**
* Missing fields:
*
* - profile_sidebar_fill_color
* - profile_link_color
* - profile_background_color
*/
/**
* @param array $publicContact Full contact table record with uid = 0
* @param array $apcontact Optional full apcontact table record
@ -89,9 +101,11 @@ class User extends BaseDataTransferObject
*/
public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
{
$uid = $userContact['uid'] ?? 0;
$this->id = (int)$publicContact['id'];
$this->id_str = (string) $publicContact['id'];
$this->name = $publicContact['name'];
$this->name = $publicContact['name'] ?: $publicContact['nick'];
$this->screen_name = $publicContact['nick'] ?: $publicContact['name'];
$this->location = $publicContact['location'] ?:
ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
@ -106,16 +120,16 @@ class User extends BaseDataTransferObject
unset($this->entities);
}
$this->description = BBCode::toPlaintext($publicContact['about']);
$this->profile_image_url_https = $userContact['avatar'] ?? $publicContact['avatar'];
$this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
$this->protected = false;
$this->followers_count = $apcontact['followers_count'] ?? 0;
$this->friends_count = $apcontact['following_count'] ?? 0;
$this->listed_count = 0;
$this->created_at = api_date($publicContact['created']);
$this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::API);
$this->favourites_count = 0;
$this->verified = false;
$this->verified = $uid != 0;
$this->statuses_count = $apcontact['statuses_count'] ?? 0;
$this->profile_banner_url = '';
$this->profile_banner_url = Contact::getHeaderUrlForId($publicContact['id'], '', $publicContact['updated']);
$this->default_profile = false;
$this->default_profile_image = false;
@ -127,9 +141,9 @@ class User extends BaseDataTransferObject
unset($this->withheld_scope);
// Deprecated
$this->profile_image_url = $userContact['avatar'] ?? $publicContact['avatar'];
$this->profile_image_url_profile_size = $publicContact['thumb'];
$this->profile_image_url_large = $publicContact['photo'];
$this->profile_image_url = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
$this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
$this->profile_image_url_large = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
$this->utc_offset = 0;
$this->time_zone = 'UTC';
$this->geo_enabled = false;
@ -137,17 +151,17 @@ class User extends BaseDataTransferObject
$this->contributors_enabled = false;
$this->is_translator = false;
$this->is_translation_enabled = false;
$this->following = false;
$this->following = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
$this->follow_request_sent = false;
$this->statusnet_blocking = false;
$this->notifications = false;
// Friendica-specific
$this->uid = (int)$userContact['uid'] ?? 0;
$this->cid = (int)$userContact['id'] ?? 0;
$this->uid = (int)$uid;
$this->cid = (int)($userContact['id'] ?? 0);
$this->pid = (int)$publicContact['id'];
$this->self = (boolean)$userContact['self'] ?? false;
$this->network = $publicContact['network'];
$this->self = (boolean)($userContact['self'] ?? false);
$this->network = $publicContact['network'] ?: Protocol::DFRN;
$this->statusnet_profile_url = $publicContact['url'];
}
}

View file

@ -62,6 +62,11 @@ class BasicAuth
return (int)self::$current_user_id;
}
public static function setCurrentUserID(int $uid = null)
{
self::$current_user_id = $uid;
}
/**
* Fetch a dummy application token
*
@ -118,7 +123,6 @@ class BasicAuth
private static function getUserIdByAuth(bool $do_login = true):int
{
$a = DI::app();
Session::set('allow_api', false);
self::$current_user_id = 0;
// workaround for HTTP-auth in CGI mode
@ -173,7 +177,10 @@ class BasicAuth
return 0;
}
Logger::debug('Access denied', ['parameters' => $_SERVER]);
// Checking for commandline for the tests, we have to avoid to send a header
if (php_sapi_name() !== 'cli') {
header('WWW-Authenticate: Basic realm="Friendica"');
}
throw new UnauthorizedException("This API requires login");
}
@ -182,15 +189,10 @@ class BasicAuth
DI::auth()->setForUser($a, $record, false, false, $login_refresh);
Session::set('allow_api', true);
Hook::callAll('logged_in', $record);
if (Session::get('allow_api')) {
self::$current_user_id = local_user();
} else {
self::$current_user_id = 0;
}
return self::$current_user_id;
}
}

View file

@ -35,6 +35,7 @@ class DateTimeFormat
const MYSQL = 'Y-m-d H:i:s';
const HTTP = 'D, d M Y H:i:s \G\M\T';
const JSON = 'Y-m-d\TH:i:s.v\Z';
const API = 'D M d H:i:s +0000 Y';
static $localTimezone = 'UTC';

View file

@ -63,10 +63,10 @@ $apiRoutes = [
'/favorites/create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/favorites/destroy[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::DELETE, R::POST]],
'/favorites[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
'/followers/ids[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\FollowersIds::class, [R::GET ]],
'/followers/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\FollowersList::class, [R::GET ]],
'/friends/ids[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\FriendsIds::class, [R::GET ]],
'/friends/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\FriendsList::class, [R::GET ]],
'/followers/ids[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Followers\Ids::class, [R::GET ]],
'/followers/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Followers\Lists::class, [R::GET ]],
'/friends/ids[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Friends\Ids::class, [R::GET ]],
'/friends/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Friends\Lists::class, [R::GET ]],
'/friendships/destroy[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]],
'/friendships/incoming[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]],
@ -474,6 +474,7 @@ return [
'/photo' => [
'/{name}' => [Module\Photo::class, [R::GET]],
'/{type}/{id:\d+}' => [Module\Photo::class, [R::GET]],
'/{type:contact|header}/{guid}' => [Module\Photo::class, [R::GET]],
// User Id Fallback, to remove after version 2021.12
'/{type}/{uid_ext:\d+\..*}' => [Module\Photo::class, [R::GET]],
'/{type}/{nickname_ext}' => [Module\Photo::class, [R::GET]],

View file

@ -110,10 +110,10 @@ class ApiTest extends FixtureTest
// Most API require login so we force the session
$_SESSION = [
'allow_api' => true,
'authenticated' => true,
'uid' => $this->selfUser['id']
];
BasicAuth::setCurrentUserID($this->selfUser['id']);
}
/**
@ -223,7 +223,7 @@ class ApiTest extends FixtureTest
*/
public function testApiUser()
{
self::assertEquals($this->selfUser['id'], api_user());
self::assertEquals($this->selfUser['id'], BaseApi::getCurrentUserID());
}
/**
@ -233,8 +233,7 @@ class ApiTest extends FixtureTest
*/
public function testApiUserWithUnallowedUser()
{
$_SESSION = ['allow_api' => false];
self::assertEquals(false, api_user());
// self::assertEquals(false, api_user());
}
/**
@ -276,7 +275,7 @@ class ApiTest extends FixtureTest
*/
public function testApiDate()
{
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10'));
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
}
/**
@ -310,6 +309,7 @@ class ApiTest extends FixtureTest
*/
public function testApiLoginWithoutLogin()
{
BasicAuth::setCurrentUserID();
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::getCurrentUserID(true);
}
@ -323,6 +323,7 @@ class ApiTest extends FixtureTest
*/
public function testApiLoginWithBadLogin()
{
BasicAuth::setCurrentUserID();
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
$_SERVER['PHP_AUTH_USER'] = 'user@server';
BasicAuth::getCurrentUserID(true);
@ -357,6 +358,7 @@ class ApiTest extends FixtureTest
*/
public function testApiLoginWithCorrectLogin()
{
BasicAuth::setCurrentUserID();
$_SERVER['PHP_AUTH_USER'] = 'Test user';
$_SERVER['PHP_AUTH_PW'] = 'password';
BasicAuth::getCurrentUserID(true);
@ -370,42 +372,12 @@ class ApiTest extends FixtureTest
*/
public function testApiLoginWithRemoteUser()
{
BasicAuth::setCurrentUserID();
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
$_SERVER['REDIRECT_REMOTE_USER'] = '123456dXNlcjpwYXNzd29yZA==';
BasicAuth::getCurrentUserID(true);
}
/**
* Test the api_check_method() function.
*
* @return void
*/
public function testApiCheckMethod()
{
self::assertFalse(api_check_method('method'));
}
/**
* Test the api_check_method() function with a correct method.
*
* @return void
*/
public function testApiCheckMethodWithCorrectMethod()
{
$_SERVER['REQUEST_METHOD'] = 'method';
self::assertTrue(api_check_method('method'));
}
/**
* Test the api_check_method() function with a wildcard.
*
* @return void
*/
public function testApiCheckMethodWithWildcard()
{
self::assertTrue(api_check_method('*'));
}
/**
* Test the api_call() function.
*
@ -584,7 +556,7 @@ class ApiTest extends FixtureTest
public function testApiRssExtra()
{
$user_info = ['url' => 'user_url', 'lang' => 'en'];
$result = api_rss_extra($this->app, [], $user_info);
$result = api_rss_extra([], $user_info);
self::assertEquals($user_info, $result['$user']);
self::assertEquals($user_info['url'], $result['$rss']['alternate']);
self::assertArrayHasKey('self', $result['$rss']);
@ -602,7 +574,7 @@ class ApiTest extends FixtureTest
*/
public function testApiRssExtraWithoutUserInfo()
{
$result = api_rss_extra($this->app, [], null);
$result = api_rss_extra([], null);
self::assertIsArray($result['$user']);
self::assertArrayHasKey('alternate', $result['$rss']);
self::assertArrayHasKey('self', $result['$rss']);
@ -640,11 +612,11 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUser()
{
$user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
self::assertEquals('ededed', $user['profile_background_color']);
// $user = api_get_user();
// self::assertSelfUser($user);
// self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
// self::assertEquals('6fdbe8', $user['profile_link_color']);
// self::assertEquals('ededed', $user['profile_background_color']);
}
/**
@ -654,13 +626,13 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithFrioSchema()
{
$pConfig = $this->dice->create(IManagePersonalConfigValues::class);
$pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
$user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
self::assertEquals('ededed', $user['profile_background_color']);
// $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
// $pConfig->set($this->selfUser['id'], 'frio', 'schema', 'red');
// $user = api_get_user();
// self::assertSelfUser($user);
// self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
// self::assertEquals('6fdbe8', $user['profile_link_color']);
// self::assertEquals('ededed', $user['profile_background_color']);
}
/**
@ -670,13 +642,13 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithEmptyFrioSchema()
{
$pConfig = $this->dice->create(IManagePersonalConfigValues::class);
$pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
$user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
self::assertEquals('6fdbe8', $user['profile_link_color']);
self::assertEquals('ededed', $user['profile_background_color']);
// $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
// $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
// $user = api_get_user();
// self::assertSelfUser($user);
// self::assertEquals('708fa0', $user['profile_sidebar_fill_color']);
// self::assertEquals('6fdbe8', $user['profile_link_color']);
// self::assertEquals('ededed', $user['profile_background_color']);
}
/**
@ -686,16 +658,16 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithCustomFrioSchema()
{
$pConfig = $this->dice->create(IManagePersonalConfigValues::class);
$pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
$pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
$pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
$pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
$user = api_get_user();
self::assertSelfUser($user);
self::assertEquals('123456', $user['profile_sidebar_fill_color']);
self::assertEquals('123456', $user['profile_link_color']);
self::assertEquals('123456', $user['profile_background_color']);
// $pConfig = $this->dice->create(IManagePersonalConfigValues::class);
// $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
// $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
// $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
// $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
// $user = api_get_user();
// self::assertSelfUser($user);
// self::assertEquals('123456', $user['profile_sidebar_fill_color']);
// self::assertEquals('123456', $user['profile_link_color']);
// self::assertEquals('123456', $user['profile_background_color']);
}
/**
@ -706,10 +678,13 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithoutApiUser()
{
// api_get_user() with empty parameters is not used anymore
/*
$_SERVER['PHP_AUTH_USER'] = 'Test user';
$_SERVER['PHP_AUTH_PW'] = 'password';
$_SESSION['allow_api'] = false;
BasicAuth::setCurrentUserID();
self::assertFalse(api_get_user());
*/
}
/**
@ -719,8 +694,7 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithGetId()
{
$_GET['user_id'] = $this->otherUser['id'];
self::assertOtherUser(api_get_user());
// self::assertOtherUser(api_get_user());
}
/**
@ -730,9 +704,8 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithWrongGetId()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
$_GET['user_id'] = $this->wrongUserId;
self::assertOtherUser(api_get_user());
// $this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
// self::assertOtherUser(api_get_user());
}
/**
@ -742,8 +715,7 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithGetName()
{
$_GET['screen_name'] = $this->selfUser['nick'];
self::assertSelfUser(api_get_user());
// self::assertSelfUser(api_get_user());
}
/**
@ -753,8 +725,7 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithGetUrl()
{
$_GET['profileurl'] = $this->selfUser['nurl'];
self::assertSelfUser(api_get_user());
// self::assertSelfUser(api_get_user());
}
/**
@ -764,10 +735,10 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithNumericCalledApi()
{
global $called_api;
$called_api = ['api_path'];
DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
self::assertOtherUser(api_get_user());
// global $called_api;
// $called_api = ['api_path'];
// DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
// self::assertOtherUser(api_get_user());
}
/**
@ -777,30 +748,9 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithCalledApi()
{
global $called_api;
$called_api = ['api', 'api_path'];
self::assertSelfUser(api_get_user());
}
/**
* Test the api_get_user() function with a valid user.
*
* @return void
*/
public function testApiGetUserWithCorrectUser()
{
self::assertOtherUser(api_get_user($this->otherUser['id']));
}
/**
* Test the api_get_user() function with a wrong user ID.
*
* @return void
*/
public function testApiGetUserWithWrongUser()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
self::assertOtherUser(api_get_user($this->wrongUserId));
// global $called_api;
// $called_api = ['api', 'api_path'];
// self::assertSelfUser(api_get_user());
}
/**
@ -810,7 +760,7 @@ class ApiTest extends FixtureTest
*/
public function testApiGetUserWithZeroUser()
{
self::assertSelfUser(api_get_user(0));
self::assertSelfUser(DI::twitterUser()->createFromUserId(BaseApi::getCurrentUserID())->toArray());
}
/**
@ -995,7 +945,8 @@ class ApiTest extends FixtureTest
*/
public function testApiAccountVerifyCredentialsWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_account_verify_credentials('json');
}
@ -1065,7 +1016,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesMediapWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_mediap('json');
}
@ -1117,7 +1069,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesUpdateWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_update('json');
}
@ -1170,7 +1123,8 @@ class ApiTest extends FixtureTest
*/
public function testApiMediaUploadWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_media_upload();
}
@ -1418,9 +1372,8 @@ class ApiTest extends FixtureTest
*/
public function testApiSearchWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_search('json');
}
@ -1474,9 +1427,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesHomeTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_statuses_home_timeline('json');
}
@ -1545,9 +1497,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesPublicTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_statuses_public_timeline('json');
}
@ -1599,9 +1550,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesNetworkpublicTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_statuses_networkpublic_timeline('json');
}
@ -1662,9 +1612,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesShowWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_statuses_show('json');
}
@ -1703,9 +1652,8 @@ class ApiTest extends FixtureTest
*/
public function testApiConversationShowWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_conversation_show('json');
}
@ -1727,7 +1675,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesRepeatWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_repeat('json');
}
@ -1767,7 +1716,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesDestroyWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_destroy('json');
}
@ -1817,9 +1767,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesMentionsWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_statuses_mentions('json');
}
@ -1884,9 +1833,8 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesUserTimelineWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_statuses_user_timeline('json');
}
@ -1973,8 +1921,9 @@ class ApiTest extends FixtureTest
*/
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_favorites_create_destroy('json');
}
@ -2012,9 +1961,8 @@ class ApiTest extends FixtureTest
*/
public function testApiFavoritesWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_favorites('json');
}
@ -2387,7 +2335,8 @@ class ApiTest extends FixtureTest
*/
public function testApiListsOwnershipsWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_lists_ownerships('json');
}
@ -2437,9 +2386,8 @@ class ApiTest extends FixtureTest
*/
public function testApiListsStatusesWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_lists_statuses('json');
}
@ -2627,7 +2575,8 @@ class ApiTest extends FixtureTest
*/
public function testApiDirectMessagesNewWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_direct_messages_new('json');
}
@ -2731,7 +2680,8 @@ class ApiTest extends FixtureTest
*/
public function testApiDirectMessagesDestroyWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_direct_messages_destroy('json');
}
@ -2863,9 +2813,8 @@ class ApiTest extends FixtureTest
*/
public function testApiDirectMessagesBoxWithUnallowedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$_SESSION['allow_api'] = false;
$_GET['screen_name'] = $this->selfUser['nick'];
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
api_direct_messages_box('json', 'sentbox', 'false');
}
@ -2951,7 +2900,8 @@ class ApiTest extends FixtureTest
*/
public function testApiFrPhotosListWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_fr_photos_list('json');
}
@ -2972,7 +2922,8 @@ class ApiTest extends FixtureTest
*/
public function testApiFrPhotoCreateUpdateWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_fr_photo_create_update('json');
}
@ -3027,7 +2978,8 @@ class ApiTest extends FixtureTest
*/
public function testApiFrPhotoDetailWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_fr_photo_detail('json');
}
@ -3072,7 +3024,8 @@ class ApiTest extends FixtureTest
*/
public function testApiAccountUpdateProfileImageWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_account_update_profile_image('json');
}

View file

@ -46,8 +46,8 @@ class FriendSuggestTest extends MockedTest
'',
'',
'',
new \DateTime('now', new \DateTimeZone('URC')),
28
new \DateTime('now', new \DateTimeZone('UTC')),
20
),
],
'full' => [

View file

@ -226,20 +226,20 @@ class ContactEndpointTest extends FixtureTest
],
'description' => '',
'protected' => false,
'verified' => false,
'verified' => true,
'followers_count' => 0,
'friends_count' => 0,
'listed_count' => 0,
'favourites_count' => 0,
'statuses_count' => 0,
'created_at' => 'Fri Feb 02 00:00:00 +0000 0000',
'profile_banner_url' => '',
'profile_image_url_https' => '',
'profile_banner_url' => 'http://localhost/photo/header/44?ts=-62135596800',
'profile_image_url_https' => 'http://localhost/photo/contact/48/44?ts=-62135596800',
'default_profile' => false,
'default_profile_image' => false,
'profile_image_url' => '',
'profile_image_url_profile_size' => '',
'profile_image_url_large' => '',
'profile_image_url' => 'http://localhost/photo/contact/48/44?ts=-62135596800',
'profile_image_url_profile_size' => 'http://localhost/photo/contact/80/44?ts=-62135596800',
'profile_image_url_large' => 'http://localhost/photo/contact/1024/44?ts=-62135596800',
'utc_offset' => 0,
'time_zone' => 'UTC',
'geo_enabled' => false,