2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const testUtils = require('../../utils');
|
|
|
|
const _ = require('lodash');
|
2013-09-15 20:04:42 +04:00
|
|
|
|
2021-03-12 09:42:33 +03:00
|
|
|
const ghostVersion = require('../../../core/server/lib/ghost-version');
|
|
|
|
const {exportedBodyLatest} = require('../../utils/fixtures/export/body-generator');
|
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
// Stuff we are testing
|
|
|
|
const exporter = require('../../../core/server/data/exporter');
|
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
describe('Exporter', function () {
|
2020-02-24 23:51:09 +03:00
|
|
|
before(testUtils.teardownDb);
|
|
|
|
afterEach(testUtils.teardownDb);
|
2014-07-21 21:50:04 +04:00
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
2016-07-15 19:22:41 +03:00
|
|
|
beforeEach(testUtils.setup('default', 'settings'));
|
2014-07-21 21:50:04 +04:00
|
|
|
|
|
|
|
should.exist(exporter);
|
2013-09-15 20:04:42 +04:00
|
|
|
|
2021-03-12 09:42:33 +03:00
|
|
|
it('exports expected table data', function (done) {
|
2016-03-12 21:54:06 +03:00
|
|
|
exporter.doExport().then(function (exportData) {
|
2021-03-12 09:42:33 +03:00
|
|
|
const tables = [
|
|
|
|
'actions',
|
|
|
|
'api_keys',
|
|
|
|
'brute',
|
|
|
|
'email_batches',
|
|
|
|
'email_recipients',
|
|
|
|
'emails',
|
|
|
|
'integrations',
|
|
|
|
'invites',
|
|
|
|
'labels',
|
|
|
|
'members',
|
|
|
|
'members_email_change_events',
|
|
|
|
'members_labels',
|
|
|
|
'members_login_events',
|
|
|
|
'members_paid_subscription_events',
|
|
|
|
'members_payment_events',
|
|
|
|
'members_status_events',
|
|
|
|
'members_stripe_customers',
|
|
|
|
'members_stripe_customers_subscriptions',
|
|
|
|
'members_subscribe_events',
|
|
|
|
'migrations',
|
|
|
|
'migrations_lock',
|
|
|
|
'mobiledoc_revisions',
|
|
|
|
'permissions',
|
|
|
|
'permissions_roles',
|
|
|
|
'permissions_users',
|
|
|
|
'posts',
|
|
|
|
'posts_authors',
|
|
|
|
'posts_meta',
|
|
|
|
'posts_tags',
|
|
|
|
'roles',
|
|
|
|
'roles_users',
|
|
|
|
'sessions',
|
|
|
|
'settings',
|
|
|
|
'snippets',
|
|
|
|
'tags',
|
|
|
|
'tokens',
|
|
|
|
'users',
|
|
|
|
'webhooks'
|
|
|
|
];
|
2013-09-15 20:04:42 +04:00
|
|
|
|
|
|
|
should.exist(exportData);
|
|
|
|
should.exist(exportData.meta);
|
|
|
|
should.exist(exportData.data);
|
|
|
|
|
2021-03-12 09:42:33 +03:00
|
|
|
exportData.data.should.have.only.keys(...tables);
|
|
|
|
exportData.data.should.have.keys(...Object.keys(exportedBodyLatest().db[0].data));
|
2017-12-14 16:13:40 +03:00
|
|
|
exportData.meta.version.should.equal(ghostVersion.full);
|
2013-09-15 20:04:42 +04:00
|
|
|
|
2021-03-12 09:42:33 +03:00
|
|
|
// excludes table should contain no data
|
|
|
|
const excludedTables = [
|
|
|
|
'sessions',
|
|
|
|
'mobiledoc_revisions',
|
|
|
|
'email_batches',
|
|
|
|
'email_recipients',
|
|
|
|
'members_payment_events',
|
|
|
|
'members_login_events',
|
|
|
|
'members_email_change_events',
|
|
|
|
'members_status_events',
|
|
|
|
'members_paid_subscription_events',
|
|
|
|
'members_subscribe_events'
|
|
|
|
];
|
|
|
|
|
|
|
|
excludedTables.forEach((tableName) => {
|
|
|
|
// NOTE: why is this undefined? The key should probably not even be present
|
|
|
|
should.equal(exportData.data[tableName], undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
// excludes settings with sensitive data
|
|
|
|
const excludedSettings = [
|
|
|
|
'stripe_connect_publishable_key',
|
|
|
|
'stripe_connect_secret_key',
|
|
|
|
'stripe_connect_account_id',
|
|
|
|
'stripe_secret_key',
|
|
|
|
'stripe_publishable_key',
|
|
|
|
'members_stripe_webhook_id',
|
|
|
|
'members_stripe_webhook_secret'
|
|
|
|
];
|
|
|
|
|
|
|
|
excludedSettings.forEach((settingKey) => {
|
|
|
|
should.not.exist(_.find(exportData.data.settings, {key: settingKey}));
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
2017-01-26 15:12:00 +03:00
|
|
|
|
2018-08-06 18:18:59 +03:00
|
|
|
should.not.exist(_.find(exportData.data.settings, {key: 'permalinks'}));
|
|
|
|
|
2013-09-15 20:04:42 +04:00
|
|
|
// should not export sqlite data
|
|
|
|
should.not.exist(exportData.data.sqlite_sequence);
|
|
|
|
done();
|
2014-05-06 00:58:58 +04:00
|
|
|
}).catch(done);
|
2013-09-15 20:04:42 +04:00
|
|
|
});
|
|
|
|
});
|