fix(striker-ui-api): avoid blank inputs by using sanitize fallback in create host connection

main
Tsu-ba-me 1 year ago
parent 4a8f6b27dc
commit d1bc6c0ce3
  1. 20
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts

@ -18,24 +18,16 @@ export const createHostConnection: RequestHandler<
CreateHostConnectionRequestBody CreateHostConnectionRequestBody
> = async (request, response) => { > = async (request, response) => {
const { const {
body: { body: { dbName, ipAddress, isPing, password, port, sshPort, user },
dbName = 'anvil',
ipAddress,
isPing = false,
password,
port = 5432,
sshPort = 22,
user = 'root',
},
} = request; } = request;
const commonDBName = sanitize(dbName, 'string'); const commonDBName = sanitize(dbName, 'string', { fallback: 'anvil' });
const commonIsPing = sanitize(isPing, 'boolean'); const commonIsPing = sanitize(isPing, 'boolean');
const commonPassword = sanitize(password, 'string'); const commonPassword = sanitize(password, 'string');
const commonDBPort = sanitize(port, 'number'); const commonDBPort = sanitize(port, 'number', { fallback: 5432 });
const commonDBUser = sanitize(user, 'string'); const commonDBUser = sanitize(user, 'string', { fallback: 'root' });
const peerIPAddress = sanitize(ipAddress, 'string'); const peerIPAddress = sanitize(ipAddress, 'string');
const peerSSHPort = sanitize(sshPort, 'number'); const peerSSHPort = sanitize(sshPort, 'number', { fallback: 22 });
const commonPing = commonIsPing ? 1 : 0; const commonPing = commonIsPing ? 1 : 0;
@ -138,7 +130,7 @@ export const createHostConnection: RequestHandler<
`Cannot connect to peer database; please verify database credentials.`, `Cannot connect to peer database; please verify database credentials.`,
); );
return response.status(400).send(); // return response.status(400).send();
} }
const localHostUUID = getLocalHostUUID(); const localHostUUID = getLocalHostUUID();

Loading…
Cancel
Save