Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): server-side checking of duplicate import paths and exclusion patterns #6993

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions server/e2e/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ describe(`${LibraryController.name} (e2e)`, () => {
);
});

it('should not create an external library with duplicate import paths', async () => {
const { status, body } = await request(server)
.post('/library')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({
type: LibraryType.EXTERNAL,
name: 'My Awesome Library',
importPaths: ['/path', '/path'],
exclusionPatterns: ['**/Raw/**'],
});

expect(status).toBe(400);
expect(body).toEqual(errorStub.badRequest(["All importPaths's elements must be unique"]));
});

it('should not create an external library with duplicate exclusion patterns', async () => {
const { status, body } = await request(server)
.post('/library')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({
type: LibraryType.EXTERNAL,
name: 'My Awesome Library',
importPaths: ['/path/to/import'],
exclusionPatterns: ['**/Raw/**', '**/Raw/**'],
});

expect(status).toBe(400);
expect(body).toEqual(errorStub.badRequest(["All exclusionPatterns's elements must be unique"]));
});

it('should create an upload library with defaults', async () => {
const { status, body } = await request(server)
.post('/library')
Expand Down Expand Up @@ -229,7 +259,7 @@ describe(`${LibraryController.name} (e2e)`, () => {
);
});

it('should not allow an empty import path', async () => {
it('should reject an empty import path', async () => {
const { status, body } = await request(server)
.put(`/library/${library.id}`)
.set('Authorization', `Bearer ${admin.accessToken}`)
Expand All @@ -239,6 +269,16 @@ describe(`${LibraryController.name} (e2e)`, () => {
expect(body).toEqual(errorStub.badRequest(['each value in importPaths should not be empty']));
});

it('should reject duplicate import paths', async () => {
const { status, body } = await request(server)
.put(`/library/${library.id}`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ importPaths: ['/path', '/path'] });

expect(status).toBe(400);
expect(body).toEqual(errorStub.badRequest(["All importPaths's elements must be unique"]));
});

it('should change the exclusion pattern', async () => {
const { status, body } = await request(server)
.put(`/library/${library.id}`)
Expand All @@ -253,7 +293,17 @@ describe(`${LibraryController.name} (e2e)`, () => {
);
});

it('should not allow an empty exclusion pattern', async () => {
it('should reject duplicate exclusion patterns', async () => {
const { status, body } = await request(server)
.put(`/library/${library.id}`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ exclusionPatterns: ['**/*.jpg', '**/*.jpg'] });

expect(status).toBe(400);
expect(body).toEqual(errorStub.badRequest(["All exclusionPatterns's elements must be unique"]));
});

it('should reject an empty exclusion pattern', async () => {
const { status, body } = await request(server)
.put(`/library/${library.id}`)
.set('Authorization', `Bearer ${admin.accessToken}`)
Expand Down
6 changes: 5 additions & 1 deletion server/src/domain/library/library.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LibraryEntity, LibraryType } from '@app/infra/entities';
import { ApiProperty } from '@nestjs/swagger';
import { IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { ArrayUnique, IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { ValidateUUID } from '../domain.util';

export class CreateLibraryDto {
Expand All @@ -20,11 +20,13 @@ export class CreateLibraryDto {
@IsOptional()
@IsString({ each: true })
@IsNotEmpty({ each: true })
@ArrayUnique()
importPaths?: string[];

@IsOptional()
@IsString({ each: true })
@IsNotEmpty({ each: true })
@ArrayUnique()
exclusionPatterns?: string[];

@IsOptional()
Expand All @@ -45,11 +47,13 @@ export class UpdateLibraryDto {
@IsOptional()
@IsString({ each: true })
@IsNotEmpty({ each: true })
@ArrayUnique()
importPaths?: string[];

@IsOptional()
@IsNotEmpty({ each: true })
@IsString({ each: true })
@ArrayUnique()
exclusionPatterns?: string[];
}

Expand Down
Loading