From: Avan Thakkar Date: Tue, 15 Feb 2022 13:13:36 +0000 (+0530) Subject: mgr/dashboard: add validation for snmp v3 engine id X-Git-Tag: v16.2.8~195^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2867c323b8b65343889c6bb187c11c7c417e264c;p=ceph.git mgr/dashboard: add validation for snmp v3 engine id Fixes: https://tracker.ceph.com/issues/54270 Signed-off-by: Avan Thakkar (cherry picked from commit 2866db1eac7d726201f5bb34abdb32981c783f0e) --- 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 24dac8871f74..22b401ec86a6 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 3cc921403f9b..b85ff3f7a23e 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 d45d939d5871..ac4eec308f87 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' } }) ] ]