Skip to content

Commit 972e854

Browse files
#RI-3742-resolve comments
1 parent e123588 commit 972e854

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

redisinsight/api/src/constants/telemetry-events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ export enum CommandType {
6161
Core = 'core',
6262
Module = 'module',
6363
}
64+
65+
export const unknownCommand = 'unknown';

redisinsight/api/src/modules/cli/services/cli-business/cli-business.service.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
CommandParsingError,
2929
WrongDatabaseTypeError,
3030
} from 'src/modules/cli/constants/errors';
31+
import { unknownCommand } from 'src/constants';
3132
import { CliAnalyticsService } from 'src/modules/cli/services/cli-analytics/cli-analytics.service';
3233
import { KeytarUnavailableException } from 'src/modules/encryption/exceptions';
3334
import { RedisToolService } from 'src/modules/redis/redis-tool.service';
@@ -330,6 +331,7 @@ describe('CliBusinessService', () => {
330331
ERROR_MESSAGES.CLI_UNTERMINATED_QUOTES(),
331332
),
332333
{
334+
command: unknownCommand,
333335
outputFormat: CliOutputFormatterTypes.Raw,
334336
},
335337
);
@@ -591,6 +593,7 @@ describe('CliBusinessService', () => {
591593
mockClientOptions.instanceId,
592594
new CommandParsingError(ERROR_MESSAGES.CLI_UNTERMINATED_QUOTES()),
593595
{
596+
command: unknownCommand,
594597
outputFormat: CliOutputFormatterTypes.Raw,
595598
},
596599
);
@@ -920,6 +923,7 @@ describe('CliBusinessService', () => {
920923
mockClientOptions.instanceId,
921924
new CommandParsingError(ERROR_MESSAGES.CLI_UNTERMINATED_QUOTES()),
922925
{
926+
command: unknownCommand,
923927
outputFormat: CliOutputFormatterTypes.Raw,
924928
},
925929
);

redisinsight/api/src/modules/cli/services/cli-business/cli-business.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Logger,
66
} from '@nestjs/common';
77
import { IFindRedisClientInstanceByOptions } from 'src/modules/redis/redis.service';
8+
import { unknownCommand } from 'src/constants';
89
import { CommandsService } from 'src/modules/commands/commands.service';
910
import {
1011
ClusterNodeRole,
@@ -143,7 +144,7 @@ export class CliBusinessService {
143144
): Promise<SendCommandResponse> {
144145
this.logger.log('Executing redis CLI command.');
145146
const { command: commandLine } = dto;
146-
let command: string;
147+
let command: string = unknownCommand;
147148
let args: string[] = [];
148149

149150
const outputFormat = dto.outputFormat || CliOutputFormatterTypes.Raw;
@@ -229,7 +230,7 @@ export class CliBusinessService {
229230
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Raw,
230231
): Promise<SendClusterCommandResponse[]> {
231232
this.logger.log(`Executing redis.cluster CLI command for [${role}] nodes.`);
232-
let command: string;
233+
let command: string = unknownCommand;
233234
let args: string[] = [];
234235

235236
try {
@@ -298,7 +299,7 @@ export class CliBusinessService {
298299
outputFormat: CliOutputFormatterTypes = CliOutputFormatterTypes.Raw,
299300
): Promise<SendClusterCommandResponse> {
300301
this.logger.log(`Executing redis.cluster CLI command for single node ${JSON.stringify(nodeOptions)}`);
301-
let command: string;
302+
let command: string = unknownCommand;
302303
let args: string[] = [];
303304

304305
try {

redisinsight/api/src/modules/workbench/providers/workbench-commands.executor.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
mockDatabase,
66
mockWorkbenchAnalyticsService,
77
} from 'src/__mocks__';
8+
import ERROR_MESSAGES from 'src/constants/error-messages';
9+
import { unknownCommand } from 'src/constants';
810
import { IFindRedisClientInstanceByOptions } from 'src/modules/redis/redis.service';
911
import { WorkbenchCommandsExecutor } from 'src/modules/workbench/providers/workbench-commands.executor';
1012
import {
@@ -17,6 +19,7 @@ import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
1719
import { BadRequestException, InternalServerErrorException, ServiceUnavailableException } from '@nestjs/common';
1820
import {
1921
CommandNotSupportedError,
22+
CommandParsingError,
2023
ClusterNodeNotFoundError,
2124
WrongDatabaseTypeError,
2225
} from 'src/modules/cli/constants/errors';
@@ -49,6 +52,7 @@ const mockCliNodeResponse: ICliExecResultFromNode = {
4952
};
5053

5154
const mockSetCommand = 'set';
55+
const mockGetEscapedKeyCommand = 'get "\\\\key';
5256
const mockCreateCommandExecutionDto: CreateCommandExecutionDto = {
5357
command: `${mockSetCommand} foo bar`,
5458
nodeOptions: {
@@ -564,5 +568,35 @@ describe('WorkbenchCommandsExecutor', () => {
564568
}
565569
});
566570
});
571+
describe('CommandParsingError', () => {
572+
it('should return response with [CLI_UNTERMINATED_QUOTES] error for sendCommandForNodes', async () => {
573+
const mockResult = [
574+
{
575+
response: ERROR_MESSAGES.CLI_UNTERMINATED_QUOTES(),
576+
status: CommandExecutionStatus.Fail,
577+
},
578+
];
579+
580+
const result = await service.sendCommand(mockClientOptions, {
581+
command: mockGetEscapedKeyCommand,
582+
role: mockCreateCommandExecutionDto.role,
583+
mode: RunQueryMode.ASCII,
584+
});
585+
586+
expect(result).toEqual(mockResult);
587+
expect(mockAnalyticsService.sendCommandExecutedEvent).toHaveBeenCalledWith(
588+
mockClientOptions.instanceId,
589+
{
590+
response: ERROR_MESSAGES.CLI_UNTERMINATED_QUOTES(),
591+
error: new CommandParsingError(ERROR_MESSAGES.CLI_UNTERMINATED_QUOTES()),
592+
status: CommandExecutionStatus.Fail,
593+
},
594+
{
595+
command: unknownCommand,
596+
rawMode: false,
597+
},
598+
);
599+
});
600+
});
567601
});
568602
});

redisinsight/api/src/modules/workbench/providers/workbench-commands.executor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ClusterNodeNotFoundError,
1919
WrongDatabaseTypeError,
2020
} from 'src/modules/cli/constants/errors';
21+
import { unknownCommand } from 'src/constants';
2122
import { CommandExecutionResult } from 'src/modules/workbench/models/command-execution-result';
2223
import { CreateCommandExecutionDto, RunQueryMode } from 'src/modules/workbench/dto/create-command-execution.dto';
2324
import { RedisToolService } from 'src/modules/redis/redis-tool.service';
@@ -62,18 +63,17 @@ export class WorkbenchCommandsExecutor {
6263
dto: CreateCommandExecutionDto,
6364
): Promise<CommandExecutionResult[]> {
6465
let result;
66+
let command = unknownCommand;
67+
let commandArgs: string[] = [];
6568

6669
const {
6770
command: commandLine,
6871
role,
6972
nodeOptions,
7073
mode,
7174
} = dto;
72-
let command = commandLine;
73-
7475
try {
75-
const [parsedCommand, ...commandArgs] = splitCliCommandLine(commandLine);
76-
command = parsedCommand;
76+
[command, ...commandArgs] = splitCliCommandLine(commandLine);
7777

7878
if (nodeOptions) {
7979
result = [await this.sendCommandForSingleNode(

0 commit comments

Comments
 (0)