Skip to content

Commit 31fe38f

Browse files
authored
Merge pull request #2050 from RedisInsight/bugfix/feature/RI-4352-upload_data_win_error
#RI-4466 fix file was not found on win
2 parents 8ac5cab + 5c9c697 commit 31fe38f

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

redisinsight/api/src/modules/bulk-actions/bulk-import.service.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,19 @@ describe('BulkImportService', () => {
260260
expect(mockedFs.readFile).toHaveBeenCalledWith(join(PATH_CONFIG.homedir, 'danger'));
261261
});
262262

263-
it('should normalize path before importing and not search for file outside home folder (relative)', async () => {
263+
it('should normalize path before importing and throw an error when search for file outside home folder (relative)', async () => {
264264
mockedFs.pathExists.mockImplementationOnce(async () => true);
265265

266-
await service.uploadFromTutorial(mockClientMetadata, {
267-
path: '../../../danger',
268-
});
266+
try {
267+
await service.uploadFromTutorial(mockClientMetadata, {
268+
path: '../../../danger',
269+
});
269270

270-
expect(mockedFs.readFile).toHaveBeenCalledWith(join(PATH_CONFIG.homedir, 'danger'));
271+
fail();
272+
} catch (e) {
273+
expect(e).toBeInstanceOf(BadRequestException);
274+
expect(e.message).toEqual('Data file was not found');
275+
}
271276
});
272277

273278
it('should throw BadRequest when no file found', async () => {
@@ -289,9 +294,8 @@ describe('BulkImportService', () => {
289294
mockedFs.stat.mockImplementationOnce(async () => ({ size: 100 * 1024 * 1024 + 1 } as fs.Stats));
290295

291296
try {
292-
await service.uploadFromTutorial(mockClientMetadata, {
293-
path: '../../../danger',
294-
});
297+
await service.uploadFromTutorial(mockClientMetadata, mockUploadImportFileByPathDto);
298+
295299
fail();
296300
} catch (e) {
297301
expect(e).toBeInstanceOf(BadRequestException);

redisinsight/api/src/modules/bulk-actions/bulk-import.service.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,18 @@ export class BulkImportService {
155155
dto: UploadImportFileByPathDto,
156156
): Promise<IBulkActionOverview> {
157157
try {
158+
const filePath = join(dto.path);
159+
158160
const staticPath = join(SERVER_CONFIG.base, SERVER_CONFIG.staticUri);
159161

160-
let trimmedPath = dto.path;
161-
if (dto.path.indexOf(staticPath) === 0) {
162-
trimmedPath = dto.path.slice(staticPath.length);
162+
let trimmedPath = filePath;
163+
if (filePath.indexOf(staticPath) === 0) {
164+
trimmedPath = filePath.slice(staticPath.length);
163165
}
164166

165-
const resolvedPath = resolve(
166-
'/',
167-
trimmedPath,
168-
);
169-
170-
const path = join(PATH_CONFIG.homedir, resolvedPath);
167+
const path = join(PATH_CONFIG.homedir, trimmedPath);
171168

172-
if (!await fs.pathExists(path)) {
169+
if (!path.startsWith(PATH_CONFIG.homedir) || !await fs.pathExists(path)) {
173170
throw new BadRequestException('Data file was not found');
174171
}
175172

0 commit comments

Comments
 (0)