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

Loading…
Cancel
Save