Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7248: Destroy token instance if created by CloudServices plugin #7257

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/ckeditor5-cloud-services/src/cloudservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export default class CloudServices extends ContextPlugin {

return this.token.init();
}

/**
* @inheritDoc
*/
destroy() {
super.destroy();

if ( this.token ) {
this.token.destroy();
}
}
}

CloudServices.Token = Token;
Expand Down
31 changes: 31 additions & 0 deletions packages/ckeditor5-cloud-services/tests/cloudservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,35 @@ describe( 'CloudServices', () => {
} );
} );
} );

describe( 'destroy()', () => {
it( 'should destroy created token when tokenUrl was provided', async () => {
CloudServices.Token.initialToken = 'initial-token';

const context = await Context.create( {
plugins: [ CloudServices ],
cloudServices: {
tokenUrl: 'http://token-endpoint'
}
} );

const cloudServicesPlugin = context.plugins.get( CloudServices );

const destroySpy = sinon.spy( cloudServicesPlugin.token, 'destroy' );

await context.destroy();

sinon.assert.calledOnce( destroySpy );
} );

it( 'should not crash when tokenUrl was not provided', async () => {
const context = await Context.create( { plugins: [ CloudServices ] } );

try {
await context.destroy();
} catch ( error ) {
expect.fail( 'Error should not be thrown.' );
}
} );
} );
} );