Skip to content

Commit 84481b1

Browse files
author
nicola
committed
adding skeleton for ACL tests and fixing in different scope
1 parent bc6ba29 commit 84481b1

2 files changed

Lines changed: 77 additions & 10 deletions

File tree

‎acl.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ ACL.prototype.fetchDocument = function(uri, callback) {
405405
* @param {Object} err Error occurred when reading the acl file
406406
* @param {Number} err.status Status code of the error (HTTP way)
407407
* @param {String} err.message Reason of the error
408-
* @param {Object} RDFlib graph of the fetched file
408+
* @param {Object} graph RDFlib graph of the fetched file
409409
*/
410410

411411
/**
@@ -415,20 +415,22 @@ ACL.prototype.fetchDocument = function(uri, callback) {
415415
* @param {ACL~getUserId_cb} callback Callback called when UserId is retrieved
416416
*/
417417
ACL.prototype.getUserId = function (callback) {
418-
if (!this.onBehalfOf) {
418+
var acl = this;
419+
420+
if (!acl.onBehalfOf) {
419421
return callback(null, this.session.userId);
420422
}
421423

422-
var delegator = rdfVocab.debrack(this.onBehalfOf);
423-
this.verifyDelegator(delegator, this.session.userId, function(err, res) {
424+
var delegator = rdfVocab.debrack(acl.onBehalfOf);
425+
acl.verifyDelegator(delegator, acl.session.userId, function(err, res) {
424426

425-
// TODO handle error
427+
// TODO dle error
426428

427429
if (res) {
428430
debug("Request User ID (delegation) :" + delegator);
429431
return callback(null, delegator);
430432
}
431-
return callback(null, this.session.userId);
433+
return callback(null, acl.session.userId);
432434
});
433435
};
434436
/**
@@ -457,6 +459,7 @@ ACL.prototype.verifyDelegator = function (delegator, delegatee, callback) {
457459
.each(delegatorGraph.sym(delegator),
458460
delegatorGraph.sym("http://www.w3.org/ns/auth/acl#delegates"),
459461
undefined);
462+
460463
for (var delegateeIndex in delegatesStatements) {
461464
var delegateeValue = delegatesStatements[delegateeIndex];
462465
if (rdfVocab.debrack(delegateeValue.toString()) === delegatee) {

‎test/acl.js‎

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ describe('ACL HTTP', function() {
986986
});
987987

988988
describe('ACL Class', function () {
989+
this.timeout(10000);
989990
var ldpConfig = {
990991
mount: '/test',
991992
root: __dirname + '/resources',
@@ -996,8 +997,44 @@ describe('ACL Class', function () {
996997
var ldpServer = ldnode(ldpConfig);
997998
var ldp = ldpServer.locals.ldp;
998999

1000+
var user1 = "https://user1.databox.me/profile/card#me";
1001+
var user2 = "https://user2.databox.me/profile/card#me";
1002+
var nicola = "https://nicola.databox.me/profile/card#me";
1003+
1004+
describe('readACL', function () {
1005+
1006+
});
1007+
1008+
describe('findACLinPath', function () {
1009+
1010+
});
1011+
1012+
describe('findACL', function () {
1013+
1014+
});
1015+
1016+
describe('allowMode', function () {
1017+
1018+
});
1019+
1020+
describe('allowControl', function () {
1021+
1022+
});
1023+
1024+
describe('allow', function () {
1025+
1026+
});
1027+
1028+
describe('allowOrigin', function () {
1029+
1030+
});
1031+
1032+
describe('fetchDocument', function () {
1033+
1034+
});
1035+
9991036
describe('getUserId', function () {
1000-
it('should return userId in session if On-Behalf-Of is not specified', function() {
1037+
it('should return userId in session if On-Behalf-Of is not specified', function(done) {
10011038
var acl = new ACL({
10021039
ldp: ldp,
10031040
origin: 'https://example.com',
@@ -1009,23 +1046,50 @@ describe('ACL Class', function () {
10091046

10101047
acl.getUserId(function(err, userId) {
10111048
assert.equal(userId, 'https://user1.databox.me/profile/card#me');
1049+
done(err);
10121050
});
10131051
});
10141052

1015-
it('should return userId in session if On-Behalf-Of is not valid', function() {
1053+
it('should return userId in session if On-Behalf-Of is not valid', function(done) {
10161054
var acl = new ACL({
10171055
ldp: ldp,
10181056
origin: 'https://example.com',
10191057
session: {
1020-
userId: 'https://user1.databox.me/profile/card#me',
1058+
userId: user1,
10211059
identified: true
10221060
},
10231061
onBehalfOf: ''
10241062
});
10251063

10261064
acl.getUserId(function(err, userId) {
1027-
assert.equal(userId, 'https://user1.databox.me/profile/card#me');
1065+
assert.equal(userId, user1);
1066+
done(err);
10281067
});
10291068
});
1069+
1070+
// it('should return On-Behalf-Of if is the delegatee', function(done) {
1071+
// var acl = new ACL({
1072+
// ldp: ldp,
1073+
// origin: 'https://example.com',
1074+
// session: {
1075+
// userId: user2,
1076+
// identified: true
1077+
// },
1078+
// onBehalfOf: '<' + user1 + '>'
1079+
// });
1080+
1081+
// acl.getUserId(function(err, userId) {
1082+
// assert.equal(userId, user1);
1083+
// done(err);
1084+
// });
1085+
// });
1086+
});
1087+
1088+
describe('verifyDelegator', function () {
1089+
1090+
});
1091+
1092+
describe('readACL', function () {
1093+
10301094
});
10311095
});

0 commit comments

Comments
 (0)