Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.

Commit 6e6795a

Browse files
author
Chris Wiechmann
committed
Separate tests as nock.cleanAll() has no effect
causing the tests to conflict
1 parent 7e1b57b commit 6e6795a

File tree

2 files changed

+76
-24
lines changed

2 files changed

+76
-24
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const { expect } = require('chai');
2+
const { startApiBuilder, stopApiBuilder, requestAsync, sendToElasticsearch, getRandomInt } = require('../../../_base');
3+
const path = require('path');
4+
const fs = require('fs');
5+
const nock = require('nock');
6+
const envLoader = require('dotenv');
7+
8+
describe('Endpoints', function () {
9+
this.timeout(30000);
10+
let server;
11+
let auth;
12+
const indexName = `apigw-traffic-summary-search_custom_restricted_perm_test_${getRandomInt(9999)}`;
13+
14+
/**
15+
* Start API Builder.
16+
*/
17+
before(() => {
18+
return new Promise(function(resolve, reject){
19+
const envFilePath = path.join(__dirname, '../../../.env');
20+
if (fs.existsSync(envFilePath)) {
21+
envLoader.config({ path: envFilePath });
22+
}
23+
// Special permissions configured required to get unrestricted traffic access
24+
process.env.UNRESTRICTED_PERMISSIONS = "logs,mgmt";
25+
server = startApiBuilder();
26+
server.apibuilder.config.testElasticIndex = indexName;
27+
elasticConfig = server.apibuilder.config.pluginConfig['@axway-api-builder-ext/api-builder-plugin-fn-elasticsearch'].elastic;
28+
server.started
29+
.then(() => {
30+
const entryset = require('../../../documents/http/search_count_documents');
31+
sendToElasticsearch(elasticConfig, indexName, 'traffic-summary/index_template.json', entryset)
32+
.then(() => {
33+
resolve();
34+
})
35+
.catch(err => reject(err));
36+
});
37+
});
38+
});
39+
40+
/**
41+
* Stop API Builder after the tests.
42+
*/
43+
after(() => {
44+
stopApiBuilder(server);
45+
delete process.env.UNRESTRICTED_PERMISSIONS;
46+
});
47+
48+
afterEach(async () => {
49+
nock.cleanAll();
50+
});
51+
52+
describe('Search', async () => {
53+
it('[RestrictedPermissions-0002] Custom restriction permission configuration - User has with monitoring permission a restricted access', async () => {
54+
// Configured permissions: mgmt,logs - Not enough for user rene only having permission monitoring
55+
nock('https://mocked-api-gateway:8090').get('/api/rbac/currentuser').reply(200, { "result": "rene" });
56+
nock('https://mocked-api-gateway:8090').get('/api/topology').reply(200, { result: {} });
57+
nock('https://mocked-api-gateway:8090').get('/api/rbac/permissions/currentuser').replyWithFile(200, './test/mockedReplies/apigateway/permissionMonitoring.json');
58+
nock('https://mocked-api-gateway:8075').get(`/api/portal/v1.3/users?field=loginName&op=eq&value=rene&field=enabled&op=eq&value=enabled`).replyWithFile(200, './test/mockedReplies/apimanager/apiManagerUserRene.json');
59+
nock('https://mocked-api-gateway:8075').get(`/api/portal/v1.3/organizations/2bfaa1c2-49ab-4059-832d-MAX`).replyWithFile(200, './test/mockedReplies/apimanager/organizationMax.json');
60+
return await requestAsync({
61+
method: 'GET',
62+
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?count=20`,
63+
headers: {
64+
'cookie': 'VIDUSR=Search-Count-0001-DAVID-1597468226-Z+qdRW4rGZnwzQ==',
65+
'csrf-token': '04F9F07E59F588CDE469FC367A12ED3A4B845FDA9A9AE2D9A77686823067CDDC'
66+
},
67+
json: true
68+
}).then(({ response, body }) => {
69+
expect(response.statusCode).to.equal(200);
70+
expect(body).to.be.an('Object');
71+
expect(body).to.have.property('data');
72+
expect(body.data).to.have.lengthOf(2); // Expect only two results as the user is restricted
73+
});
74+
});
75+
});
76+
});

apibuilder4elastic/test/trafficMonitorAPI/asAdmin/http/test_search_custom_restrictionPermissions.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,5 @@ describe('Endpoints', function () {
7070
expect(body.data).to.have.lengthOf(13); // Expect the entire result set
7171
});
7272
});
73-
74-
// For any stupid reason this tests conflicts with the test before, as the existin nock is not cleaned and user david is still returned
75-
it.skip('[RestrictedPermissions-0002] Custom restriction permission configuration - User has with monitoring permission a restricted access', async () => {
76-
// Configured permissions: mgmt,logs - Not enough for user rene only having permission monitoring
77-
nock('https://mocked-api-gateway:8090').get('/api/rbac/currentuser').reply(200, { "result": "rene" });
78-
nock('https://mocked-api-gateway:8090').get('/api/topology').reply(200, { result: {} });
79-
nock('https://mocked-api-gateway:8090').get('/api/rbac/permissions/currentuser').replyWithFile(200, './test/mockedReplies/apigateway/permissionMonitoring.json');
80-
nock('https://mocked-api-gateway:8075').get(`/api/portal/v1.3/users?field=loginName&op=eq&value=rene&field=enabled&op=eq&value=enabled`).replyWithFile(200, './test/mockedReplies/apimanager/apiManagerUserRene.json');
81-
nock('https://mocked-api-gateway:8075').get(`/api/portal/v1.3/organizations/2bfaa1c2-49ab-4059-832d-MAX`).replyWithFile(200, './test/mockedReplies/apimanager/organizationMax.json');
82-
return await requestAsync({
83-
method: 'GET',
84-
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search?count=20`,
85-
headers: {
86-
'cookie': 'VIDUSR=Search-Count-0001-DAVID-1597468226-Z+qdRW4rGZnwzQ==',
87-
'csrf-token': '04F9F07E59F588CDE469FC367A12ED3A4B845FDA9A9AE2D9A77686823067CDDC'
88-
},
89-
json: true
90-
}).then(({ response, body }) => {
91-
expect(response.statusCode).to.equal(200);
92-
expect(body).to.be.an('Object');
93-
expect(body).to.have.property('data');
94-
expect(body.data).to.have.lengthOf(2); // Expect only two results as the user is restricted
95-
});
96-
});
9773
});
9874
});

0 commit comments

Comments
 (0)