Skip to content

Commit

Permalink
mgr/dashboard: add snmp destination validation
Browse files Browse the repository at this point in the history
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
  • Loading branch information
avanthakkar committed Jan 28, 2022
1 parent ad6fcfc commit 81c93a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Expand Up @@ -464,6 +464,9 @@
<span class="invalid-feedback"
*ngIf="serviceForm.showError('snmp_destination', frm, 'required')"
i18n>This field is required.</span>
<span class="invalid-feedback"
*ngIf="serviceForm.showError('snmp_destination', frm, 'snmpDestinationPattern')"
i18n>The value does not match the pattern: <strong>hostname:port</strong></span>
</div>
</div>
<!-- Engine id for snmp V3 -->
Expand Down
Expand Up @@ -484,6 +484,12 @@ 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');
});
});

describe('check edit fields', () => {
Expand Down
Expand Up @@ -28,6 +28,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]/;
@ViewChild(NgbTypeahead, { static: false })
typeahead: NgbTypeahead;

Expand Down Expand Up @@ -217,12 +218,20 @@ export class ServiceFormComponent extends CdForm implements OnInit {
snmp_version: [null, [Validators.required]],
snmp_destination: [
null,
[
CdValidators.requiredIf({
service_type: 'snmp-gateway',
unmanaged: false
})
]
{
validators: [
CdValidators.requiredIf({
service_type: 'snmp-gateway',
unmanaged: false
}),
CdValidators.custom('snmpDestinationPattern', (value: string) => {
if (_.isEmpty(value)) {
return false;
}
return !this.SNMP_DESTINATION_PATTERN.test(value);
})
]
}
],
engine_id: [
null,
Expand Down

0 comments on commit 81c93a2

Please sign in to comment.