From 0ae8d59de077a59e0a0b68000d699358cdc3adfb Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 2 Nov 2017 11:41:54 +0100 Subject: [PATCH 1/2] Prevented UploadGateway from being created when cloudServices#tokenUrl is not provided. --- src/cloudservicesuploadadapter.js | 4 ++++ tests/cloudservicesuploadadapter.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/cloudservicesuploadadapter.js b/src/cloudservicesuploadadapter.js index 2139618..0f4690d 100644 --- a/src/cloudservicesuploadadapter.js +++ b/src/cloudservicesuploadadapter.js @@ -41,6 +41,10 @@ export default class CloudServicesUploadAdapter extends Plugin { const token = cloudServices.token; const uploadUrl = cloudServices.uploadUrl || 'https://files.cke-cs.com/upload/'; + if ( !token ) { + return; + } + this._uploadGateway = new CloudServicesUploadAdapter._UploadGateway( token, uploadUrl ); editor.plugins.get( FileRepository ).createAdapter = loader => { diff --git a/tests/cloudservicesuploadadapter.js b/tests/cloudservicesuploadadapter.js index 4980a2d..51a781c 100644 --- a/tests/cloudservicesuploadadapter.js +++ b/tests/cloudservicesuploadadapter.js @@ -60,6 +60,20 @@ describe( 'CloudServicesUploadAdapter', () => { } ); } ); + it( 'should not set loader if there is no token', () => { + UploadGatewayMock.lastToken = undefined; + + return ClassicTestEditor + .create( div, { + plugins: [ CloudServicesUploadAdapter ] + } ) + .then( editor => { + expect( UploadGatewayMock.lastToken ).to.be.an( 'undefined' ); + + return editor.destroy(); + } ); + } ); + it( 'should set the default uploadUrl', () => { const expectedDefaultUrl = 'https://files.cke-cs.com/upload/'; From 744d6e4c18fc1f1ec0a4ec8a407b30f9e763c04b Mon Sep 17 00:00:00 2001 From: Maciej Bukowski Date: Thu, 2 Nov 2017 12:57:20 +0100 Subject: [PATCH 2/2] Simplified test. --- tests/cloudservicesuploadadapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cloudservicesuploadadapter.js b/tests/cloudservicesuploadadapter.js index 51a781c..1998fe1 100644 --- a/tests/cloudservicesuploadadapter.js +++ b/tests/cloudservicesuploadadapter.js @@ -68,7 +68,7 @@ describe( 'CloudServicesUploadAdapter', () => { plugins: [ CloudServicesUploadAdapter ] } ) .then( editor => { - expect( UploadGatewayMock.lastToken ).to.be.an( 'undefined' ); + expect( UploadGatewayMock.lastToken ).to.be.undefined; return editor.destroy(); } );