Skip to content

Commit f74cd10

Browse files
authored
Merge pull request #577 from telefonicaid/fix/check_role_admin_in_service
Fix/check role admin in service
2 parents 6e75ea3 + 6cc2aac commit f74cd10

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
- Fix: check rol admin in service when local pdp

lib/services/pdp.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ function validationRequest(logger, roles, frn, action, headers, callback) {
8888
let matchedRole = null;
8989

9090
for (const role of roles) {
91-
const name = role.name || '';
92-
const parts = name.split('#');
93-
if (parts.length !== 2) {
94-
continue;
95-
}
91+
const name = (role.name || '').trim();
9692

97-
const roleInfo = parts[1];
93+
// if name role with '#', then get right part; otherwise name as is
94+
const hashParts = name.split('#');
95+
const roleInfoRaw = (hashParts.length === 2 ? hashParts[1] : hashParts[0]).trim();
96+
// Alias: admin (without #) = ServiceAdmin for all components
97+
const roleInfo = /^admin$/i.test(roleInfoRaw) ? 'ServiceAdmin' : roleInfoRaw;
9898

9999
// Try extrat type and component (i.e.: ServiceCustomerORION)
100100
let match = roleInfo.match(

test/unit/validate_user_local_pdp_action_test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ describe('Local PDP validationRequest decision tree', function () {
107107
.catch(done);
108108
});
109109

110+
it('admin without component can READ ORION at service level', function (done) {
111+
runValidation({
112+
roles: [{ id: '1', name: 'admin' }],
113+
frn: 'fiware:orion:smartcity:/:::',
114+
action: 'create'
115+
})
116+
.then(function (decision) {
117+
decision.should.equal('Permit');
118+
done();
119+
})
120+
.catch(done);
121+
});
122+
110123
it('ServiceCustomer without component cannot CREATE in ORION', function (done) {
111124
runValidation({
112125
roles: [{ id: '1', name: 'x#ServiceCustomer' }],

0 commit comments

Comments
 (0)