2017-09-01 16:42:46 +00:00
|
|
|
import { size, some } from 'lodash';
|
2016-12-23 18:40:16 +00:00
|
|
|
|
2017-01-24 22:19:43 +00:00
|
|
|
import APP_CONSTANTS from 'app_constants';
|
|
|
|
|
|
|
|
|
|
const { APP_SETTINGS } = APP_CONSTANTS;
|
|
|
|
|
|
2016-12-23 18:40:16 +00:00
|
|
|
export default (formData) => {
|
|
|
|
|
const errors = {};
|
|
|
|
|
const {
|
|
|
|
|
authentication_type: authType,
|
|
|
|
|
kolide_server_url: kolideServerUrl,
|
2017-01-06 00:41:32 +00:00
|
|
|
org_name: orgName,
|
|
|
|
|
password: smtpPassword,
|
2016-12-23 18:40:16 +00:00
|
|
|
sender_address: smtpSenderAddress,
|
|
|
|
|
server: smtpServer,
|
2017-01-11 02:00:46 +00:00
|
|
|
port: smtpServerPort,
|
2016-12-23 18:40:16 +00:00
|
|
|
user_name: smtpUserName,
|
2017-05-17 15:58:40 +00:00
|
|
|
enable_sso: enableSSO,
|
|
|
|
|
metadata,
|
|
|
|
|
metadata_url: metadataURL,
|
|
|
|
|
entity_id: entityID,
|
|
|
|
|
idp_name: idpName,
|
2016-12-23 18:40:16 +00:00
|
|
|
} = formData;
|
|
|
|
|
|
2017-05-17 15:58:40 +00:00
|
|
|
if (enableSSO) {
|
|
|
|
|
if (!metadata && !metadataURL) {
|
|
|
|
|
errors.metadata_url = 'Metadata URL must be present';
|
|
|
|
|
}
|
|
|
|
|
if (!entityID) {
|
|
|
|
|
errors.entity_id = 'Entity ID must be present';
|
|
|
|
|
}
|
|
|
|
|
if (!idpName) {
|
|
|
|
|
errors.idp_name = 'Identity Provider Name must be present';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 18:40:16 +00:00
|
|
|
if (!kolideServerUrl) {
|
|
|
|
|
errors.kolide_server_url = 'Kolide Server URL must be present';
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 00:41:32 +00:00
|
|
|
if (!orgName) {
|
|
|
|
|
errors.org_name = 'Organization Name must be present';
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-30 03:29:08 +00:00
|
|
|
if (some([smtpSenderAddress, smtpServer, smtpUserName]) ||
|
|
|
|
|
(smtpPassword && smtpPassword !== APP_SETTINGS.FAKE_PASSWORD) ||
|
|
|
|
|
(smtpServerPort !== APP_SETTINGS.DEFAULT_SMTP_PORT)) {
|
2016-12-23 18:40:16 +00:00
|
|
|
if (!smtpSenderAddress) {
|
|
|
|
|
errors.sender_address = 'SMTP Sender Address must be present';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!smtpServer) {
|
|
|
|
|
errors.server = 'SMTP Server must be present';
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 02:00:46 +00:00
|
|
|
if (!smtpServerPort) {
|
|
|
|
|
errors.server = 'SMTP Server Port must be present';
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 18:40:16 +00:00
|
|
|
if (authType !== 'authtype_none') {
|
|
|
|
|
if (!smtpUserName) {
|
|
|
|
|
errors.user_name = 'SMTP Username must be present';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!smtpPassword) {
|
|
|
|
|
errors.password = 'SMTP Password must be present';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const valid = !size(errors);
|
|
|
|
|
|
|
|
|
|
return { valid, errors };
|
|
|
|
|
};
|