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

Commit 05d7d59

Browse files
author
Chris Wiechmann
committed
Making it possible to skip ext user authz if returned URI is undefined
#126
1 parent 3dfbada commit 05d7d59

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
### Fixed
9+
- Index-Templates failed to install without using a region [#124](https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk/issues/124)
10+
11+
### Added
12+
- Skip Ext-HTTP-User-AuthZ if returned URL is undefined [#126](https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk/issues/126)
13+
814
### Changed
915
- Updated Elastic-Stack from version 7.12.1 to 7.13.3
16+
- API-Builder stops/terminates with an error-message and error-code, if Elasticsearch cannot be configured (e.g. Index-Templates cannot be installed)
17+
1018

1119
## [3.3.0] 2021-07-21
1220
### Fixed

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-authorization/src/actions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ async function addExtHTTPAuthzFilter(params, options) {
142142
} else {
143143
throw new Error(`Missing method: createRequestUri. You have to defined the createRequestUri method to create the request URI.`);
144144
}
145+
if(!replacedUri) {
146+
logger.info(`User authorization for user: ${user.loginName} is skipped, as returned URI is undefined.`);
147+
return elasticQuery;
148+
}
145149
logger.info(`External groups NOT found in cache with key: '${cacheKey}'. Going to request information from ${replacedUri}`);
146150
const resp = await requester(replacedUri, cfg.headers, cfg.method, cfg.body, { logger, ...cfg.options });
147151
cache.set(cacheKey, resp);

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-authorization/test/testConfig/authorization-config-extAuthZCustom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ var authorizationConfig = {
1818

1919
async function createRequestUri(user, cfg, options) {
2020
// Replace the loginName which is part of the URI
21+
if(user.loginName == "SKIP-AUTHZ") return undefined;
22+
if(user.loginName == "SKIP-AUTHZ-BOOLEAN") return false;
2123
return cfg.uri.replace("__loginName__", user.loginName);
2224
}
2325

apibuilder4elastic/custom_flow_nodes/api-builder-plugin-authorization/test/testExtHttpAuthZ1Custom.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,29 @@ describe('flow-node Authorization', () => {
4646
expect(value).to.deep.equal(expectedQuery);
4747
expect(output).to.equal('next');
4848
});
49+
50+
it('should skip the user authorization based on undefined URI', async () => {
51+
var elasticQuery = JSON.parse(fs.readFileSync('./test/mock/givenElasticQuery.json'), null);
52+
53+
const { value, output } = await flowNode.addExtHTTPAuthzFilter({
54+
user: { loginName: "SKIP-AUTHZ" }, elasticQuery: elasticQuery, restrictionField: "customProperties.field1"
55+
});
56+
57+
expect(value).to.be.instanceOf(Object);
58+
expect(value).to.deep.equal(elasticQuery);
59+
expect(output).to.equal('next');
60+
});
61+
62+
it('should skip the user authorization based on a returned boolean false as an URI', async () => {
63+
var elasticQuery = JSON.parse(fs.readFileSync('./test/mock/givenElasticQuery.json'), null);
64+
65+
const { value, output } = await flowNode.addExtHTTPAuthzFilter({
66+
user: { loginName: "SKIP-AUTHZ-BOOLEAN" }, elasticQuery: elasticQuery, restrictionField: "customProperties.field1"
67+
});
68+
69+
expect(value).to.be.instanceOf(Object);
70+
expect(value).to.deep.equal(elasticQuery);
71+
expect(output).to.equal('next');
72+
});
4973
});
5074
});

0 commit comments

Comments
 (0)