2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
2021-10-06 11:12:21 +01:00
|
|
|
const parseContext = require('../../../../../core/server/services/permissions/parse-context');
|
2017-09-25 10:17:06 +01:00
|
|
|
|
|
|
|
describe('Permissions', function () {
|
|
|
|
describe('parseContext', function () {
|
|
|
|
it('should return public for no context', function () {
|
|
|
|
parseContext().should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: true,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
parseContext({}).should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: true,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return public for random context', function () {
|
|
|
|
parseContext('public').should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: true,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
parseContext({client: 'thing'}).should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: true,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return user if user populated', function () {
|
|
|
|
parseContext({user: 1}).should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: 1,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: false,
|
|
|
|
integration: null
|
2019-01-18 12:17:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-24 14:19:34 +00:00
|
|
|
it('should return api_key and public context if content api_key provided', function () {
|
|
|
|
parseContext({api_key: {
|
|
|
|
id: 1,
|
2019-07-05 13:40:43 +02:00
|
|
|
type: 'content'
|
2019-02-06 20:14:36 +01:00
|
|
|
}, integration: {id: 2}}).should.eql({
|
2019-01-18 12:17:12 +01:00
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: {
|
|
|
|
id: 1,
|
|
|
|
type: 'content'
|
|
|
|
},
|
2019-02-06 20:14:36 +01:00
|
|
|
public: true,
|
|
|
|
integration: {id: 2}
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-24 14:19:34 +00:00
|
|
|
it('should return api_key and non public context if admin api_key provided', function () {
|
|
|
|
parseContext({api_key: {
|
|
|
|
id: 1,
|
|
|
|
type: 'admin'
|
2019-02-06 20:14:36 +01:00
|
|
|
}, integration: {id: 3}}).should.eql({
|
2019-01-24 14:19:34 +00:00
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
|
|
|
api_key: {
|
|
|
|
id: 1,
|
|
|
|
type: 'admin'
|
|
|
|
},
|
2019-02-06 20:14:36 +01:00
|
|
|
public: false,
|
|
|
|
integration: {id: 3}
|
2019-01-24 14:19:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-25 10:17:06 +01:00
|
|
|
it('should return internal if internal provided', function () {
|
|
|
|
parseContext({internal: true}).should.eql({
|
|
|
|
internal: true,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: false,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
parseContext('internal').should.eql({
|
|
|
|
internal: true,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: false,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return external if external provided', function () {
|
|
|
|
parseContext({external: true}).should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: true,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: false,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
parseContext('external').should.eql({
|
|
|
|
internal: false,
|
|
|
|
external: true,
|
|
|
|
user: null,
|
2019-01-24 14:19:34 +00:00
|
|
|
api_key: null,
|
2019-02-06 20:14:36 +01:00
|
|
|
public: false,
|
|
|
|
integration: null
|
2017-09-25 10:17:06 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|