diff --git a/.eslintrc.js b/.eslintrc.js index 6f8d841b..59c91b77 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,7 +24,7 @@ module.exports = { 'linebreak-style': ['error', 'unix'], 'prefer-const': 'error', 'prettier/prettier': 'error', - '@typescript-eslint/no-unused-vars': ['error'], + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], curly: [2, 'all'], }, } diff --git a/jest.config.js b/jest.config.js index e3812aa4..ca8424b7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,11 +7,13 @@ module.exports = { collectCoverageFrom: [ './proxy/**/**.ts', './management/**/**.ts', + './proxy/handlers/status.ts', '!**/index.ts', - '!**/errors/**', '!**/config.ts', '!**/env.ts', '!**/handlers/**', + '!**/proxy/app.ts', + '!**/management/app.ts', ], coverageReporters: ['lcov', 'json-summary', ['text', { file: 'coverage.txt', path: './' }]], transform: { diff --git a/proxy/errors/integrarionError.test.ts b/proxy/errors/integrarionError.test.ts new file mode 100644 index 00000000..394d9a9c --- /dev/null +++ b/proxy/errors/integrarionError.test.ts @@ -0,0 +1,16 @@ +import { IntegrationError } from './IntegrationError' + +describe('check integration error result', () => { + it('check if error return valid body', async () => { + const json = { + vendor: 'Fingerprint Pro Azure Function', + message: 'Download failed', + path: 'fpjs/agent', + } + + const message: IntegrationError = new IntegrationError(json.message, json.path) + const body = message.toBody() + + expect(body).toBe(JSON.stringify(json)) + }) +}) diff --git a/proxy/handlers/status.test.ts b/proxy/handlers/status.test.ts new file mode 100644 index 00000000..ae66b961 --- /dev/null +++ b/proxy/handlers/status.test.ts @@ -0,0 +1,162 @@ +import { CustomerVariables } from '../customer-variables/CustomerVariables' +import { CustomerVariableType } from '../customer-variables/types' +import { EnvCustomerVariables } from '../customer-variables/EnvCustomerVariables' +import { handleStatus } from './status' +import { HttpRequest, Form, FormPart } from '@azure/functions' + +const fp: FormPart = { + value: Buffer.from(''), +} +const form: Form = { + get: (_: string) => fp, + getAll: (_: string) => [fp], + has: (_: string) => true, + length: 0, + *[Symbol.iterator]() {}, +} +const req: HttpRequest = { + method: 'GET', + url: 'https://fp.domain.com/fpjs/status', + headers: {}, + query: {}, + params: {}, + user: null, + get: (x) => x, + parseFormBody: () => form, +} + +function removeNonce(body: string): string { + const nonceParam = " nonce='" + const begin = body.indexOf(nonceParam) + const end = body.indexOf("'", begin + nonceParam.length) + 1 + + return body.replace(body.substring(begin, end), '') +} + +describe('Handle status', () => { + it('returns correct status info in html if all variables are set', async () => { + const getHeaderCustomerVariables = (env: typeof process.env) => + new CustomerVariables([new EnvCustomerVariables(env)]) + const env = { + [CustomerVariableType.AgentDownloadPath]: 'qwertyt', + [CustomerVariableType.RoutePrefix]: 'dsgfkjdfs', + [CustomerVariableType.GetResultPath]: 'fdgvdsfgfds', + [CustomerVariableType.PreSharedSecret]: 'aadddddd', + } + const customerVariables = getHeaderCustomerVariables(env) + + const result = await handleStatus({ + httpRequest: req, + customerVariables: customerVariables, + }) + + expect(removeNonce(result.body)).toMatchInlineSnapshot(` + " + + + Fingerprint Pro Azure integration status + + + + +

Fingerprint Pro Azure integration status

+
+ Fingerprint Pro Azure Function App version: __azure_function_version__ +
+ +
+ ✅ All environment variables are set +
+ + + Please reach out our support via support@fingerprint.com if you have any issues + + + + " + `) + }) + + it('returns correct status info in html if some variables are using default values', async () => { + const getHeaderCustomerVariables = (env: typeof process.env) => + new CustomerVariables([new EnvCustomerVariables(env)]) + const customerVariables = getHeaderCustomerVariables({}) + + const result = await handleStatus({ + httpRequest: req, + customerVariables: customerVariables, + }) + + expect(removeNonce(result.body)).toMatchInlineSnapshot(` + " + + + Fingerprint Pro Azure integration status + + + + +

Fingerprint Pro Azure integration status

+
+ Fingerprint Pro Azure Function App version: __azure_function_version__ +
+ +
+ +
+ ⚠️ fpjs_route_prefix is not defined and uses default value +
+
+ ⚠️ fpjs_get_result_path is not defined and uses default value +
+
+ ⚠️ fpjs_pre_shared_secret is not defined +
+
+ ⚠️ fpjs_agent_download_path is not defined and uses default value +
+
+ + + Please reach out our support via support@fingerprint.com if you have any issues + + + + " + `) + }) +}) diff --git a/proxy/handlers/status.ts b/proxy/handlers/status.ts index 14b8c39b..c2bc73fa 100644 --- a/proxy/handlers/status.ts +++ b/proxy/handlers/status.ts @@ -66,16 +66,16 @@ function renderHtml({ version, envInfo }: StatusInfo) { body, .env-info { display: flex; } - + .env-info { flex-direction: column; } - + body { flex-direction: column; align-items: center; } - + body > * { margin-bottom: 1em; }