From 9cc675233d1525f677c8c05d14765172fb7acbfd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 27 Nov 2021 18:30:41 -0500 Subject: [PATCH] Add a second parameter to BaseApi::getRequest to enable API tests --- src/Module/Api/Friendica/Activity.php | 2 +- src/Module/Api/Friendica/DirectMessages/Setseen.php | 2 +- src/Module/Api/Friendica/Events/Index.php | 2 +- src/Module/Api/Friendica/Group/Delete.php | 2 +- src/Module/Api/Friendica/Photo/Delete.php | 2 +- src/Module/Api/Friendica/Photoalbum/Delete.php | 2 +- src/Module/Api/Friendica/Photoalbum/Update.php | 2 +- src/Module/Api/Mastodon/Accounts/Followers.php | 2 +- src/Module/Api/Mastodon/Accounts/Following.php | 2 +- src/Module/Api/Mastodon/Accounts/Note.php | 2 +- src/Module/Api/Mastodon/Accounts/Relationships.php | 2 +- src/Module/Api/Mastodon/Accounts/Search.php | 2 +- src/Module/Api/Mastodon/Accounts/Statuses.php | 2 +- src/Module/Api/Mastodon/Apps.php | 2 +- src/Module/Api/Mastodon/Blocks.php | 2 +- src/Module/Api/Mastodon/Bookmarks.php | 2 +- src/Module/Api/Mastodon/Conversations.php | 2 +- src/Module/Api/Mastodon/Directory.php | 2 +- src/Module/Api/Mastodon/Favourited.php | 2 +- src/Module/Api/Mastodon/FollowRequests.php | 2 +- src/Module/Api/Mastodon/Lists.php | 2 +- src/Module/Api/Mastodon/Lists/Accounts.php | 2 +- src/Module/Api/Mastodon/Mutes.php | 2 +- src/Module/Api/Mastodon/Notifications.php | 2 +- src/Module/Api/Mastodon/PushSubscription.php | 2 +- src/Module/Api/Mastodon/ScheduledStatuses.php | 2 +- src/Module/Api/Mastodon/Search.php | 2 +- src/Module/Api/Mastodon/Statuses.php | 2 +- src/Module/Api/Mastodon/Statuses/Context.php | 2 +- src/Module/Api/Mastodon/Suggestions.php | 2 +- src/Module/Api/Mastodon/Timelines/Direct.php | 2 +- src/Module/Api/Mastodon/Timelines/Home.php | 2 +- src/Module/Api/Mastodon/Timelines/ListTimeline.php | 2 +- src/Module/Api/Mastodon/Timelines/PublicTimeline.php | 2 +- src/Module/Api/Mastodon/Timelines/Tag.php | 2 +- src/Module/Api/Mastodon/Trends.php | 2 +- src/Module/BaseApi.php | 8 ++++++-- src/Module/OAuth/Authorize.php | 2 +- src/Module/OAuth/Revoke.php | 2 +- src/Module/OAuth/Token.php | 2 +- 40 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/Module/Api/Friendica/Activity.php b/src/Module/Api/Friendica/Activity.php index aaab6417f..070dc452c 100644 --- a/src/Module/Api/Friendica/Activity.php +++ b/src/Module/Api/Friendica/Activity.php @@ -47,7 +47,7 @@ class Activity extends BaseApi $request = self::getRequest([ 'id' => 0, // Id of the post - ]); + ], $request); $res = Item::performActivity($request['id'], $this->parameters['verb'], $uid); diff --git a/src/Module/Api/Friendica/DirectMessages/Setseen.php b/src/Module/Api/Friendica/DirectMessages/Setseen.php index d64b4ee15..a6a4875b8 100644 --- a/src/Module/Api/Friendica/DirectMessages/Setseen.php +++ b/src/Module/Api/Friendica/DirectMessages/Setseen.php @@ -37,7 +37,7 @@ class Setseen extends BaseApi $request = self::getRequest([ 'id' => 0, // Id of the direct message - ]); + ], $request); // return error if id is zero if (empty($request['id'])) { diff --git a/src/Module/Api/Friendica/Events/Index.php b/src/Module/Api/Friendica/Events/Index.php index 86f79578d..6e3daa770 100644 --- a/src/Module/Api/Friendica/Events/Index.php +++ b/src/Module/Api/Friendica/Events/Index.php @@ -41,7 +41,7 @@ class Index extends BaseApi $request = self::getRequest([ 'since_id' => 0, 'count' => 0, - ]); + ], $request); $condition = ["`id` > ? AND `uid` = ?", $request['since_id'], $uid]; $params = ['limit' => $request['count']]; diff --git a/src/Module/Api/Friendica/Group/Delete.php b/src/Module/Api/Friendica/Group/Delete.php index 56b3445c0..ef38d9364 100644 --- a/src/Module/Api/Friendica/Group/Delete.php +++ b/src/Module/Api/Friendica/Group/Delete.php @@ -40,7 +40,7 @@ class Delete extends BaseApi $request = self::getRequest([ 'gid' => 0, 'name' => '' - ]); + ], $request); // params diff --git a/src/Module/Api/Friendica/Photo/Delete.php b/src/Module/Api/Friendica/Photo/Delete.php index 2edf398aa..1857de5c7 100644 --- a/src/Module/Api/Friendica/Photo/Delete.php +++ b/src/Module/Api/Friendica/Photo/Delete.php @@ -40,7 +40,7 @@ class Delete extends BaseApi $request = self::getRequest([ 'photo_id' => null, // Photo id - ]); + ], $request); // do several checks on input parameters // we do not allow calls without photo id diff --git a/src/Module/Api/Friendica/Photoalbum/Delete.php b/src/Module/Api/Friendica/Photoalbum/Delete.php index c7592a5ea..2d71e3581 100644 --- a/src/Module/Api/Friendica/Photoalbum/Delete.php +++ b/src/Module/Api/Friendica/Photoalbum/Delete.php @@ -41,7 +41,7 @@ class Delete extends BaseApi $request = self::getRequest([ 'album' => '', // Album name - ]); + ], $request); // we do not allow calls without album string if (empty($request['album'])) { diff --git a/src/Module/Api/Friendica/Photoalbum/Update.php b/src/Module/Api/Friendica/Photoalbum/Update.php index 87513c5ad..2c1e5e878 100644 --- a/src/Module/Api/Friendica/Photoalbum/Update.php +++ b/src/Module/Api/Friendica/Photoalbum/Update.php @@ -40,7 +40,7 @@ class Update extends BaseApi $request = self::getRequest([ 'album' => '', // Current album name 'album_new' => '', // New album name - ]); + ], $request); // we do not allow calls without album string if (empty($request['album'])) { diff --git a/src/Module/Api/Mastodon/Accounts/Followers.php b/src/Module/Api/Mastodon/Accounts/Followers.php index 08c56b3d4..ba24625c4 100644 --- a/src/Module/Api/Mastodon/Accounts/Followers.php +++ b/src/Module/Api/Mastodon/Accounts/Followers.php @@ -53,7 +53,7 @@ class Followers extends BaseApi 'since_id' => 0, // Return results newer than this id 'min_id' => 0, // Return results immediately newer than id 'limit' => 40, // Maximum number of results to return. Defaults to 40. - ]); + ], $request); $params = ['order' => ['relation-cid' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Accounts/Following.php b/src/Module/Api/Mastodon/Accounts/Following.php index ded1e6a4b..a80af6ea9 100644 --- a/src/Module/Api/Mastodon/Accounts/Following.php +++ b/src/Module/Api/Mastodon/Accounts/Following.php @@ -53,7 +53,7 @@ class Following extends BaseApi 'since_id' => 0, // Return results newer than this id 'min_id' => 0, // Return results immediately newer than id 'limit' => 40, // Maximum number of results to return. Defaults to 40. - ]); + ], $request); $params = ['order' => ['cid' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Accounts/Note.php b/src/Module/Api/Mastodon/Accounts/Note.php index cb0c18135..7135cb930 100644 --- a/src/Module/Api/Mastodon/Accounts/Note.php +++ b/src/Module/Api/Mastodon/Accounts/Note.php @@ -43,7 +43,7 @@ class Note extends BaseApi $request = self::getRequest([ 'comment' => '', - ]); + ], $request); $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid); if (empty($cdata['user'])) { diff --git a/src/Module/Api/Mastodon/Accounts/Relationships.php b/src/Module/Api/Mastodon/Accounts/Relationships.php index c3c886446..b56fd5a94 100644 --- a/src/Module/Api/Mastodon/Accounts/Relationships.php +++ b/src/Module/Api/Mastodon/Accounts/Relationships.php @@ -41,7 +41,7 @@ class Relationships extends BaseApi $request = self::getRequest([ 'id' => [], - ]); + ], $request); if (empty($request['id'])) { DI::mstdnError()->UnprocessableEntity(); diff --git a/src/Module/Api/Mastodon/Accounts/Search.php b/src/Module/Api/Mastodon/Accounts/Search.php index b7b963e11..53569b79a 100644 --- a/src/Module/Api/Mastodon/Accounts/Search.php +++ b/src/Module/Api/Mastodon/Accounts/Search.php @@ -47,7 +47,7 @@ class Search extends BaseApi 'limit' => 40, // Maximum number of results. Defaults to 40. 'resolve' => false, // Attempt WebFinger lookup. Defaults to false. Use this when q is an exact address. 'following' => false, // Only who the user is following. Defaults to false. - ]); + ], $request); $accounts = []; diff --git a/src/Module/Api/Mastodon/Accounts/Statuses.php b/src/Module/Api/Mastodon/Accounts/Statuses.php index 9027c68a4..609bcdb20 100644 --- a/src/Module/Api/Mastodon/Accounts/Statuses.php +++ b/src/Module/Api/Mastodon/Accounts/Statuses.php @@ -63,7 +63,7 @@ class Statuses extends BaseApi 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. 'exclude_reblogs' => false, // Undocumented parameter 'tagged' => false, // Undocumented parameter - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Apps.php b/src/Module/Api/Mastodon/Apps.php index 7b0b103c4..5811e3873 100644 --- a/src/Module/Api/Mastodon/Apps.php +++ b/src/Module/Api/Mastodon/Apps.php @@ -42,7 +42,7 @@ class Apps extends BaseApi 'redirect_uris' => '', 'scopes' => 'read', 'website' => '', - ]); + ], $request); // Workaround for AndStatus, see issue https://github.com/andstatus/andstatus/issues/538 $postdata = Network::postdata(); diff --git a/src/Module/Api/Mastodon/Blocks.php b/src/Module/Api/Mastodon/Blocks.php index fe08f875d..0a1e9506f 100644 --- a/src/Module/Api/Mastodon/Blocks.php +++ b/src/Module/Api/Mastodon/Blocks.php @@ -53,7 +53,7 @@ class Blocks extends BaseApi 'since_id' => 0, // Return results newer than this id 'min_id' => 0, // Return results immediately newer than id 'limit' => 40, // Maximum number of results. Defaults to 40. - ]); + ], $request); $params = ['order' => ['cid' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Bookmarks.php b/src/Module/Api/Mastodon/Bookmarks.php index e5fcaeeaf..d56ad5a88 100644 --- a/src/Module/Api/Mastodon/Bookmarks.php +++ b/src/Module/Api/Mastodon/Bookmarks.php @@ -47,7 +47,7 @@ class Bookmarks extends BaseApi 'since_id' => 0, // Return results newer than id 'min_id' => 0, // Return results immediately newer than id 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Conversations.php b/src/Module/Api/Mastodon/Conversations.php index fc32c76cc..5ff51deb1 100644 --- a/src/Module/Api/Mastodon/Conversations.php +++ b/src/Module/Api/Mastodon/Conversations.php @@ -59,7 +59,7 @@ class Conversations extends BaseApi 'max_id' => 0, // Return results older than this ID. Use HTTP Link header to paginate. 'since_id' => 0, // Return results newer than this ID. Use HTTP Link header to paginate. 'min_id' => 0, // Return results immediately newer than this ID. Use HTTP Link header to paginate. - ]); + ], $request); $params = ['order' => ['id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Directory.php b/src/Module/Api/Mastodon/Directory.php index 8ee6ac036..740d5d92a 100644 --- a/src/Module/Api/Mastodon/Directory.php +++ b/src/Module/Api/Mastodon/Directory.php @@ -46,7 +46,7 @@ class Directory extends BaseApi 'limit' => 40, // How many accounts to load. Default 40. 'order' => 'active', // active to sort by most recently posted statuses (default) or new to sort by most recently created profiles. 'local' => false, // Only return local accounts. - ]); + ], $request); Logger::info('directory', ['offset' => $request['offset'], 'limit' => $request['limit'], 'order' => $request['order'], 'local' => $request['local']]); diff --git a/src/Module/Api/Mastodon/Favourited.php b/src/Module/Api/Mastodon/Favourited.php index 3d3e6aad1..c1ac2a89c 100644 --- a/src/Module/Api/Mastodon/Favourited.php +++ b/src/Module/Api/Mastodon/Favourited.php @@ -47,7 +47,7 @@ class Favourited extends BaseApi 'min_id' => 0, // Return results immediately newer than id 'max_id' => 0, // Return results older than id 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. - ]); + ], $request); $params = ['order' => ['thr-parent-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index dbdab7e51..739c53c49 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -91,7 +91,7 @@ class FollowRequests extends BaseApi 'min_id' => 0, 'max_id' => 0, 'limit' => 40, // Maximum number of results to return. Defaults to 40. Paginate using the HTTP Link header. - ]); + ], $request); $introductions = DI::intro()->selectForUser($uid, $request['min_id'], $request['max_id'], $request['limit']); diff --git a/src/Module/Api/Mastodon/Lists.php b/src/Module/Api/Mastodon/Lists.php index ec9ad86a3..53a9ac012 100644 --- a/src/Module/Api/Mastodon/Lists.php +++ b/src/Module/Api/Mastodon/Lists.php @@ -58,7 +58,7 @@ class Lists extends BaseApi $request = self::getRequest([ 'title' => '', - ]); + ], $request); if (empty($request['title'])) { DI::mstdnError()->UnprocessableEntity(); diff --git a/src/Module/Api/Mastodon/Lists/Accounts.php b/src/Module/Api/Mastodon/Lists/Accounts.php index be87dbf9d..151da9cc6 100644 --- a/src/Module/Api/Mastodon/Lists/Accounts.php +++ b/src/Module/Api/Mastodon/Lists/Accounts.php @@ -66,7 +66,7 @@ class Accounts extends BaseApi 'since_id' => 0, // Return results newer than this id 'min_id' => 0, // Return results immediately newer than id 'limit' => 40, // Maximum number of results. Defaults to 40. Max 40. Set to 0 in order to get all accounts without pagination. - ]); + ], $request); $params = ['order' => ['contact-id' => true]]; diff --git a/src/Module/Api/Mastodon/Mutes.php b/src/Module/Api/Mastodon/Mutes.php index 515e04848..9d612a455 100644 --- a/src/Module/Api/Mastodon/Mutes.php +++ b/src/Module/Api/Mastodon/Mutes.php @@ -53,7 +53,7 @@ class Mutes extends BaseApi 'since_id' => 0, // Return results newer than this id 'min_id' => 0, // Return results immediately newer than id 'limit' => 40, // Maximum number of results. Defaults to 40. - ]); + ], $request); $params = ['order' => ['cid' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Notifications.php b/src/Module/Api/Mastodon/Notifications.php index 664c996c9..f57c0268e 100644 --- a/src/Module/Api/Mastodon/Notifications.php +++ b/src/Module/Api/Mastodon/Notifications.php @@ -64,7 +64,7 @@ class Notifications extends BaseApi 'account_id' => 0, // Return only notifications received from this account 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. 'count' => 0, // Unknown parameter - ]); + ], $request); $params = ['order' => ['id' => true]]; diff --git a/src/Module/Api/Mastodon/PushSubscription.php b/src/Module/Api/Mastodon/PushSubscription.php index 91e79b82d..b4b152e5c 100644 --- a/src/Module/Api/Mastodon/PushSubscription.php +++ b/src/Module/Api/Mastodon/PushSubscription.php @@ -42,7 +42,7 @@ class PushSubscription extends BaseApi $request = self::getRequest([ 'subscription' => [], 'data' => [], - ]); + ], $request); $subscription = [ 'application-id' => $application['id'], diff --git a/src/Module/Api/Mastodon/ScheduledStatuses.php b/src/Module/Api/Mastodon/ScheduledStatuses.php index e79d1e153..644aea874 100644 --- a/src/Module/Api/Mastodon/ScheduledStatuses.php +++ b/src/Module/Api/Mastodon/ScheduledStatuses.php @@ -76,7 +76,7 @@ class ScheduledStatuses extends BaseApi 'max_id' => 0, // Return results older than ID 'since_id' => 0, // Return results newer than ID 'min_id' => 0, // Return results immediately newer than ID - ]); + ], $request); $params = ['order' => ['id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Search.php b/src/Module/Api/Mastodon/Search.php index 026d71f04..1730db68c 100644 --- a/src/Module/Api/Mastodon/Search.php +++ b/src/Module/Api/Mastodon/Search.php @@ -56,7 +56,7 @@ class Search extends BaseApi 'limit' => 20, // Maximum number of results to load, per type. Defaults to 20. Max 40. 'offset' => 0, // Offset in search results. Used for pagination. Defaults to 0. 'following' => false, // Only include accounts that the user is following. Defaults to false. - ]); + ], $request); if (empty($request['q'])) { DI::mstdnError()->UnprocessableEntity(); diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 21bb97285..54e85d2a6 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -56,7 +56,7 @@ class Statuses extends BaseApi 'visibility' => '', // Visibility of the posted status. One of: "public", "unlisted", "private" or "direct". 'scheduled_at' => '', // ISO 8601 Datetime at which to schedule a status. Providing this paramter will cause ScheduledStatus to be returned instead of Status. Must be at least 5 minutes in the future. 'language' => '', // ISO 639 language code for this status. - ]); + ], $request); $owner = User::getOwnerDataById($uid); diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index 674be5f22..4193b8fa9 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -45,7 +45,7 @@ class Context extends BaseApi $request = self::getRequest([ 'limit' => 40, // Maximum number of results to return. Defaults to 40. - ]); + ], $request); $id = $this->parameters['id']; diff --git a/src/Module/Api/Mastodon/Suggestions.php b/src/Module/Api/Mastodon/Suggestions.php index bda78becf..d8d89070a 100644 --- a/src/Module/Api/Mastodon/Suggestions.php +++ b/src/Module/Api/Mastodon/Suggestions.php @@ -41,7 +41,7 @@ class Suggestions extends BaseApi $request = self::getRequest([ 'limit' => 40, // Maximum number of results to return. Defaults to 40. - ]); + ], $request); $suggestions = Contact\Relation::getSuggestions($uid, 0, $request['limit']); diff --git a/src/Module/Api/Mastodon/Timelines/Direct.php b/src/Module/Api/Mastodon/Timelines/Direct.php index ef2a9bb1a..f6b55a093 100644 --- a/src/Module/Api/Mastodon/Timelines/Direct.php +++ b/src/Module/Api/Mastodon/Timelines/Direct.php @@ -45,7 +45,7 @@ class Direct extends BaseApi 'since_id' => 0, // Return results newer than id 'min_id' => 0, // Return results immediately newer than id 'limit' => 20, // Maximum number of results to return. Defaults to 20. - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Timelines/Home.php b/src/Module/Api/Mastodon/Timelines/Home.php index 2727745f0..f717ef119 100644 --- a/src/Module/Api/Mastodon/Timelines/Home.php +++ b/src/Module/Api/Mastodon/Timelines/Home.php @@ -51,7 +51,7 @@ class Home extends BaseApi 'only_media' => false, // Show only statuses with media attached? Defaults to false. 'remote' => false, // Show only remote statuses? Defaults to false. 'exclude_replies' => false, // Don't show comments - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Timelines/ListTimeline.php b/src/Module/Api/Mastodon/Timelines/ListTimeline.php index 1fe3f3b47..a1ecd61f6 100644 --- a/src/Module/Api/Mastodon/Timelines/ListTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/ListTimeline.php @@ -55,7 +55,7 @@ class ListTimeline extends BaseApi 'local' => false, // Show only local statuses? Defaults to false. 'remote' => false, // Show only remote statuses? Defaults to false. 'exclude_replies' => false, // Don't show comments - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php index 91894f5c6..9d3b7f836 100644 --- a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php @@ -53,7 +53,7 @@ class PublicTimeline extends BaseApi 'limit' => 20, // Maximum number of results to return. Defaults to 20. 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. 'exclude_replies' => false, // Don't show comments - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Timelines/Tag.php b/src/Module/Api/Mastodon/Timelines/Tag.php index 701d656e4..d6915a68f 100644 --- a/src/Module/Api/Mastodon/Timelines/Tag.php +++ b/src/Module/Api/Mastodon/Timelines/Tag.php @@ -63,7 +63,7 @@ class Tag extends BaseApi 'limit' => 20, // Maximum number of results to return. Defaults to 20. 'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users. 'exclude_replies' => false, // Don't show comments - ]); + ], $request); $params = ['order' => ['uri-id' => true], 'limit' => $request['limit']]; diff --git a/src/Module/Api/Mastodon/Trends.php b/src/Module/Api/Mastodon/Trends.php index c9659f7d2..4e99b2c74 100644 --- a/src/Module/Api/Mastodon/Trends.php +++ b/src/Module/Api/Mastodon/Trends.php @@ -38,7 +38,7 @@ class Trends extends BaseApi { $request = self::getRequest([ 'limit' => 20, // Maximum number of results to return. Defaults to 10. - ]); + ], $request); $trending = []; $tags = Tag::getGlobalTrendingHashtags(24, 20); diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 009809376..5c94bc772 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -108,12 +108,16 @@ class BaseApi extends BaseModule /** * Processes data from GET requests and sets defaults * + * @param array $defaults Associative array of expected request keys and their default typed value. A null + * value will remove the request key from the resulting value array. + * @param array|null $request Custom REQUEST array, superglobal instead * @return array request data + * @throws \Exception */ - public static function getRequest(array $defaults) + public static function getRequest(array $defaults, array $request = null): array { $httpinput = HTTPInputData::process(); - $input = array_merge($httpinput['variables'], $httpinput['files'], $_REQUEST); + $input = array_merge($httpinput['variables'], $httpinput['files'], $request ?? $_REQUEST); self::$request = $input; self::$boundaries = []; diff --git a/src/Module/OAuth/Authorize.php b/src/Module/OAuth/Authorize.php index 851e0f461..973f31a0b 100644 --- a/src/Module/OAuth/Authorize.php +++ b/src/Module/OAuth/Authorize.php @@ -47,7 +47,7 @@ class Authorize extends BaseApi 'redirect_uri' => '', // Set a URI to redirect the user to. If this parameter is set to "urn:ietf:wg:oauth:2.0:oob" then the authorization code will be shown instead. Must match one of the redirect URIs declared during app registration. 'scope' => 'read', // List of requested OAuth scopes, separated by spaces (or by pluses, if using query parameters). Must be a subset of scopes declared during app registration. If not provided, defaults to "read". 'state' => '', - ]); + ], $request); if ($request['response_type'] != 'code') { Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]); diff --git a/src/Module/OAuth/Revoke.php b/src/Module/OAuth/Revoke.php index 6543969bf..536d603c7 100644 --- a/src/Module/OAuth/Revoke.php +++ b/src/Module/OAuth/Revoke.php @@ -38,7 +38,7 @@ class Revoke extends BaseApi 'client_id' => '', // Client ID, obtained during app registration 'client_secret' => '', // Client secret, obtained during app registration 'token' => '', // The previously obtained token, to be invalidated - ]); + ], $request); $condition = ['client_id' => $request['client_id'], 'client_secret' => $request['client_secret'], 'access_token' => $request['token']]; $token = DBA::selectFirst('application-view', ['id'], $condition); diff --git a/src/Module/OAuth/Token.php b/src/Module/OAuth/Token.php index 20ba22490..8bbb272c3 100644 --- a/src/Module/OAuth/Token.php +++ b/src/Module/OAuth/Token.php @@ -43,7 +43,7 @@ class Token extends BaseApi 'scope' => 'read', // List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration. If not provided, defaults to "read". 'code' => '', // A user authorization code, obtained via /oauth/authorize 'grant_type' => '', // Set equal to "authorization_code" if code is provided in order to gain user-level access. Otherwise, set equal to "client_credentials" to obtain app-level access only. - ]); + ], $request); // AndStatus transmits the client data in the AUTHORIZATION header field, see https://github.com/andstatus/andstatus/issues/530 $authorization = $_SERVER['HTTP_AUTHORIZATION'] ?? '';