]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix ssl cert validation for rgw service creation 42554/head
authorAvan Thakkar <athakkar@redhat.com>
Thu, 29 Jul 2021 22:53:43 +0000 (04:23 +0530)
committerAvan Thakkar <athakkar@localhost.localdomain>
Tue, 3 Aug 2021 19:18:02 +0000 (00:48 +0530)
Fixes: https://tracker.ceph.com/issues/51965
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
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
src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-validators.ts

index 1bcce5497cc388cb1fe0d7dabaf656e9e69ed424..1f9679dca58748b0dfe4152e42f765f5ade33a53 100644 (file)
@@ -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', () => {
index 149ff39c40fe8b1325a7c71be910d05fb3dc09b9..df231c7efdb25d732c04a320578b18097f0e2ad1 100644 (file)
@@ -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(
             {
index b72b8f18bdcf5c62054bd3680cce37099093d550..53fcc747b9f2acd97b7417056390806ec31f75d1 100644 (file)
@@ -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,