]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add validation for snmp v3 engine id 45052/head
authorAvan Thakkar <athakkar@redhat.com>
Tue, 15 Feb 2022 13:13:36 +0000 (18:43 +0530)
committerAvan Thakkar <athakkar@redhat.com>
Wed, 16 Feb 2022 10:09:27 +0000 (15:39 +0530)
Fixes: https://tracker.ceph.com/issues/54270
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
(cherry picked from commit 2866db1eac7d726201f5bb34abdb32981c783f0e)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts

index 24dac8871f740a4fab1a607794d51b3457a8c485..22b401ec86a61f85298f59628350474697e80ad2 100644 (file)
@@ -84,7 +84,8 @@
         </div>
 
         <!-- unmanaged -->
-        <div class="form-group row">
+        <div class="form-group row"
+             *ngIf="serviceForm.controls.service_type.value !== 'snmp-gateway'">
           <div class="cd-col-form-offset">
             <div class="custom-control custom-checkbox">
               <input class="custom-control-input"
               <span class="invalid-feedback"
                     *ngIf="serviceForm.showError('engine_id', frm, 'required')"
                     i18n>This field is required.</span>
+              <span class="invalid-feedback"
+                    *ngIf="serviceForm.showError('engine_id', frm, 'snmpEngineIdPattern')"
+                    i18n>The value does not match the pattern: <strong>Must be in hexadecimal and length must be multiple of 2 with min value = 10 amd max value = 64.</strong></span>
             </div>
           </div>
           <!-- Auth protocol for snmp V3 -->
index 3cc921403f9bc30e807f5cd81ce7326da02d9a57..b85ff3f7a23e561314873c3ab579f933084f17af 100644 (file)
@@ -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', () => {
index d45d939d587128367131b00a7302a21c7dbdfe4f..ac4eec308f87971fdd01218fba95b2564cff78e4 100644 (file)
@@ -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' }
           })
         ]
       ]