fix(striker-ui-api): move uuid assert for update mail server

main
Tsu-ba-me 11 months ago
parent 9f1c2dd2c3
commit 22fa465f1b
  1. 7
      striker-ui-api/src/lib/request_handlers/mail-server/getMailServerRequestBody.ts
  2. 7
      striker-ui-api/src/lib/request_handlers/mail-server/updateMailServer.ts

@ -1,9 +1,12 @@
import assert from 'assert'; import assert from 'assert';
import { REP_UUID } from '../../consts';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
export const getMailServerRequestBody = ( export const getMailServerRequestBody = (
body: Partial<MailServerRequestBody>, body: Partial<MailServerRequestBody>,
uuid?: string,
): MailServerRequestBody => { ): MailServerRequestBody => {
const { const {
address: rAddress, address: rAddress,
@ -25,6 +28,10 @@ export const getMailServerRequestBody = (
const security = sanitize(rSecurity, 'string', { fallback: 'none' }); const security = sanitize(rSecurity, 'string', { fallback: 'none' });
const username = sanitize(rUsername, 'string'); const username = sanitize(rUsername, 'string');
if (uuid) {
assert(REP_UUID.test(uuid), `Expected valid UUIDv4; got [${uuid}]`);
}
assert.ok(address.length, `Expected address; got [${address}]`); assert.ok(address.length, `Expected address; got [${address}]`);
assert( assert(

@ -1,8 +1,5 @@
import assert from 'assert';
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { REP_UUID } from '../../consts';
import { execManageAlerts } from '../../execManageAlerts'; import { execManageAlerts } from '../../execManageAlerts';
import { getMailServerRequestBody } from './getMailServerRequestBody'; import { getMailServerRequestBody } from './getMailServerRequestBody';
import { stderr, stdout } from '../../shell'; import { stderr, stdout } from '../../shell';
@ -22,9 +19,7 @@ export const updateMailServer: RequestHandler<
let body: MailServerRequestBody; let body: MailServerRequestBody;
try { try {
assert(REP_UUID.test(uuid), `Expected valid UUIDv4; got [${uuid}]`); body = getMailServerRequestBody(rBody, uuid);
body = getMailServerRequestBody(rBody);
} catch (error) { } catch (error) {
stderr(`Failed to process mail server input; CAUSE: ${error}`); stderr(`Failed to process mail server input; CAUSE: ${error}`);

Loading…
Cancel
Save