Skip to content

Commit

Permalink
Merge pull request #26 from telefonicaid/task/IOTCORE-122_FRN_Composi…
Browse files Browse the repository at this point in the history
…tion

Task/iotcore 122 frn composition
  • Loading branch information
Fermín Galán Márquez committed Sep 22, 2014
2 parents 4cc85e0 + 741ab18 commit 8616acb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
27 changes: 27 additions & 0 deletions lib/fiware-orion-pep.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ function xmlRawBody(req, res, next) {
}
}

function generateFRN(req, res, next) {
var frn = 'frn:' + config.componentName + ':';

if (req.organization) {
frn += req.organization + ':';
} else {
frn += ':';
}

if (req.headers[constants.PATH_HEADER]) {
frn += req.headers[constants.PATH_HEADER] + ':';
} else {
frn += ':';
}

if (req.entityType) {
frn += req.entityType;
} else {
frn += ':';
}

req.frn = frn;

next();
}

/**
* Start a new proxy for the configured target. All the configuration is picked up from the config file.
*
Expand Down Expand Up @@ -194,6 +220,7 @@ function startProxy(callback) {
proxyObj.proxy.use(extractOrganization);
proxyObj.proxy.use(extractUserId);
proxyObj.proxy.use(executeDynamicMiddlewares);
proxyObj.proxy.use(generateFRN);
proxyObj.proxy.use(validation.extractRoles);
proxyObj.proxy.use(validation.validate);
proxyObj.proxy.use(sendRequest);
Expand Down
2 changes: 1 addition & 1 deletion lib/services/accessValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function sendAccessRequest(accessPayload, callback) {
*/
function validationProcess(req, res, next) {
async.waterfall([
apply(createAccessRequest, req.roles, req.organization, req.action),
apply(createAccessRequest, req.roles, req.frn, req.action),
sendAccessRequest
], next);
}
Expand Down
2 changes: 1 addition & 1 deletion test/authorizationResponses/rolesOfUser.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"organizations": [
{
"id": 551,
"id": 833,
"actorId": 4230,
"displayName": "VlciBasuras",
"roles": [
Expand Down
35 changes: 13 additions & 22 deletions test/unit/validate_user_action_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ describe('Validate action with Access Control', function() {
res.json(200, utils.readExampleFile('./test/authorizationResponses/rolesOfUser.json'));
};

mockAccessApp.handler = function(req, res) {
res.set('Content-Type', 'application/xml');
res.send(utils.readExampleFile('./test/accessControlResponses/permitResponse.xml', true));
};

done();
});
});
Expand All @@ -85,8 +90,8 @@ describe('Validate action with Access Control', function() {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Fiware-Service': 'frn:contextbroker:551:::',
'fiware-servicepath': '551',
'Fiware-Service': '551',
'fiware-servicepath': '833',
'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q'
},
json: utils.readExampleFile('./test/orionRequests/entityCreation.json')
Expand Down Expand Up @@ -117,22 +122,6 @@ describe('Validate action with Access Control', function() {
});
});

it('should send a validation request to Access Control', function(done) {
var mockExecuted = false;

mockAccessApp.handler = function(req, res) {
req.rawBody.should.match(/8907(.|\n)*4937(.|\n)*frn:contextbroker:551:::(.|\n)*create/);
res.set('Content-Type', 'application/xml');
res.send(utils.readExampleFile('./test/accessControlResponses/permitResponse.xml', true));
mockExecuted = true;
};

request(options, function(error, response, body) {
mockExecuted.should.equal(true);
done();
});
});

it('should proxy the request to the destination', function(done) {
var mockExecuted = false;

Expand Down Expand Up @@ -160,8 +149,8 @@ describe('Validate action with Access Control', function() {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Fiware-Service': 'frn:contextbroker:551:::',
'fiware-servicepath': '551',
'Fiware-Service': '551',
'fiware-servicepath': '833',
'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q'
},
json: utils.readExampleFile('./test/orionRequests/entityCreation.json')
Expand Down Expand Up @@ -203,7 +192,8 @@ describe('Validate action with Access Control', function() {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Fiware-Service': 'frn:contextbroker:551:::',
'Fiware-Service': '551',
'Fiware-Path': '833',
'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q'
},
json: utils.readExampleFile('./test/orionRequests/entityCreation.json')
Expand Down Expand Up @@ -248,7 +238,8 @@ describe('Validate action with Access Control', function() {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Fiware-Service': 'frn:contextbroker:551:::',
'Fiware-Service': '551',
'Fiware-Path': '833',
'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q'
},
json: utils.readExampleFile('./test/orionRequests/entityCreation.json')
Expand Down

0 comments on commit 8616acb

Please sign in to comment.