From 5f52c00e5291b53b4fe9ab7f9fae5d499017f91b Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Fri, 30 Jul 2021 04:23:43 +0530 Subject: [PATCH] mgr/dashboard: fix ssl cert validation for rgw service creation Fixes: https://tracker.ceph.com/issues/51965 Signed-off-by: Avan Thakkar --- .../service-form/service-form.component.spec.ts | 17 +++++++++++++++++ .../service-form/service-form.component.ts | 2 +- .../src/app/shared/forms/cd-validators.ts | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) 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, -- 2.39.5