2018-10-07 17:36:02 +03:00
|
|
|
const url = require('url');
|
|
|
|
const _ = require('lodash');
|
2019-01-22 19:54:50 +03:00
|
|
|
const testUtils = require('../../../utils');
|
|
|
|
const schema = require('../../../../server/data/schema').tables;
|
2018-10-07 17:36:02 +03:00
|
|
|
const API_URL = '/ghost/api/v2/admin/';
|
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
const expectedProperties = {
|
|
|
|
// API top level
|
|
|
|
posts: ['posts', 'meta'],
|
2019-02-22 06:17:14 +03:00
|
|
|
pages: ['pages', 'meta'],
|
2018-12-17 18:14:36 +03:00
|
|
|
tags: ['tags', 'meta'],
|
|
|
|
users: ['users', 'meta'],
|
|
|
|
settings: ['settings', 'meta'],
|
|
|
|
subscribers: ['subscribers', 'meta'],
|
|
|
|
roles: ['roles'],
|
|
|
|
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
|
|
|
slugs: ['slugs'],
|
|
|
|
slug: ['slug'],
|
2018-12-17 19:45:07 +03:00
|
|
|
invites: ['invites', 'meta'],
|
|
|
|
themes: ['themes'],
|
2019-01-29 21:52:05 +03:00
|
|
|
actions: ['actions', 'meta'],
|
|
|
|
|
|
|
|
action: ['id', 'resource_type', 'actor_type', 'event', 'created_at', 'actor'],
|
2018-12-17 19:45:07 +03:00
|
|
|
|
2018-12-17 18:14:36 +03:00
|
|
|
post: _(schema.posts)
|
|
|
|
.keys()
|
2019-02-25 12:44:19 +03:00
|
|
|
// by default we only return mobildoc
|
|
|
|
.without('html', 'plaintext')
|
2019-02-13 13:41:14 +03:00
|
|
|
.without('visibility')
|
|
|
|
.without('locale')
|
2019-02-22 06:17:14 +03:00
|
|
|
.without('page')
|
2019-02-25 12:55:24 +03:00
|
|
|
// deprecated
|
|
|
|
.without('author_id')
|
|
|
|
// always returns computed properties
|
|
|
|
.concat('url', 'primary_tag', 'primary_author', 'excerpt')
|
2019-02-25 13:08:28 +03:00
|
|
|
// returned by default
|
|
|
|
.concat('tags', 'authors')
|
2018-12-17 19:45:07 +03:00
|
|
|
,
|
2019-02-22 06:17:14 +03:00
|
|
|
|
|
|
|
page: _(schema.posts)
|
|
|
|
.keys()
|
2019-02-25 12:44:19 +03:00
|
|
|
// by default we only return mobildoc
|
|
|
|
.without('html', 'plaintext')
|
2019-02-22 06:17:14 +03:00
|
|
|
.without('visibility')
|
|
|
|
.without('locale')
|
|
|
|
.without('page')
|
2019-02-25 12:55:24 +03:00
|
|
|
// deprecated
|
|
|
|
.without('author_id')
|
|
|
|
// always returns computed properties
|
|
|
|
.concat('url', 'primary_tag', 'primary_author', 'excerpt')
|
2019-02-25 13:08:28 +03:00
|
|
|
// returned by default
|
|
|
|
.concat('tags', 'authors')
|
2019-02-22 06:17:14 +03:00
|
|
|
,
|
|
|
|
|
2018-12-17 19:45:07 +03:00
|
|
|
user: _(schema.users)
|
|
|
|
.keys()
|
2019-02-13 13:41:14 +03:00
|
|
|
.without('visibility')
|
2018-12-17 19:45:07 +03:00
|
|
|
.without('password')
|
2019-02-13 13:41:14 +03:00
|
|
|
.without('locale')
|
2018-12-17 19:45:07 +03:00
|
|
|
.without('ghost_auth_access_token')
|
2019-02-13 01:36:42 +03:00
|
|
|
.without('ghost_auth_id')
|
2018-12-17 19:45:07 +03:00
|
|
|
,
|
|
|
|
tag: _(schema.tags)
|
|
|
|
.keys()
|
2019-02-12 21:26:31 +03:00
|
|
|
// unused field
|
|
|
|
.without('parent_id')
|
2018-12-17 19:45:07 +03:00
|
|
|
,
|
|
|
|
setting: _(schema.settings)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
subscriber: _(schema.subscribers)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
accesstoken: _(schema.accesstokens)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
role: _(schema.roles)
|
|
|
|
.keys()
|
|
|
|
,
|
|
|
|
permission: _(schema.permissions)
|
|
|
|
.keys()
|
|
|
|
,
|
2018-12-17 18:14:36 +03:00
|
|
|
notification: ['type', 'message', 'status', 'id', 'dismissible', 'location', 'custom'],
|
|
|
|
theme: ['name', 'package', 'active'],
|
2018-12-17 19:45:07 +03:00
|
|
|
invite: _(schema.invites)
|
|
|
|
.keys()
|
|
|
|
.without('token')
|
|
|
|
,
|
2018-12-17 18:14:36 +03:00
|
|
|
webhook: _(schema.webhooks)
|
|
|
|
.keys()
|
|
|
|
};
|
|
|
|
|
2018-12-17 19:45:07 +03:00
|
|
|
_.each(expectedProperties, (value, key) => {
|
|
|
|
if (!value.__wrapped__) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated: x_by
|
|
|
|
*/
|
|
|
|
expectedProperties[key] = value
|
|
|
|
.without(
|
|
|
|
'created_by',
|
|
|
|
'updated_by',
|
|
|
|
'published_by'
|
|
|
|
)
|
|
|
|
.value();
|
|
|
|
});
|
|
|
|
|
2018-10-07 17:36:02 +03:00
|
|
|
module.exports = {
|
|
|
|
API: {
|
|
|
|
getApiQuery(route) {
|
|
|
|
return url.resolve(API_URL, route);
|
2018-12-17 18:14:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
checkResponse(...args) {
|
|
|
|
this.expectedProperties = expectedProperties;
|
|
|
|
return testUtils.API.checkResponse.call(this, ...args);
|
2018-10-07 17:36:02 +03:00
|
|
|
}
|
2018-10-09 06:24:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
doAuth(...args) {
|
|
|
|
return testUtils.API.doAuth(`${API_URL}session/`, ...args);
|
2019-01-18 19:36:11 +03:00
|
|
|
},
|
|
|
|
|
2019-02-23 14:51:21 +03:00
|
|
|
getValidAdminToken(audience) {
|
2019-01-18 19:36:11 +03:00
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const JWT_OPTIONS = {
|
2019-01-23 15:22:47 +03:00
|
|
|
algorithm: 'HS256',
|
2019-01-23 20:08:57 +03:00
|
|
|
expiresIn: '5m',
|
2019-02-23 14:51:21 +03:00
|
|
|
audience: audience
|
2019-01-18 19:36:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return jwt.sign(
|
|
|
|
{
|
|
|
|
kid: testUtils.DataGenerator.Content.api_keys[0].id
|
|
|
|
},
|
|
|
|
Buffer.from(testUtils.DataGenerator.Content.api_keys[0].secret, 'hex'),
|
2019-01-23 15:22:47 +03:00
|
|
|
JWT_OPTIONS
|
2019-01-18 19:36:11 +03:00
|
|
|
);
|
2018-10-07 17:36:02 +03:00
|
|
|
}
|
|
|
|
};
|