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

Commit 5d64a88

Browse files
author
Chris Wiechmann
committed
Multi-Org - Ignore if primary org is Non-Dev-Org, when user has multiple orgs
#141
1 parent 210574b commit 5d64a88

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-axway-api-management/src/actions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ async function lookupCurrentUser(params, options) {
108108
throw new Error(`User: '${user.loginName}' not found in API-Manager.`);
109109
}
110110
user.apiManager = users[0];
111-
// Get the name of the primary organization
111+
// Get the name of the primary organization, ignore the Dev-Status if the user has multiple organizations
112+
options.mustBeDevelopmentOrg = (user.apiManager.orgs2Name) ? false : true;
112113
var org = await _getOrganization(user.apiManager, null, null, options);
113114
user.apiManager.organizationName = org.name;
114115
logger.debug(`User: '${user.loginName}' (Role: ${user.apiManager.role}) found in API-Manager. Organization: '${user.apiManager.organizationName}'`);
@@ -667,7 +668,7 @@ async function _getApplication(applicationId, groupId, region) {
667668
}
668669

669670
async function _getOrganization(apiProxy, groupId, region, options) {
670-
const { logger } = options;
671+
const { logger, mustBeDevelopmentOrg } = options;
671672
if(apiProxy.locallyConfigured) {
672673
if(apiProxy.organizationName == undefined) apiProxy.organizationName = "N/A";
673674
return apiProxy;
@@ -701,7 +702,7 @@ async function _getOrganization(apiProxy, groupId, region, options) {
701702
if(!org.enabled) {
702703
throw new Error(`Organization: '${org.name}' is disabled.`);
703704
}
704-
if(!org.development) {
705+
if(!org.development && mustBeDevelopmentOrg) {
705706
throw new Error(`Organization: '${org.name}' is not a development organization.`);
706707
}
707708
cache.set(orgCacheKey, org)

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-axway-api-management/test/test-userlookup.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,18 @@ describe('Tests User-Lookup with complete configuration parameters', () => {
308308
.and.to.have.property('message', 'Organization: \'API Development\' is not a development organization.');
309309
expect(output).to.equal('error');
310310
});
311+
312+
it('should NOT error even if belonging organization has no development flag if the user has multiple organizations-', async () => {
313+
nock('https://mocked-api-gateway:8190').get('/api/rbac/currentuser').reply(200, { "result": "chris" });
314+
nock('https://mocked-api-gateway:8190').get('/api/rbac/permissions/currentuser').replyWithFile(200, './test/testReplies/gateway/operatorRoleOnlyPermissions.json');
315+
nock('https://mocked-api-gateway:8175').get(`/api/portal/v1.3/users?field=loginName&op=eq&value=chris${enabledField}`).replyWithFile(200, './test/testReplies/apimanager/apiManagerUserChrisMultiOrg.json');
316+
nock('https://mocked-api-gateway:8175').get(`/api/portal/v1.3/organizations/2bfaa1c2-49ab-4059-832d-f833ca1c0a74`).replyWithFile(200, './test/testReplies/apimanager/noDevelopmentOrg.json');
317+
318+
const { value, output } = await flowNode.lookupCurrentUser({
319+
requestHeaders: {"host":"api-gateway:8090","max-forwards":"20", "cookie":"VIDUSR=1597381095-XTawGDtJhBA7Zw==;", "csrf-token": "CF2796B3BD18C1B0B5AB1C8E95B75662E92FBC04BD799DEB97838FC5B9C39348"}
320+
});
321+
322+
expect(output).to.equal('next');
323+
});
311324
});
312325
});

0 commit comments

Comments
 (0)