From cc4e29258c824e59fe8116fad391ec07070487dc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2024 14:41:53 +0200 Subject: [PATCH 1/2] fix(chat): Remove commands Signed-off-by: Joas Schilling --- appinfo/info.xml | 9 - appinfo/routes.php | 1 - appinfo/routes/routesCommandController.php | 35 --- docs/commands.md | 99 +------- docs/events.md | 11 - docs/index.md | 1 - docs/occ.md | 77 ------ lib/AppInfo/Application.php | 7 - lib/Chat/ChatManager.php | 4 +- lib/Chat/Command/Executor.php | 200 ---------------- lib/Chat/Command/Listener.php | 117 --------- lib/Chat/Command/ShellExecutor.php | 76 ------ lib/Chat/Parser/Command.php | 10 +- lib/Command/Command/Add.php | 119 --------- lib/Command/Command/AddSamples.php | 130 ---------- lib/Command/Command/Delete.php | 65 ----- lib/Command/Command/ListCommand.php | 62 ----- lib/Command/Command/TRenderCommand.php | 56 ----- lib/Command/Command/Update.php | 125 ---------- lib/Controller/CommandController.php | 59 ----- lib/Events/CommandEvent.php | 72 ------ lib/Flow/Operation.php | 1 - lib/Migration/CreateHelpCommand.php | 68 ------ lib/Model/Command.php | 92 ------- lib/Model/CommandMapper.php | 100 -------- lib/Service/CommandService.php | 240 ------------------- lib/Settings/Admin/AdminSettings.php | 14 -- mkdocs.yml | 2 + sample-commands/calc.sh | 28 --- sample-commands/hackernews.php | 75 ------ sample-commands/wikipedia.php | 87 ------- src/components/AdminSettings/Commands.vue | 144 ----------- src/components/MessagesList/MessagesList.vue | 2 +- src/store/conversationsStore.js | 8 +- src/store/conversationsStore.spec.js | 22 -- src/views/AdminSettings.vue | 3 - templates/settings/admin-settings.php | 8 - tests/psalm-baseline.xml | 55 ++--- 38 files changed, 40 insertions(+), 2244 deletions(-) delete mode 100644 appinfo/routes/routesCommandController.php delete mode 100644 lib/Chat/Command/Executor.php delete mode 100644 lib/Chat/Command/Listener.php delete mode 100644 lib/Chat/Command/ShellExecutor.php delete mode 100644 lib/Command/Command/Add.php delete mode 100644 lib/Command/Command/AddSamples.php delete mode 100644 lib/Command/Command/Delete.php delete mode 100644 lib/Command/Command/ListCommand.php delete mode 100644 lib/Command/Command/TRenderCommand.php delete mode 100644 lib/Command/Command/Update.php delete mode 100644 lib/Controller/CommandController.php delete mode 100644 lib/Events/CommandEvent.php delete mode 100644 lib/Migration/CreateHelpCommand.php delete mode 100644 lib/Model/Command.php delete mode 100644 lib/Model/CommandMapper.php delete mode 100644 lib/Service/CommandService.php delete mode 100644 sample-commands/calc.sh delete mode 100644 sample-commands/hackernews.php delete mode 100644 sample-commands/wikipedia.php delete mode 100644 src/components/AdminSettings/Commands.vue diff --git a/appinfo/info.xml b/appinfo/info.xml index 803a42acbb5..952b62fe753 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -73,13 +73,9 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m OCA\Talk\Migration\FixNamespaceInDatabaseTables - OCA\Talk\Migration\CreateHelpCommand OCA\Talk\Migration\ClearResourceAccessCache OCA\Talk\Migration\CacheUserDisplayNames - - OCA\Talk\Migration\CreateHelpCommand - @@ -89,11 +85,6 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m OCA\Talk\Command\Bot\State OCA\Talk\Command\Bot\Setup OCA\Talk\Command\Bot\Uninstall - OCA\Talk\Command\Command\Add - OCA\Talk\Command\Command\AddSamples - OCA\Talk\Command\Command\Delete - OCA\Talk\Command\Command\ListCommand - OCA\Talk\Command\Command\Update OCA\Talk\Command\Developer\UpdateDocs OCA\Talk\Command\Monitor\Calls OCA\Talk\Command\Monitor\HasActiveCalls diff --git a/appinfo/routes.php b/appinfo/routes.php index be859e962ea..3713ff1b20a 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -31,7 +31,6 @@ include(__DIR__ . '/routes/routesCallController.php'), include(__DIR__ . '/routes/routesCertificateController.php'), include(__DIR__ . '/routes/routesChatController.php'), - include(__DIR__ . '/routes/routesCommandController.php'), include(__DIR__ . '/routes/routesFederationController.php'), include(__DIR__ . '/routes/routesFilesIntegrationController.php'), include(__DIR__ . '/routes/routesGuestController.php'), diff --git a/appinfo/routes/routesCommandController.php b/appinfo/routes/routesCommandController.php deleted file mode 100644 index 834032847d2..00000000000 --- a/appinfo/routes/routesCommandController.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * @author Lukas Reschke - * - * @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 . - * - */ - -$requirements = [ - 'apiVersion' => '(v1)', -]; - -return [ - 'ocs' => [ - /** @see \OCA\Talk\Controller\CommandController::index() */ - ['name' => 'Command#index', 'url' => '/api/{apiVersion}/command', 'verb' => 'GET', 'requirements' => $requirements], - ], -]; diff --git a/docs/commands.md b/docs/commands.md index 629abb682b1..9af5115101e 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -2,101 +2,4 @@ !!! warning - **Deprecation:** Commands are deprecated in favor of [Bots](bots.md). - ---- - -!!! note - - For security reasons commands can only be added via the - command line. `./occ talk:command:add --help` gives you - a short overview of the required arguments, but they are - explained here in more depth. - ---- - -## "Add command" arguments - -| Argument | Allowed chars | Description | -|------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `cmd` | [a-z0-9] | The keyword the user has to type to run this command (min. 1, max. 64 characters) | -| `name` | * | The author name of the response that is posted by the command (min. 1, max. 64 characters) | -| `script` | * | Actual command that is being ran. The script must be executable by the user of your webserver and has to use absolute paths only! See the parameter table below for options. The script is invoked with `--help` as argument on set up, to check if it can be executed correctly. | -| `response` | 0-2 | Who should see the response: 0 - No one, 1 - User who executed the command, 2 - Everyone | -| `enabled` | 0-3 | Who can use the command: 0 - No one, 1 - Moderators of the room, 2 - Logged in users, 3 - Everyone | - -## Script parameter - -| Parameter | Description | -|---------------|----------------------------------------------------| -| `{ROOM}` | The token of the room the command was used in | -| `{USER}` | ID of the user that called the command | -| `{ARGUMENTS}` | Everything the user write after the actual command | - -## Example - -### Create `/path/to/calc.sh` - -``` - while test $# -gt 0; do - case "$1" in - --help) - echo "/calc - A Nextcloud Talk chat wrapper for gnome-calculator" - echo " " - echo "Simple equations: /calc 3 + 4 * 5" - echo "Complex equations: /calc sin(3) + 3^3 * sqrt(5)" - exit 0 - ;; - *) - break - ;; - esac - done - - set -f - echo "$@ =" - echo $(gnome-calculator --solve="$@") -``` - -Please note, that your command should also understand the argument `--help`. -It should return a useful description, the first line is also displayed in a list of all commands when the user just types `/help`. - -### Register command - - -Make sure to use the absolute path to your script when registering the command: - -``` -./occ talk:command:add calculator calculator "/path/to/calc.sh {ARGUMENTS} {ROOM} {USER}" 1 3 -``` - -### Explanation -* User input by user `my user id` in the chat of room `index.php/call/4tf349j`: - - ``` - /calculator 1 + 2 + 3 + "hello" - ``` - - -* Executed shell command: - - ``` - /path/to/calc.sh '1 + 2 + 3 + "hello"' '4tf349j' 'my user id' - ``` - -## Aliases - -It is also possible to define an alias for a command. This allows e.g. to get the `/help` command also with the german word `/hilfe`. - -An alias for the `/calculator` command from above could be created using the following command: - -``` -./occ talk:command:add calc calculator "alias:calculator" 1 3 -``` - -Now `/calculator 1 + 2 + 3` and `/calc 1 + 2 + 3` result in the same message. - - -!!! note - - The enabled and response flag of the alias are ignored and the flags of the original command will be used and respected. + **Deprecation:** Commands have been removed in favor of [Bots](bots.md). diff --git a/docs/events.md b/docs/events.md index ea6bd421ec4..f71b82fce1d 100644 --- a/docs/events.md +++ b/docs/events.md @@ -156,17 +156,6 @@ listen to the `OCA\Talk\Events\SystemMessagesMultipleSentEvent` event instead. * Since: 18.0.0 * Since: 19.0.0 - Method `getParent()` was added -### Deprecated events - -These events were not using the typed-event mechanism and are therefore deprecated and will be removed in a future version. - -#### Command execution for apps - -* Event class: `OCA\Talk\Events\CommandEvent` -* Event name: `OCA\Talk\Chat\Command\Executor::EVENT_APP_EXECUTE` -* Since: 8.0.0 -* Deprecated: 17.0.0 - Commands are deprecated, please migrate to bots instead - ## Other events ### Turn servers get diff --git a/docs/index.md b/docs/index.md index 5d046a66e7d..86c9fa97ce5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,6 @@ * [Call experience](call-experience.md) * [Occ commands](occ.md) * [Bots](bot-list.md) -* [Commands (deprecated)](commands.md) * [Matterbridge integration](matterbridge.md) ## Developer documentation diff --git a/docs/occ.md b/docs/occ.md index 04dacdaf01a..f6fe0b066e6 100644 --- a/docs/occ.md +++ b/docs/occ.md @@ -106,83 +106,6 @@ Uninstall a bot from the server | `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | `'plain'` | | `--url` | The URL of the bot (required when no ID is given, ignored otherwise) | yes | yes | no | *Required* | -## talk:command:add - -Add a new command - -### Usage - -* `talk:command:add [--output [OUTPUT]] [--] - - diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index cb5bb0245bd..32063b251d5 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -499,7 +499,7 @@ export default { return false // Edited messages are not grouped } - if (message1.actorType === ATTENDEE.ACTOR_TYPE.BOTS // Don't group messages of commands and bots + if (message1.actorType === ATTENDEE.ACTOR_TYPE.BOTS // Don't group messages of bots && message1.actorId !== ATTENDEE.CHANGELOG_BOT_ID) { // Apart from the changelog bot return false } diff --git a/src/store/conversationsStore.js b/src/store/conversationsStore.js index a09ebf4e279..1c35d10ae31 100644 --- a/src/store/conversationsStore.js +++ b/src/store/conversationsStore.js @@ -693,8 +693,7 @@ const actions = { /** * Only use the last message as lastMessage when: * 1. It's not a command reply - * 2. It's not a temporary message starting with "/" which is a user posting a command - * 3. It's not a reaction or deletion of a reaction + * 2. It's not a reaction or deletion of a reaction * 3. It's not a deletion of a message */ if ((lastMessage.actorType !== ATTENDEE.ACTOR_TYPE.BOTS @@ -704,10 +703,7 @@ const actions = { && lastMessage.systemMessage !== 'reaction_deleted' && lastMessage.systemMessage !== 'reaction_revoked' && lastMessage.systemMessage !== 'message_deleted' - && lastMessage.systemMessage !== 'message_edited' - && !(typeof lastMessage.id.startsWith === 'function' - && lastMessage.id.startsWith('temp-') - && lastMessage.message.startsWith('/'))) { + && lastMessage.systemMessage !== 'message_edited') { commit('updateConversationLastMessage', { token, lastMessage }) } }, diff --git a/src/store/conversationsStore.spec.js b/src/store/conversationsStore.spec.js index 534252c393b..d8038b90974 100644 --- a/src/store/conversationsStore.spec.js +++ b/src/store/conversationsStore.spec.js @@ -1202,28 +1202,6 @@ describe('conversationsStore', () => { const changedConversation = store.getters.conversation(testToken) expect(changedConversation.lastMessage).toBe(testLastMessage) }) - - test('ignore update from temporary if posting a command', () => { - const testLastMessage = { - actorType: 'users', - actorId: 'admin', - systemMessage: '', - id: 'temp-42', - message: '/quit', - } - - testConversation.lastMessage = previousLastMessage - - store.dispatch('addConversation', testConversation) - - store.dispatch('updateConversationLastMessage', { - token: testToken, - lastMessage: testLastMessage, - }) - - const changedConversation = store.getters.conversation(testToken) - expect(changedConversation.lastMessage).toBe(previousLastMessage) - }) }) describe('creating conversations', () => { diff --git a/src/views/AdminSettings.vue b/src/views/AdminSettings.vue index fe686c2f7de..345d39c4840 100644 --- a/src/views/AdminSettings.vue +++ b/src/views/AdminSettings.vue @@ -27,7 +27,6 @@ - @@ -43,7 +42,6 @@ import { getCapabilities } from '@nextcloud/capabilities' import AllowedGroups from '../components/AdminSettings/AllowedGroups.vue' import BotsSettings from '../components/AdminSettings/BotsSettings.vue' -import Commands from '../components/AdminSettings/Commands.vue' import Federation from '../components/AdminSettings/Federation.vue' import GeneralSettings from '../components/AdminSettings/GeneralSettings.vue' import HostedSignalingServer from '../components/AdminSettings/HostedSignalingServer.vue' @@ -63,7 +61,6 @@ export default { components: { AllowedGroups, BotsSettings, - Commands, Federation, GeneralSettings, HostedSignalingServer, diff --git a/templates/settings/admin-settings.php b/templates/settings/admin-settings.php index e8a5a911ad3..26ebf39523f 100644 --- a/templates/settings/admin-settings.php +++ b/templates/settings/admin-settings.php @@ -14,14 +14,6 @@

t('Users that cannot use Talk anymore will still be listed as participants in their previous conversations and also their chat messages will be kept.')); ?>

-
-

t('Commands')) ?>

-

t('Specify commands the users can use in chats')); ?>

- -
-
-
-

t('STUN servers')) ?>

t('A STUN server is used to determine the public IP address of participants behind a router.')); ?>

diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 0339a1a5d97..b2776efd894 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,44 +1,39 @@ - + - BeforeTemplateRenderedEvent - BeforeTemplateRenderedEvent + + - SchemaWrapper + - NullCache + - $guestNames + - \OC_Util + - - - - - - null + - Filesystem + @@ -48,7 +43,7 @@ - $fileId + @@ -56,7 +51,7 @@ tokenProvider]]> tokenProvider]]> tokenProvider]]> - private + @@ -73,30 +68,30 @@ - BeforeTemplateRenderedEvent + - BeforeTemplateRenderedEvent + - Filesystem - \OC_Image + + - $recordingFolder + - Folder + - NoUserException - NoUserException + + @@ -104,20 +99,20 @@ getView()]]> getView()]]> getView()]]> - $view - $view - $view - Filesystem + + + + - Cache + - NoUserException + From 9a7f3059dca9e28a01aea08327d2c38ac56788b8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2024 15:01:42 +0200 Subject: [PATCH 2/2] fix(commands): Also remove tests Signed-off-by: Joas Schilling --- .../features/chat-1/commands.feature | 46 ----- .../integration/features/chat-2/reply.feature | 13 -- .../features/command/command-list.feature | 24 --- tests/php/Chat/Command/ExecutorTest.php | 159 ------------------ tests/php/Chat/Command/ShellExecutorTest.php | 106 ------------ tests/php/Chat/Command/echo-argument.sh | 1 - tests/php/Chat/Command/echo-option.sh | 11 -- .../php/Settings/Admin/AdminSettingsTest.php | 8 - 8 files changed, 368 deletions(-) delete mode 100644 tests/integration/features/chat-1/commands.feature delete mode 100644 tests/integration/features/command/command-list.feature delete mode 100644 tests/php/Chat/Command/ExecutorTest.php delete mode 100644 tests/php/Chat/Command/ShellExecutorTest.php delete mode 100755 tests/php/Chat/Command/echo-argument.sh delete mode 100755 tests/php/Chat/Command/echo-option.sh diff --git a/tests/integration/features/chat-1/commands.feature b/tests/integration/features/chat-1/commands.feature deleted file mode 100644 index a853e2ccacf..00000000000 --- a/tests/integration/features/chat-1/commands.feature +++ /dev/null @@ -1,46 +0,0 @@ -Feature: chat/commands - Background: - Given user "participant1" exists - Given user "participant2" exists - - Scenario: user can see own help command and others can not - Given user "participant1" creates room "group room" (v4) - | roomType | 2 | - | roomName | room | - And user "participant1" adds user "participant2" to room "group room" with 200 (v4) - When user "participant1" sends message "/help" to room "group room" with 201 - Then user "participant1" sees the following messages in room "group room" with 200 - | room | actorType | actorId | actorDisplayName | message | messageParameters | - | group room | bots | talk | talk-bot | There are currently no commands available. | [] | - And user "participant2" sees the following messages in room "group room" with 200 - - Scenario: user can see own help command along with regular messages and others can not - Given user "participant1" creates room "group room" (v4) - | roomType | 2 | - | roomName | room | - And user "participant1" adds user "participant2" to room "group room" with 200 (v4) - When user "participant1" sends message "Message 1" to room "group room" with 201 - And user "participant1" sends message "/help" to room "group room" with 201 - And user "participant1" sends message "Message 2" to room "group room" with 201 - Then user "participant1" sees the following messages in room "group room" with 200 - | room | actorType | actorId | actorDisplayName | message | messageParameters | - | group room | users | participant1 | participant1-displayname | Message 2 | [] | - | group room | bots | talk | talk-bot | There are currently no commands available. | [] | - | group room | users | participant1 | participant1-displayname | Message 1 | [] | - And user "participant2" sees the following messages in room "group room" with 200 - | room | actorType | actorId | actorDisplayName | message | messageParameters | - | group room | users | participant1 | participant1-displayname | Message 2 | [] | - | group room | users | participant1 | participant1-displayname | Message 1 | [] | - - Scenario: double slash escapes a command for everyone - Given user "participant1" creates room "group room" (v4) - | roomType | 2 | - | roomName | room | - And user "participant1" adds user "participant2" to room "group room" with 200 (v4) - When user "participant1" sends message "//help" to room "group room" with 201 - Then user "participant1" sees the following messages in room "group room" with 200 - | room | actorType | actorId | actorDisplayName | message | messageParameters | - | group room | users | participant1 | participant1-displayname | /help | [] | - And user "participant2" sees the following messages in room "group room" with 200 - | room | actorType | actorId | actorDisplayName | message | messageParameters | - | group room | users | participant1 | participant1-displayname | /help | [] | diff --git a/tests/integration/features/chat-2/reply.feature b/tests/integration/features/chat-2/reply.feature index 42404ce583e..67d455b1b92 100644 --- a/tests/integration/features/chat-2/reply.feature +++ b/tests/integration/features/chat-2/reply.feature @@ -90,19 +90,6 @@ Feature: chat-2/reply | group room | users | participant1 | participant1-displayname | Message X-1 | [] | {file} | | group room | users | participant1 | participant1-displayname | {file} | "IGNORE" | | - Scenario: user can not reply to commands - Given user "participant1" creates room "group room" (v4) - | roomType | 2 | - | invite | attendees1 | - And user "participant1" sends message "/help" to room "group room" with 201 - # In the tests the reference for the message to reply to is got from the - # messages originally sent, not from how they are returned by the server. - When user "participant1" sends reply "Message X-1" on message "/help" to room "group room" with 400 - Then user "participant1" sees the following messages in room "group room" with 200 - | room | actorType | actorId | actorDisplayName | message | messageParameters | parentMessage | - | group room | bots | talk | talk-bot | There are currently no commands available. | [] | | - And user "participant2" sees the following messages in room "group room" with 200 - Scenario: user can not reply to system messages Given user "participant1" creates room "group room" (v4) | roomType | 2 | diff --git a/tests/integration/features/command/command-list.feature b/tests/integration/features/command/command-list.feature deleted file mode 100644 index d853e4839b2..00000000000 --- a/tests/integration/features/command/command-list.feature +++ /dev/null @@ -1,24 +0,0 @@ -Feature: command/command-list - - Scenario: Get the output options - Given invoking occ with "talk:command:list --help" - Then the command was successful - And the command output contains the text "Output format" - - Scenario: List all available commands as plain text and verify if contains the help command as markdown table (default) - Given invoking occ with "talk:command:list" - Then the command was successful - And the command output contains the text "| help" - - Scenario: List all available commands as plain text and verify if contains the help command as markdown table - Given invoking occ with "talk:command:list --output=plain" - Then the command was successful - And the command output contains the text "| help" - - Scenario: List all available commands as json and verify if contains the help command as json format - Given invoking occ with "talk:command:list --output=json" - Then the command was successful - And the command output contains the text: - """ - "name":"talk","command":"help","script":"help" - """ diff --git a/tests/php/Chat/Command/ExecutorTest.php b/tests/php/Chat/Command/ExecutorTest.php deleted file mode 100644 index 8ec95901599..00000000000 --- a/tests/php/Chat/Command/ExecutorTest.php +++ /dev/null @@ -1,159 +0,0 @@ -. - * - */ - -namespace OCA\Talk\Tests\php\Chat\Command; - -use OCA\Talk\Chat\Command\Executor; -use OCA\Talk\Chat\Command\ShellExecutor; -use OCA\Talk\Events\CommandEvent; -use OCA\Talk\Model\Command; -use OCA\Talk\Room; -use OCA\Talk\Service\CommandService; -use OCP\Comments\IComment; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\IL10N; -use PHPUnit\Framework\MockObject\MockObject; -use Psr\Log\LoggerInterface; -use Test\TestCase; - -class ExecutorTest extends TestCase { - protected IEventDispatcher&MockObject $dispatcher; - protected ShellExecutor&MockObject $shellExecutor; - protected CommandService&MockObject $commandService; - protected LoggerInterface&MockObject $logger; - protected IL10N&MockObject $l10n; - protected ?Executor $executor = null; - - public function setUp(): void { - parent::setUp(); - - $this->dispatcher = $this->createMock(IEventDispatcher::class); - $this->shellExecutor = $this->createMock(ShellExecutor::class); - $this->commandService = $this->createMock(CommandService::class); - $this->logger = $this->createMock(LoggerInterface::class); - $this->l10n = $this->createMock(IL10N::class); - $this->executor = new Executor( - $this->dispatcher, - $this->shellExecutor, - $this->commandService, - $this->logger, - $this->l10n - ); - } - - public static function dataExecApp(): array { - return [ - ['arguments1', ''], - ['arguments2', "output from\nevent"], - ]; - } - - /** - * @dataProvider dataExecApp - */ - public function testExecApp(string $arguments, string $expected): void { - $message = $this->createMock(IComment::class); - $room = $this->createMock(Room::class); - $command = Command::fromParams([]); - - $event = $this->createMock(CommandEvent::class); - $event->expects($this->once()) - ->method('getOutput') - ->willReturn($expected); - - $executor = $this->getMockBuilder(Executor::class) - ->setConstructorArgs([ - $this->dispatcher, - $this->shellExecutor, - $this->commandService, - $this->logger, - $this->l10n, - ]) - ->onlyMethods(['createEvent']) - ->getMock(); - $executor->expects($this->once()) - ->method('createEvent') - ->with($room, $message, $command, $arguments) - ->willReturn($event); - - $this->dispatcher->expects($this->once()) - ->method('dispatch') - ->with(Executor::EVENT_APP_EXECUTE, $event); - - $this->assertSame($expected, self::invokePrivate($executor, 'execApp', [$room, $message, $command, $arguments])); - } - - public static function dataExecShell(): array { - return [ - ['admin', 'token', '', '', ''], - ['admin', 'token', '/var/www/nextcloud/script.sh {USER} {ROOM} {ARGUMENTS}', 'foo bar "hello bear"', 'output1'], - ['admin', 'token', '/var/www/nextcloud/script.sh {USER} {ROOM} --arguments="{ARGUMENTS_DOUBLEQUOTE_ESCAPED}"', 'foo bar "hello bear"', "out\nput\n2"], - ]; - } - - /** - * @dataProvider dataExecShell - */ - public function testExecShell(?string $actorId, string $roomToken, string $script, string $arguments, string $output): void { - /** @var IComment&MockObject $message */ - $message = $this->createMock(IComment::class); - if ($actorId === null) { - $message->expects($this->once()) - ->method('getActorType') - ->willReturn('guests'); - $message->expects($this->never()) - ->method('getActorId'); - } else { - $message->expects($this->once()) - ->method('getActorType') - ->willReturn('users'); - $message->expects($this->once()) - ->method('getActorId') - ->willReturn($actorId); - } - - /** @var Room&MockObject $room */ - $room = $this->createMock(Room::class); - $room->expects($this->once()) - ->method('getToken') - ->willReturn($roomToken); - - /** @var Command $command */ - $command = Command::fromParams([ - 'script' => $script, - ]); - - $this->shellExecutor->expects($this->once()) - ->method('execShell') - ->with( - $script, - $arguments, - $roomToken, - (string) $actorId - ) - ->willReturn($output); - - $this->assertSame($output, $this->executor->execShell($room, $message, $command, $arguments)); - } -} diff --git a/tests/php/Chat/Command/ShellExecutorTest.php b/tests/php/Chat/Command/ShellExecutorTest.php deleted file mode 100644 index 071e2bc9e75..00000000000 --- a/tests/php/Chat/Command/ShellExecutorTest.php +++ /dev/null @@ -1,106 +0,0 @@ -. - * - */ - -namespace OCA\Talk\Tests\php\Chat\Command; - -use OCA\Talk\Chat\Command\ShellExecutor; -use Test\TestCase; - -class ShellExecutorTest extends TestCase { - public static function dataExecShellRun(): array { - return [ - ['admin', 'token', 'echo {ARGUMENTS}', '$PATH', '$PATH'], - ['admin', 'token', 'echo {ARGUMENTS}', '$(pwd)', '$(pwd)'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '$(pwd)', '$(pwd)'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '$PATH', '$PATH'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '$(pwd)', '$(pwd)'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '$PATH', '$PATH'], - - ['admin', 'token', 'echo {ARGUMENTS}', '\\$PATH', '\\$PATH'], - ['admin', 'token', 'echo {ARGUMENTS}', '\\$(pwd)', '\\$(pwd)'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '\\$(pwd)', '\\$(pwd)'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '\\$PATH', '\\$PATH'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '\\$(pwd)', '\\$(pwd)'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '\\$PATH', '\\$PATH'], - - ['admin', 'token', 'echo {ARGUMENTS}', '`echo $PATH`', '`echo $PATH`'], - ['admin', 'token', 'echo {ARGUMENTS}', '`pwd`', '`pwd`'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '`pwd`', '`pwd`'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '`echo $PATH`', '`echo $PATH`'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '`pwd`', '`pwd`'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '`echo $PATH`', '`echo $PATH`'], - - ['admin', 'token', 'echo {ARGUMENTS}', '\\`echo $PATH\\`', '\\`echo $PATH\\`'], - ['admin', 'token', 'echo {ARGUMENTS}', '\\`pwd \\`', '\\`pwd \\`'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '\\`pwd \\`', '\\`pwd \\`'], - ['admin', 'token', __DIR__ . '/echo-argument.sh {ARGUMENTS}', '\\`echo $PATH\\`', '\\`echo $PATH\\`'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '\\`pwd \\`', '\\`pwd \\`'], - ['admin', 'token', __DIR__ . '/echo-option.sh -a {ARGUMENTS}', '\\`echo $PATH\\`', '\\`echo $PATH\\`'], - ]; - } - - /** - * @dataProvider dataExecShellRun - */ - public function testExecShellRun(?string $actorId, string $roomToken, string $cmd, string $arguments, string $output): void { - $executor = new ShellExecutor(); - $this->assertSame($output, $executor->execShell($cmd, $arguments, $roomToken, $actorId)); - } - - public static function dataExecShell(): array { - return [ - ['admin', 'token', '', '', '', ''], - ['admin', 'token', '/var/www/nextcloud/script.sh {USER} {ROOM} {ARGUMENTS}', 'foo bar "hello bear"', "/var/www/nextcloud/script.sh 'admin' 'token' 'foo bar \"hello bear\"'", 'output1'], - ['admin', 'token', '/var/www/nextcloud/script.sh {USER} {ROOM} --arguments {ARGUMENTS}', 'foo bar "hello bear"', "/var/www/nextcloud/script.sh 'admin' 'token' --arguments 'foo bar \"hello bear\"'", "out\nput\n2"], - ]; - } - - /** - * @dataProvider dataExecShell - */ - public function testExecShell(?string $actorId, string $roomToken, string $cmd, string $arguments, string $expected, string $output): void { - $executor = $this->getMockBuilder(ShellExecutor::class) - ->onlyMethods(['wrapExec']) - ->getMock(); - - $executor->expects($this->once()) - ->method('wrapExec') - ->with($expected) - ->willReturn($output); - - $this->assertSame($output, self::invokePrivate($executor, 'execShell', [$cmd, $arguments, $roomToken, $actorId])); - } - - public function testLegacyArguments(): void { - $executor = $this->getMockBuilder(ShellExecutor::class) - ->onlyMethods(['wrapExec']) - ->getMock(); - - $executor->expects($this->never()) - ->method('wrapExec'); - - $this->expectException(\InvalidArgumentException::class); - self::invokePrivate($executor, 'execShell', ['echo "{ARGUMENTS_DOUBLEQUOTE_ESCAPED}"', 'arguments', '', '']); - } -} diff --git a/tests/php/Chat/Command/echo-argument.sh b/tests/php/Chat/Command/echo-argument.sh deleted file mode 100755 index cf024e95cc8..00000000000 --- a/tests/php/Chat/Command/echo-argument.sh +++ /dev/null @@ -1 +0,0 @@ -echo "$1" diff --git a/tests/php/Chat/Command/echo-option.sh b/tests/php/Chat/Command/echo-option.sh deleted file mode 100755 index c263f955bba..00000000000 --- a/tests/php/Chat/Command/echo-option.sh +++ /dev/null @@ -1,11 +0,0 @@ -while getopts ":a:" o; do - case "${o}" in - a) - s=${OPTARG} - ;; - *) - ;; - esac -done - -echo "${s}" diff --git a/tests/php/Settings/Admin/AdminSettingsTest.php b/tests/php/Settings/Admin/AdminSettingsTest.php index 91e9e6eda62..abdaa4a2a63 100644 --- a/tests/php/Settings/Admin/AdminSettingsTest.php +++ b/tests/php/Settings/Admin/AdminSettingsTest.php @@ -25,7 +25,6 @@ use OCA\Talk\Config; use OCA\Talk\MatterbridgeManager; -use OCA\Talk\Service\CommandService; use OCA\Talk\Settings\Admin\AdminSettings; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Services\IInitialState; @@ -43,7 +42,6 @@ class AdminSettingsTest extends TestCase { protected Config&MockObject $talkConfig; protected IConfig&MockObject $serverConfig; protected IAppConfig&MockObject $appConfig; - protected CommandService&MockObject $commandService; protected IInitialState&MockObject $initialState; protected ICacheFactory&MockObject $cacheFactory; protected IGroupManager&MockObject $groupManager; @@ -59,7 +57,6 @@ public function setUp(): void { $this->talkConfig = $this->createMock(Config::class); $this->serverConfig = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); - $this->commandService = $this->createMock(CommandService::class); $this->initialState = $this->createMock(IInitialState::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->groupManager = $this->createMock(IGroupManager::class); @@ -81,7 +78,6 @@ protected function getAdminSettings(array $methods = []): AdminSettings { $this->talkConfig, $this->serverConfig, $this->appConfig, - $this->commandService, $this->initialState, $this->cacheFactory, $this->groupManager, @@ -97,7 +93,6 @@ protected function getAdminSettings(array $methods = []): AdminSettings { $this->talkConfig, $this->serverConfig, $this->appConfig, - $this->commandService, $this->initialState, $this->cacheFactory, $this->groupManager, @@ -124,7 +119,6 @@ public function testGetForm(): void { $admin = $this->getAdminSettings([ 'initGeneralSettings', 'initAllowedGroups', - 'initCommands', 'initStunServers', 'initTurnServers', 'initSignalingServers', @@ -135,8 +129,6 @@ public function testGetForm(): void { ->method('initGeneralSettings'); $admin->expects($this->once()) ->method('initAllowedGroups'); - $admin->expects($this->once()) - ->method('initCommands'); $admin->expects($this->once()) ->method('initStunServers'); $admin->expects($this->once())