diff --git a/package.json b/package.json index 2b7cb95df..8a0daed8d 100644 --- a/package.json +++ b/package.json @@ -131,4 +131,4 @@ "smart home", "hb-service" ] -} +} \ No newline at end of file diff --git a/test/e2e/app.e2e-spec.ts b/test/e2e/app.e2e-spec.ts index 1e1567ac7..50e34c8c1 100644 --- a/test/e2e/app.e2e-spec.ts +++ b/test/e2e/app.e2e-spec.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import * as fs from 'fs-extra'; import { Test, TestingModule } from '@nestjs/testing'; +import { ValidationPipe } from '@nestjs/common'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AppModule } from '../../src/app.module'; @@ -30,6 +31,12 @@ describe('AppController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); }); diff --git a/test/e2e/auth.e2e-spec.ts b/test/e2e/auth.e2e-spec.ts index 1917ff886..590537924 100644 --- a/test/e2e/auth.e2e-spec.ts +++ b/test/e2e/auth.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -31,6 +32,12 @@ describe('AuthController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); diff --git a/test/e2e/backup.e2e-spec.ts b/test/e2e/backup.e2e-spec.ts index 56c08f081..1133c1b1d 100644 --- a/test/e2e/backup.e2e-spec.ts +++ b/test/e2e/backup.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -35,6 +36,12 @@ describe('BackupController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); diff --git a/test/e2e/config-editor.e2e-spec.ts b/test/e2e/config-editor.e2e-spec.ts index 320f6d960..0c7d2c402 100644 --- a/test/e2e/config-editor.e2e-spec.ts +++ b/test/e2e/config-editor.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -35,6 +36,12 @@ describe('ConfigEditorController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); }); diff --git a/test/e2e/fastify.e2e-spec.ts b/test/e2e/fastify.e2e-spec.ts new file mode 100644 index 000000000..1eacb43f6 --- /dev/null +++ b/test/e2e/fastify.e2e-spec.ts @@ -0,0 +1,77 @@ +import * as path from 'path'; +import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; +import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; +import * as fastify from 'fastify'; +import * as fastifyMultipart from 'fastify-multipart'; +import * as helmet from 'helmet'; +import { AppModule } from '../../src/app.module'; + +describe('FastifyOptions (e2e)', () => { + let app: NestFastifyApplication; + + let authFilePath: string; + let secretsFilePath: string; + + beforeAll(async () => { + process.env.UIX_BASE_PATH = path.resolve(__dirname, '../../'); + process.env.UIX_STORAGE_PATH = path.resolve(__dirname, '../', '.homebridge'); + process.env.UIX_CONFIG_PATH = path.resolve(process.env.UIX_STORAGE_PATH, 'config.json'); + + authFilePath = path.resolve(process.env.UIX_STORAGE_PATH, 'auth.json'); + secretsFilePath = path.resolve(process.env.UIX_STORAGE_PATH, '.uix-secrets'); + + // setup test config + await fs.copy(path.resolve(__dirname, '../mocks', 'config.json'), process.env.UIX_CONFIG_PATH); + + // setup test auth file + await fs.copy(path.resolve(__dirname, '../mocks', 'auth.json'), authFilePath); + await fs.copy(path.resolve(__dirname, '../mocks', '.uix-secrets'), secretsFilePath); + + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + // setup fastify + const server = fastify({ + logger: { + prettyPrint: true, + }, + }); + + const fAdapter = new FastifyAdapter(server); + + fAdapter.register(fastifyMultipart, { + limits: { + files: 1, + }, + }); + + app = moduleFixture.createNestApplication(fAdapter); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + + app.use(helmet()); + + await app.init(); + await app.getHttpAdapter().getInstance().ready(); + }); + + it('GET /', async () => { + const res = await app.inject({ + method: 'GET', + path: '/' + }); + + expect(res.statusCode).toEqual(200); + expect(res.body).toEqual('Hello World!'); + }); + + afterAll(async () => { + await app.close(); + }); +}); \ No newline at end of file diff --git a/test/e2e/platform-tools-docker.e2e-spec.ts b/test/e2e/platform-tools-docker.e2e-spec.ts index 151bda2ac..51d0bba7d 100644 --- a/test/e2e/platform-tools-docker.e2e-spec.ts +++ b/test/e2e/platform-tools-docker.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -37,6 +38,12 @@ describe('PlatformToolsDocker (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); diff --git a/test/e2e/platform-tools-hb-service.e2e-spec.ts b/test/e2e/platform-tools-hb-service.e2e-spec.ts index f5fcd73c9..9ecca16a2 100644 --- a/test/e2e/platform-tools-hb-service.e2e-spec.ts +++ b/test/e2e/platform-tools-hb-service.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -38,6 +39,12 @@ describe('PlatformToolsHbService (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); diff --git a/test/e2e/platform-tools-linux.e2e-spec.ts b/test/e2e/platform-tools-linux.e2e-spec.ts index e6c9ba2f2..4de6ecc8e 100644 --- a/test/e2e/platform-tools-linux.e2e-spec.ts +++ b/test/e2e/platform-tools-linux.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -36,6 +37,12 @@ describe('PlatformToolsLinux (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); diff --git a/test/e2e/plugins.e2e-spec.ts b/test/e2e/plugins.e2e-spec.ts index 7295862d9..aea6b34e2 100644 --- a/test/e2e/plugins.e2e-spec.ts +++ b/test/e2e/plugins.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -39,6 +40,12 @@ describe('PluginController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); }); diff --git a/test/e2e/server.e2e-spec.ts b/test/e2e/server.e2e-spec.ts index e73c5cbdf..3b78bf17e 100644 --- a/test/e2e/server.e2e-spec.ts +++ b/test/e2e/server.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { AuthModule } from '../../src/core/auth/auth.module'; @@ -40,6 +41,12 @@ describe('ServerController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); diff --git a/test/e2e/status.e2e-spec.ts b/test/e2e/status.e2e-spec.ts index f82452826..129da9b34 100644 --- a/test/e2e/status.e2e-spec.ts +++ b/test/e2e/status.e2e-spec.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs-extra'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { StatusModule } from '../../src/modules/status/status.module'; @@ -32,6 +33,12 @@ describe('StatusController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); }); diff --git a/test/e2e/users.e2e-spec.ts b/test/e2e/users.e2e-spec.ts index 8720b89e5..f276ecab7 100644 --- a/test/e2e/users.e2e-spec.ts +++ b/test/e2e/users.e2e-spec.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import * as fs from 'fs-extra'; import { authenticator } from 'otplib'; +import { ValidationPipe } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { UsersModule } from '../../src/modules/users/users.module'; @@ -33,6 +34,12 @@ describe('UsersController (e2e)', () => { }).compile(); app = moduleFixture.createNestApplication(new FastifyAdapter()); + + app.useGlobalPipes(new ValidationPipe({ + whitelist: true, + skipMissingProperties: true, + })); + await app.init(); await app.getHttpAdapter().getInstance().ready(); });