From 2866db1eac7d726201f5bb34abdb32981c783f0e Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Tue, 15 Feb 2022 18:43:36 +0530 Subject: [PATCH] mgr/dashboard: add validation for snmp v3 engine id Fixes: https://tracker.ceph.com/issues/54270 Signed-off-by: Avan Thakkar --- .../service-form/service-form.component.html | 6 +++- .../service-form.component.spec.ts | 14 +++++++++ .../service-form/service-form.component.ts | 31 +++++++++---------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 24dac8871f740..22b401ec86a61 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -84,7 +84,8 @@ -
+
This field is required. + The value does not match the pattern: Must be in hexadecimal and length must be multiple of 2 with min value = 10 amd max value = 64.
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts index 3cc921403f9bc..b85ff3f7a23e5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts @@ -459,6 +459,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== } }); }); + it('should test snmp-gateway service with V3', () => { formHelper.setValue('snmp_version', 'V3'); formHelper.setValue('engine_id', '800C53F00000'); @@ -484,12 +485,25 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== } }); }); + it('should submit invalid snmp destination', () => { formHelper.setValue('snmp_version', 'V2c'); formHelper.setValue('snmp_destination', '192.168.20.1'); formHelper.setValue('snmp_community', 'public'); formHelper.expectError('snmp_destination', 'snmpDestinationPattern'); }); + + it('should submit invalid snmp engine id', () => { + formHelper.setValue('snmp_version', 'V3'); + formHelper.setValue('snmp_destination', '192.168.20.1'); + formHelper.setValue('engine_id', 'AABBCCDDE'); + formHelper.setValue('auth_protocol', 'SHA'); + formHelper.setValue('privacy_protocol', 'DES'); + formHelper.setValue('snmp_v3_auth_username', 'testuser'); + formHelper.setValue('snmp_v3_auth_password', 'testpass'); + + formHelper.expectError('engine_id', 'snmpEngineIdPattern'); + }); }); describe('check edit fields', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts index d45d939d58712..ac4eec308f879 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts @@ -29,6 +29,7 @@ import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; export class ServiceFormComponent extends CdForm implements OnInit { readonly RGW_SVC_ID_PATTERN = /^([^.]+)(\.([^.]+)\.([^.]+))?$/; readonly SNMP_DESTINATION_PATTERN = /^[^\:]+:[0-9]/; + readonly SNMP_ENGINE_ID_PATTERN = /^[0-9A-Fa-f]{10,64}/g; @ViewChild(NgbTypeahead, { static: false }) typeahead: NgbTypeahead; @@ -219,8 +220,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { null, [ CdValidators.requiredIf({ - service_type: 'snmp-gateway', - unmanaged: false + service_type: 'snmp-gateway' }) ] ], @@ -229,8 +229,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { { validators: [ CdValidators.requiredIf({ - service_type: 'snmp-gateway', - unmanaged: false + service_type: 'snmp-gateway' }), CdValidators.custom('snmpDestinationPattern', (value: string) => { if (_.isEmpty(value)) { @@ -245,8 +244,13 @@ export class ServiceFormComponent extends CdForm implements OnInit { null, [ CdValidators.requiredIf({ - snmp_version: 'V3', - unmanaged: false + service_type: 'snmp-gateway' + }), + CdValidators.custom('snmpEngineIdPattern', (value: string) => { + if (_.isEmpty(value)) { + return false; + } + return !this.SNMP_ENGINE_ID_PATTERN.test(value); }) ] ], @@ -254,8 +258,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { 'SHA', [ CdValidators.requiredIf({ - snmp_version: 'V3', - unmanaged: false + service_type: 'snmp-gateway' }) ] ], @@ -264,8 +267,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { null, [ CdValidators.requiredIf({ - snmp_version: 'V2c', - unmanaged: false + snmp_version: 'V2c' }) ] ], @@ -273,8 +275,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { null, [ CdValidators.requiredIf({ - snmp_version: 'V3', - unmanaged: false + service_type: 'snmp-gateway' }) ] ], @@ -282,8 +283,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { null, [ CdValidators.requiredIf({ - snmp_version: 'V3', - unmanaged: false + service_type: 'snmp-gateway' }) ] ], @@ -291,8 +291,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { null, [ CdValidators.requiredIf({ - privacy_protocol: { op: '!empty' }, - unmanaged: false + privacy_protocol: { op: '!empty' } }) ] ] -- 2.39.5