-
Notifications
You must be signed in to change notification settings - Fork 50
/
app-permissions.test.js
131 lines (124 loc) · 3.47 KB
/
app-permissions.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const { init: initClients } = require('../../utils/clients');
const permissions = [
'keys-list',
'keys-read',
'keys-write',
'schemas-read',
'schemas-write',
'history',
'search',
'search-index',
'tags-read',
'tags-write',
];
const { expect } = require('chai');
describe('authoring api - app permissions', () => {
let clients;
before(async () => {
clients = await initClients();
});
const cases = [
{
name: 'read_specific_key',
requirePermission: 'keys-read',
action: async client => {
await client.get('/api/keys/integration_tests/some_key').expect(200);
},
},
{
name: 'read_specific_key',
requirePermission: 'keys-read',
action: async client => {
await client.get('/api/key?keyPath=integration_tests%2Fsome_key').expect(200);
},
},
{
name: 'read_manifests',
requirePermission: 'keys-read',
action: async client => {
await client.get('/api/manifests/integration_tests/some_key').expect(200);
},
},
{
name: 'list_keys',
requirePermission: 'keys-list',
action: async client => {
await client.get('/api/keys').expect(200);
},
},
{
name: 'list_manifests',
requirePermission: 'keys-list',
action: async client => {
await client.get('/api/manifests').expect(200);
},
},
{
name: 'get_dependents',
requirePermission: 'keys-read',
action: async client => {
await client.get('/api/dependents/integration_tests/some_key').expect(200);
},
},
{
name: 'get_dependents',
requirePermission: 'keys-read',
action: async client => {
await client.get('/api/dependents/integration_tests/some_key').expect(200);
},
},
{
name: 'get_schemas',
requirePermission: 'schemas_read',
action: async client => {
await client.get('/api/schemas').expect(200);
},
},
{
name: 'search',
requirePermission: 'search',
action: async client => {
await client.get('/api/search').expect(200);
},
},
{
name: 'suggestions',
requirePermission: 'search',
action: async client => {
await client.get('/api/suggestions').expect(200);
},
},
{
name: 'search-index',
requirePermission: 'search-index',
action: async client => {
await client.get('/api/search-index').expect(200);
},
},
];
for (let permission of permissions) {
it(`testing permission ${permission}`, async () => {
const relevantCases = cases.filter(c => c.requirePermission === permission);
const forbiddenCases = cases.filter(c => c.requirePermission !== permission);
let response = await clients.authoring
.post('/api/apps?author.name=test&author.email=test@soluto.com')
.send({ name: 'my-app', permissions: [permission] })
.expect(200);
let { appId, appSecret } = response.body;
let appClient = await clients.authoring.with(client =>
client.set({ 'x-client-id': appId, 'x-client-secret': appSecret }).unset('Authorization'),
);
await Promise.all(relevantCases.map(x => x.action(appClient)));
await Promise.all(
forbiddenCases.map(async x => {
await x.action(appClient).then(
() => true,
ex => {
return expect(ex.message).to.contain('403');
},
);
}),
);
}).timeout(6000);
}
});