Allow update of settings page without enabling SMTP (#1903)
Fixes #1871
This commit is contained in:
@@ -24,7 +24,7 @@ const formFields = [
|
||||
'authentication_method', 'authentication_type', 'domain', 'enable_ssl_tls', 'enable_start_tls',
|
||||
'kolide_server_url', 'org_logo_url', 'org_name', 'osquery_enroll_secret', 'password',
|
||||
'port', 'sender_address', 'server', 'user_name', 'verify_ssl_certs', 'idp_name', 'entity_id',
|
||||
'issuer_uri', 'idp_image_url', 'metadata', 'metadata_url', 'enable_sso',
|
||||
'issuer_uri', 'idp_image_url', 'metadata', 'metadata_url', 'enable_sso', 'enable_smtp',
|
||||
];
|
||||
const Header = ({ showAdvancedOptions }) => {
|
||||
const CaratIcon = <Icon name={showAdvancedOptions ? 'downcarat' : 'upcarat'} />;
|
||||
@@ -58,6 +58,7 @@ class AppConfigForm extends Component {
|
||||
metadata_url: formFieldInterface.isRequired,
|
||||
idp_name: formFieldInterface.isRequired,
|
||||
enable_sso: formFieldInterface.isRequired,
|
||||
enable_smtp: formFieldInterface.isRequired,
|
||||
}).isRequired,
|
||||
handleSubmit: PropTypes.func.isRequired,
|
||||
smtpConfigured: PropTypes.bool.isRequired,
|
||||
@@ -185,6 +186,15 @@ class AppConfigForm extends Component {
|
||||
|
||||
<div className={`${baseClass}__section`}>
|
||||
<h2>SAML Single Sign On Options</h2>
|
||||
|
||||
<div className={`${baseClass}__inputs`}>
|
||||
<Checkbox
|
||||
{...fields.enable_sso}
|
||||
>
|
||||
Enable Single Sign On
|
||||
</Checkbox>
|
||||
</div>
|
||||
|
||||
<div className={`${baseClass}__inputs`}>
|
||||
<InputField
|
||||
{...fields.idp_name}
|
||||
@@ -248,18 +258,18 @@ class AppConfigForm extends Component {
|
||||
<p>A URL that references the identity provider metadata.</p>
|
||||
</div>
|
||||
|
||||
<div className={`${baseClass}__inputs`}>
|
||||
<Checkbox
|
||||
{...fields.enable_sso}
|
||||
>
|
||||
Enable Single Sign On
|
||||
</Checkbox>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div className={`${baseClass}__section`}>
|
||||
<h2>SMTP Options <small className={`smtp-options smtp-options--${smtpConfigured ? 'configured' : 'notconfigured'}`}>STATUS: <em>{smtpConfigured ? 'CONFIGURED' : 'NOT CONFIGURED'}</em></small></h2>
|
||||
<div className={`${baseClass}__inputs`}>
|
||||
<Checkbox
|
||||
{...fields.enable_smtp}
|
||||
>
|
||||
Enable SMTP
|
||||
</Checkbox>
|
||||
</div>
|
||||
|
||||
<div className={`${baseClass}__inputs`}>
|
||||
<InputField
|
||||
{...fields.sender_address}
|
||||
@@ -282,7 +292,7 @@ class AppConfigForm extends Component {
|
||||
<Checkbox
|
||||
{...fields.enable_ssl_tls}
|
||||
>
|
||||
User SSL/TLS to connect (recommended)
|
||||
Use SSL/TLS to connect (recommended)
|
||||
</Checkbox>
|
||||
</div>
|
||||
<div className={`${baseClass}__details`}>
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import { size, some } from 'lodash';
|
||||
|
||||
import APP_CONSTANTS from 'app_constants';
|
||||
|
||||
const { APP_SETTINGS } = APP_CONSTANTS;
|
||||
import { size } from 'lodash';
|
||||
|
||||
export default (formData) => {
|
||||
const errors = {};
|
||||
@@ -10,6 +6,7 @@ export default (formData) => {
|
||||
authentication_type: authType,
|
||||
kolide_server_url: kolideServerUrl,
|
||||
org_name: orgName,
|
||||
enable_smtp: enableSMTP,
|
||||
password: smtpPassword,
|
||||
sender_address: smtpSenderAddress,
|
||||
server: smtpServer,
|
||||
@@ -42,9 +39,7 @@ export default (formData) => {
|
||||
errors.org_name = 'Organization Name must be present';
|
||||
}
|
||||
|
||||
if (some([smtpSenderAddress, smtpServer, smtpUserName]) ||
|
||||
(smtpPassword && smtpPassword !== APP_SETTINGS.FAKE_PASSWORD) ||
|
||||
(smtpServerPort !== APP_SETTINGS.DEFAULT_SMTP_PORT)) {
|
||||
if (enableSMTP) {
|
||||
if (!smtpSenderAddress) {
|
||||
errors.sender_address = 'SMTP Sender Address must be present';
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ describe('AppConfigForm - validations', () => {
|
||||
authentication_type: 'username_password',
|
||||
kolide_server_url: 'https://gnar.dog',
|
||||
sender_address: 'hi@gnar.dog',
|
||||
enable_smtp: true,
|
||||
server: '192.168.99.100',
|
||||
port: '1025',
|
||||
user_name: 'gnardog',
|
||||
@@ -117,9 +118,10 @@ describe('AppConfigForm - validations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not validate smtp config if only password and port are present and they are defaults', () => {
|
||||
it('does not validate smtp config if smtp not enabled', () => {
|
||||
const formData = {
|
||||
...validFormData,
|
||||
enable_smtp: false,
|
||||
user_name: '',
|
||||
server: '',
|
||||
sender_address: '',
|
||||
|
||||
@@ -44,7 +44,6 @@ describe('Kolide - API client (config)', () => {
|
||||
authentication_method: 'authmethod_plain',
|
||||
verify_ssl_certs: true,
|
||||
enable_start_tls: true,
|
||||
email_enabled: false,
|
||||
};
|
||||
const configData = helpers.formatConfigDataForServer(formData);
|
||||
const request = configMocks.update.valid(bearerToken, configData);
|
||||
|
||||
@@ -76,8 +76,9 @@ export const formatConfigDataForServer = (config) => {
|
||||
const orgInfoAttrs = pick(config, ['org_logo_url', 'org_name']);
|
||||
const serverSettingsAttrs = pick(config, ['kolide_server_url', 'osquery_enroll_secret']);
|
||||
const smtpSettingsAttrs = pick(config, [
|
||||
'authentication_method', 'authentication_type', 'domain', 'email_enabled', 'enable_ssl_tls',
|
||||
'authentication_method', 'authentication_type', 'domain', 'enable_ssl_tls',
|
||||
'enable_start_tls', 'password', 'port', 'sender_address', 'server', 'user_name', 'verify_ssl_certs',
|
||||
'enable_smtp',
|
||||
]);
|
||||
const ssoSettingsAttrs = pick(config, ['entity_id', 'issuer_uri', 'idp_image_url', 'metadata',
|
||||
'metadata_url', 'idp_name', 'enable_sso',
|
||||
|
||||
@@ -25,6 +25,7 @@ describe('Kolide API - helpers', () => {
|
||||
kolide_server_url: '',
|
||||
configured: false,
|
||||
domain: '',
|
||||
smtp_enabled: true,
|
||||
sender_address: '',
|
||||
server: '',
|
||||
port: 587,
|
||||
@@ -35,7 +36,6 @@ describe('Kolide API - helpers', () => {
|
||||
authentication_method: 'authmethod_plain',
|
||||
verify_ssl_certs: true,
|
||||
enable_start_tls: true,
|
||||
email_enabled: false,
|
||||
};
|
||||
|
||||
it('splits config into categories for the server', () => {
|
||||
|
||||
@@ -62,7 +62,7 @@ class AppSettingsPage extends Component {
|
||||
return false;
|
||||
}
|
||||
|
||||
const formData = { ...appConfig };
|
||||
const formData = { ...appConfig, enable_smtp: smtpConfigured };
|
||||
|
||||
return (
|
||||
<div className={`${baseClass} body-wrap`}>
|
||||
|
||||
@@ -27,7 +27,6 @@ export const configStub = {
|
||||
authentication_method: 'authmethod_plain',
|
||||
verify_ssl_certs: true,
|
||||
enable_start_tls: true,
|
||||
email_enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -47,7 +46,6 @@ export const flatConfigStub = {
|
||||
authentication_method: 'authmethod_plain',
|
||||
verify_ssl_certs: true,
|
||||
enable_start_tls: true,
|
||||
email_enabled: false,
|
||||
};
|
||||
|
||||
export const hostStub = {
|
||||
|
||||
@@ -165,6 +165,9 @@ type SSOSettingsPayload struct {
|
||||
// SMTPSettingsPayload is part of the AppConfigPayload which defines the wire representation
|
||||
// of the app config endpoints
|
||||
type SMTPSettingsPayload struct {
|
||||
// SMTPEnabled indicates whether the user has selected that SMTP is
|
||||
// enabled in the UI.
|
||||
SMTPEnabled *bool `json:"enable_smtp"`
|
||||
// SMTPConfigured is a flag that indicates if smtp has been successfully
|
||||
// tested with the settings provided by an admin user.
|
||||
SMTPConfigured *bool `json:"configured"`
|
||||
|
||||
@@ -105,6 +105,7 @@ func smtpSettingsFromAppConfig(config *kolide.AppConfig) *kolide.SMTPSettingsPay
|
||||
authType := config.SMTPAuthenticationType.String()
|
||||
authMethod := config.SMTPAuthenticationMethod.String()
|
||||
return &kolide.SMTPSettingsPayload{
|
||||
SMTPEnabled: &config.SMTPConfigured,
|
||||
SMTPConfigured: &config.SMTPConfigured,
|
||||
SMTPSenderAddress: &config.SMTPSenderAddress,
|
||||
SMTPServer: &config.SMTPServer,
|
||||
|
||||
@@ -61,6 +61,7 @@ func testModifyAppConfig(t *testing.T, r *testResource) {
|
||||
}
|
||||
payload := appConfigPayloadFromAppConfig(config)
|
||||
payload.SMTPTest = new(bool)
|
||||
*payload.SMTPSettings.SMTPEnabled = true
|
||||
|
||||
var buffer bytes.Buffer
|
||||
err := json.NewEncoder(&buffer).Encode(payload)
|
||||
|
||||
@@ -84,10 +84,15 @@ func (svc service) ModifyAppConfig(ctx context.Context, p kolide.AppConfigPayloa
|
||||
config := appConfigFromAppConfigPayload(p, *oldAppConfig)
|
||||
|
||||
if p.SMTPSettings != nil {
|
||||
if err = svc.SendTestEmail(ctx, config); err != nil {
|
||||
return nil, err
|
||||
enabled := p.SMTPSettings.SMTPEnabled
|
||||
if (enabled == nil && oldAppConfig.SMTPConfigured) || (enabled != nil && *enabled) {
|
||||
if err = svc.SendTestEmail(ctx, config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.SMTPConfigured = true
|
||||
} else if enabled != nil && !*enabled {
|
||||
config.SMTPConfigured = false
|
||||
}
|
||||
config.SMTPConfigured = true
|
||||
}
|
||||
|
||||
if err := svc.ds.SaveAppConfig(config); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user