From: Avan Thakkar Date: Thu, 29 Jul 2021 22:53:43 +0000 (+0530) Subject: mgr/dashboard: fix ssl cert validation for rgw service creation X-Git-Tag: v16.2.6~111^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=df99310448c78093a3c3d49cdea7823a05c04f0c;p=ceph.git mgr/dashboard: fix ssl cert validation for rgw service creation Fixes: https://tracker.ceph.com/issues/51965 Signed-off-by: Avan Thakkar (cherry picked from commit 5f52c00e5291b53b4fe9ab7f9fae5d499017f91b) --- 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 1bcce5497cc38..1f9679dca5874 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 @@ -251,6 +251,23 @@ describe('ServiceFormComponent', () => { const ssl_key = fixture.debugElement.query(By.css('#ssl_key')); expect(ssl_key).toBeNull(); }); + + it('should test .pem file', () => { + const pemCert = ` +-----BEGIN CERTIFICATE----- +iJ5IbgzlKPssdYwuAEI3yPZxX/g5vKBrgcyD3LttLL/DlElq/1xCnwVrv7WROSNu +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +mn/S7BNBEC7AGe5ajmN+8hBTGdACUXe8rwMNrtTy/MwBZ0VpJsAAjJh+aptZh5yB +-----END CERTIFICATE----- +-----BEGIN RSA PRIVATE KEY----- +x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== +-----END RSA PRIVATE KEY-----`; + formHelper.setValue('ssl', true); + formHelper.setValue('ssl_cert', pemCert); + fixture.detectChanges(); + formHelper.expectValid('ssl_cert'); + }); }); describe('should test service iscsi', () => { 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 149ff39c40fe8..df231c7efdb25 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 @@ -185,7 +185,7 @@ export class ServiceFormComponent extends CdForm implements OnInit { unmanaged: false, ssl: true }, - [Validators.required, CdValidators.sslCert()] + [Validators.required, CdValidators.pemCert()] ), CdValidators.composeIf( { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts index b72b8f18bdcf5..53fcc747b9f2a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts @@ -103,6 +103,15 @@ export class CdValidators { ); } + /** + * Validator that performs SSL certificate validation of pem format. + * @returns {ValidatorFn} A validator function that returns an error map containing `pattern` + * if the validation check fails, otherwise `null`. + */ + static pemCert(): ValidatorFn { + return Validators.pattern(/^-----BEGIN .+-----$.+^-----END .+-----$/ms); + } + /** * Validator that requires controls to fulfill the specified condition if * the specified prerequisites matches. If the prerequisites are fulfilled,