diff --git a/packages/composer-playground/src/app/add-certificate/add-certificate.component.spec.ts b/packages/composer-playground/src/app/add-certificate/add-certificate.component.spec.ts index c421b0d5f3..66c6a8bf0c 100644 --- a/packages/composer-playground/src/app/add-certificate/add-certificate.component.spec.ts +++ b/packages/composer-playground/src/app/add-certificate/add-certificate.component.spec.ts @@ -210,7 +210,7 @@ describe('AddCertificateComponent', () => { component['fileType'].should.equal(type); }); - it('should set the cetificate string to the dataBuffer string content', async(() => { + it('should set the certificate string to the dataBuffer string content', async(() => { let data = 'someData'; component.createCertificate('', data); component['addedCertificate'].should.equal(data); @@ -242,13 +242,58 @@ describe('AddCertificateComponent', () => { mockModalSpy.should.have.been.called; })); + it('should handle strings with encoded newlines (windows format 1) in certs correctly', async(() => { + + component['addedCertificate'] = 'MuchCertificate\\r\\nFollowon\\r\\nFinal'; + component['addedHostname'] = 'suchHost'; + + let additionalData = {}; + additionalData['cert'] = 'MuchCertificate\nFollowon\nFinal'; + additionalData['hostnameOverride'] = 'suchHost'; + + // call the method + component.addCertificate(); + + mockModalSpy.should.have.been.calledWith(additionalData); + })); + + it('should handle strings with encoded newlines (windows format 2) in certs correctly', async(() => { + + component['addedCertificate'] = 'MuchCertificate\\n\\rFollowon\\n\\rFinal'; + component['addedHostname'] = 'suchHost'; + + let additionalData = {}; + additionalData['cert'] = 'MuchCertificate\nFollowon\nFinal'; + additionalData['hostnameOverride'] = 'suchHost'; + + // call the method + component.addCertificate(); + + mockModalSpy.should.have.been.calledWith(additionalData); + })); + + it('should handle strings with encoded newlines (unix format) in certs correctly', async(() => { + + component['addedCertificate'] = 'MuchCertificate\\nFollowon\\nFinal'; + component['addedHostname'] = 'suchHost'; + + let additionalData = {}; + additionalData['cert'] = 'MuchCertificate\nFollowon\nFinal'; + additionalData['hostnameOverride'] = 'suchHost'; + + // call the method + component.addCertificate(); + + mockModalSpy.should.have.been.calledWith(additionalData); + })); + it('should return a constructed json object', async(() => { component['addedCertificate'] = 'MuchCertificate'; component['addedHostname'] = 'suchHost'; let additionalData = {}; - additionalData['cert'] = 'MuchCertificate'.replace(/[\\n\\r]/g, ''); + additionalData['cert'] = 'MuchCertificate'; additionalData['hostnameOverride'] = 'suchHost'; // call the method diff --git a/packages/composer-playground/src/app/add-certificate/add-certificate.component.ts b/packages/composer-playground/src/app/add-certificate/add-certificate.component.ts index 6fbc9f18dc..5e520382e2 100644 --- a/packages/composer-playground/src/app/add-certificate/add-certificate.component.ts +++ b/packages/composer-playground/src/app/add-certificate/add-certificate.component.ts @@ -79,7 +79,7 @@ export class AddCertificateComponent { addCertificate(): void { let additionalData = {}; additionalData['hostnameOverride'] = this.addedHostname; - additionalData['cert'] = this.addedCertificate.replace(/[\\n\\r]/g, ''); + additionalData['cert'] = this.addedCertificate.replace(/\\r\\n|\\n\\r|\\n/g, '\n'); this.activeModal.close(additionalData); } }