Repository: ambari Updated Branches: refs/heads/trunk 70c4f7096 -> d627c66d6
AMBARI-15630. Email fields validation should not be used in the SNMP notifications (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d627c66d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d627c66d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d627c66d Branch: refs/heads/trunk Commit: d627c66d69cb2a17025c4516f57bddd05e1c5dc7 Parents: 70c4f70 Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Wed Mar 30 16:56:36 2016 +0300 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Wed Mar 30 17:22:17 2016 +0300 ---------------------------------------------------------------------- .../manage_alert_notifications_controller.js | 20 +++-- ambari-web/app/utils/validator.js | 10 --- ...anage_alert_notifications_controller_test.js | 93 ++++++++++++++++++-- 3 files changed, 99 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d627c66d/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js index 2ec9420..6ce36ec 100644 --- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js +++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js @@ -511,10 +511,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ smtpUsernameValidation: function () { var smtpUsernameError = false; var errorMessage = null; - if (this.get('controller.inputFields.SMTPUseAuthentication.value')) { - if (validator.isEmptyOrSpaces(this.get('controller.inputFields.SMTPUsername.value'))) { - smtpUsernameError = true; - errorMessage = Em.I18n.t('alerts.notifications.error.SMTPUsername'); + if(this.get('isEmailMethodSelected')) { + if (this.get('controller.inputFields.SMTPUseAuthentication.value')) { + if (Em.isBlank(this.get('controller.inputFields.SMTPUsername.value'))) { + smtpUsernameError = true; + errorMessage = Em.I18n.t('alerts.notifications.error.SMTPUsername'); + } } } this.set('smtpUsernameError', smtpUsernameError); @@ -524,10 +526,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ smtpPasswordValidation: function () { var smtpPasswordError = false; var errorMessage = null; - if (this.get('controller.inputFields.SMTPUseAuthentication.value')) { - if (validator.isEmptyOrSpaces(this.get('controller.inputFields.SMTPPassword.value'))) { - smtpPasswordError = true; - errorMessage = Em.I18n.t('alerts.notifications.error.SMTPPassword'); + if(this.get('isEmailMethodSelected')) { + if (this.get('controller.inputFields.SMTPUseAuthentication.value')) { + if (Em.isBlank(this.get('controller.inputFields.SMTPPassword.value'))) { + smtpPasswordError = true; + errorMessage = Em.I18n.t('alerts.notifications.error.SMTPPassword'); + } } } this.set('smtpPasswordError', smtpPasswordError); http://git-wip-us.apache.org/repos/asf/ambari/blob/d627c66d/ambari-web/app/utils/validator.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/validator.js b/ambari-web/app/utils/validator.js index 1d07403..6426163 100644 --- a/ambari-web/app/utils/validator.js +++ b/ambari-web/app/utils/validator.js @@ -282,15 +282,5 @@ module.exports = { var remotePattern = /^(?:(?:https?|ftp):\/{2})(?:\S+(?::\S*)?@)?(?:(?:(?:[\w\-.]))*)(?::[0-9]+)?(?:\/\S*)?$/, localPattern = /^file:\/{2,3}([a-zA-Z][:|]\/){0,1}[\w~!*'();@&=\/\\\-+$,?%#.\[\]]+$/; return remotePattern.test(value) || localPattern.test(value); - }, - - /** - * Validate if empty or has white spaces - * @param value - * @return {boolean} - */ - isEmptyOrSpaces: function(value) { - var regex = /(\s+)/; - return (!value || regex.test(value)); } }; http://git-wip-us.apache.org/repos/asf/ambari/blob/d627c66d/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js index cbcd778..57f799f 100644 --- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js +++ b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js @@ -25,6 +25,75 @@ require('templates/main/alerts/alert_instance/status'); function getController() { return App.ManageAlertNotificationsController.create({}); } + +function getInputFields() { + return Em.Object.create({ + name: { + value: '' + }, + groups: { + value: [] + }, + global: { + value: false + }, + allGroups: { + value: false + }, + method: { + value: '' + }, + email: { + value: '' + }, + severityFilter: { + value: [] + }, + description: { + value: '' + }, + SMTPServer: { + value: '' + }, + SMTPPort: { + value: '' + }, + SMTPUseAuthentication: { + value: '' + }, + SMTPUsername: { + value: '' + }, + SMTPPassword: { + value: '' + }, + retypeSMTPPassword: { + value: '' + }, + SMTPSTARTTLS: { + value: '' + }, + emailFrom: { + value: '' + }, + version: { + value: '' + }, + OIDs: { + value: '' + }, + community: { + value: '' + }, + host: { + value: '' + }, + port: { + value: '' + } + }); +} + var createEditPopupView = getController().showCreateEditPopup(); describe('App.ManageAlertNotificationsController', function () { @@ -610,6 +679,12 @@ describe('App.ManageAlertNotificationsController', function () { describe('#smtpUsernameValidation', function () { + beforeEach(function () { + view.set('controller.inputFields', getInputFields()); + view.set('controller.inputFields.emailFrom.value', '1...@2.com'); + view.set('controller.inputFields.method.value', 'EMAIL'); + }); + it('should check inputFields.SMTPUsername.value', function () { view.set('parentView.hasErrors', false); @@ -619,7 +694,7 @@ describe('App.ManageAlertNotificationsController', function () { view.set('controller.inputFields.SMTPPassword.value', 'pass'); view.set('controller.inputFields.retypeSMTPPassword.value', 'pass'); expect(view.get('controller.inputFields.SMTPUsername.errorMsg')).to.equal(Em.I18n.t('alerts.notifications.error.SMTPUsername')); - expect(view.get('parentView.hasErrors')).to.be.true; + expect(view.get('smtpUsernameError')).to.be.true; }); @@ -632,7 +707,7 @@ describe('App.ManageAlertNotificationsController', function () { view.set('controller.inputFields.SMTPPassword.value', 'pass'); view.set('controller.inputFields.retypeSMTPPassword.value', 'pass'); expect(view.get('controller.inputFields.SMTPUsername.errorMsg')).to.equal(null); - expect(view.get('parentView.hasErrors')).to.be.false; + expect(view.get('smtpUsernameError')).to.be.false; }); @@ -645,7 +720,7 @@ describe('App.ManageAlertNotificationsController', function () { view.set('controller.inputFields.SMTPPassword.value', ''); view.set('controller.inputFields.retypeSMTPPassword.value', ''); expect(view.get('controller.inputFields.SMTPUsername.errorMsg')).to.equal(null); - expect(view.get('parentView.hasErrors')).to.be.false; + expect(view.get('smtpUsernameError')).to.be.false; }); @@ -653,6 +728,12 @@ describe('App.ManageAlertNotificationsController', function () { describe('#smtpPasswordValidation', function () { + beforeEach(function () { + view.set('controller.inputFields', getInputFields()); + view.set('controller.inputFields.emailFrom.value', '1...@2.com'); + view.set('controller.inputFields.method.value', 'EMAIL'); + }); + it('should check inputFields.SMTPPassword.value', function () { view.set('parentView.hasErrors', false); @@ -662,7 +743,7 @@ describe('App.ManageAlertNotificationsController', function () { view.set('controller.inputFields.SMTPPassword.value', ''); view.set('controller.inputFields.retypeSMTPPassword.value', ''); expect(view.get('controller.inputFields.SMTPPassword.errorMsg')).to.equal(Em.I18n.t('alerts.notifications.error.SMTPPassword')); - expect(view.get('parentView.hasErrors')).to.be.true; + expect(view.get('smtpPasswordError')).to.be.true; }); @@ -675,7 +756,7 @@ describe('App.ManageAlertNotificationsController', function () { view.set('controller.inputFields.SMTPPassword.value', 'test'); view.set('controller.inputFields.retypeSMTPPassword.value', 'test'); expect(view.get('controller.inputFields.SMTPPassword.errorMsg')).to.equal(null); - expect(view.get('parentView.hasErrors')).to.be.false; + expect(view.get('smtpPasswordError')).to.be.false; }); @@ -688,7 +769,7 @@ describe('App.ManageAlertNotificationsController', function () { view.set('controller.inputFields.SMTPPassword.value', ''); view.set('controller.inputFields.retypeSMTPPassword.value', ''); expect(view.get('controller.inputFields.SMTPPassword.errorMsg')).to.equal(null); - expect(view.get('parentView.hasErrors')).to.be.false; + expect(view.get('smtpPasswordError')).to.be.false; });