Skip to content

Commit b0afbdc

Browse files
author
nicola
committed
adding further ACL tests
1 parent 8b7705f commit b0afbdc

1 file changed

Lines changed: 93 additions & 17 deletions

File tree

‎test/acl.js‎

Lines changed: 93 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,9 @@ describe('ACL Class', function () {
10491049
'.acl');
10501050

10511051
acl.readACL(__dirname + '/resources/.acl', address, function (err, res) {
1052+
rm('.acl');
10521053
assert.equal(err.status, 500);
10531054
assert.notOk(res);
1054-
rm('.acl');
10551055
done();
10561056
});
10571057
});
@@ -1075,9 +1075,9 @@ describe('ACL Class', function () {
10751075
'.acl');
10761076

10771077
acl.readACL(__dirname + '/resources/.acl', address, function (err, graph) {
1078+
rm('.acl');
10781079
assert.notOk(err);
10791080
assert.ok(graph);
1080-
rm('.acl');
10811081
done();
10821082
});
10831083
});
@@ -1097,9 +1097,9 @@ describe('ACL Class', function () {
10971097
'.acl');
10981098

10991099
acl.readACL(__dirname + '/resources/.acl', address, function (err, graph) {
1100+
rm('.acl');
11001101
assert.notOk(err);
11011102
assert.ok(graph);
1102-
rm('.acl');
11031103
done();
11041104
});
11051105
});
@@ -1251,6 +1251,20 @@ describe('ACL Class', function () {
12511251
});
12521252

12531253
it('should report that ACL has not been found if aclGraph is empty', function(done) {
1254+
var acl = new ACL({
1255+
ldp: ldp
1256+
});
1257+
1258+
acl.findACLinPath('Read', __dirname + '/resources/.acl', address, $rdf.graph(), 'accessTo', user1, function (err, result) {
1259+
assert.notOk(err);
1260+
assert.equal(result, false);
1261+
done();
1262+
});
1263+
});
1264+
});
1265+
1266+
describe('findACL', function () {
1267+
it('should return no error if permission is found', function (done) {
12541268
var acl = new ACL({
12551269
ldp: ldp,
12561270
origin: 'https://example.com',
@@ -1261,36 +1275,98 @@ describe('ACL Class', function () {
12611275
uri: address
12621276
});
12631277

1264-
acl.findACLinPath('Read', __dirname + '/resources/.acl', address, $rdf.graph(), 'accessTo', user1, function (err, result) {
1278+
write(
1279+
"<#Owner>\n" +
1280+
" <http://www.w3.org/ns/auth/acl#accessTo> <" +
1281+
address + "/" + ">, <" + address + ">;\n" +
1282+
" <http://www.w3.org/ns/auth/acl#owner> <" + user1 + ">;\n" +
1283+
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n",
1284+
'.acl');
1285+
1286+
acl.findACL('Read', '/', user1, function (err) {
1287+
rm('.acl');
12651288
assert.notOk(err);
1266-
assert.equal(result, false);
12671289
done();
12681290
});
12691291
});
1270-
});
12711292

1272-
describe('findACL', function () {
1273-
1274-
});
1293+
it('should return error error if user is allowed to `Read` but not to `Write`', function (done) {
1294+
var acl = new ACL({
1295+
ldp: ldp,
1296+
origin: 'https://example.com',
1297+
session: {
1298+
userId: user1,
1299+
identified: true
1300+
},
1301+
uri: address
1302+
});
12751303

1276-
describe('allowMode', function () {
1304+
write(
1305+
"<#Owner>\n" +
1306+
" <http://www.w3.org/ns/auth/acl#accessTo> <" +
1307+
address + "/" + ">, <" + address + ">;\n" +
1308+
" <http://www.w3.org/ns/auth/acl#owner> <" + user1 + ">;\n" +
1309+
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n",
1310+
'.acl');
12771311

1278-
});
1312+
acl.findACL('Write', '/', user1, function (err) {
1313+
rm('.acl');
1314+
assert.equal(err.status, 403);
1315+
done();
1316+
});
1317+
});
12791318

1280-
describe('allowControl', function () {
1319+
it('should return error 403 if user is not allowed', function (done) {
1320+
var acl = new ACL({
1321+
ldp: ldp,
1322+
origin: 'https://example.com',
1323+
session: {
1324+
userId: user1,
1325+
identified: true
1326+
},
1327+
uri: address
1328+
});
12811329

1282-
});
1330+
write(
1331+
"<#Owner>\n" +
1332+
" <http://www.w3.org/ns/auth/acl#accessTo> <" +
1333+
address + "/" + ">, <" + address + ">;\n" +
1334+
" <http://www.w3.org/ns/auth/acl#owner> <" + user2 + ">;\n" +
1335+
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Control> .\n",
1336+
'.acl');
12831337

1284-
describe('allow', function () {
1338+
acl.findACL('Control', '/', user1, function (err) {
1339+
rm('.acl');
1340+
assert.equal(err.status, 403);
1341+
done();
1342+
});
1343+
});
12851344

1286-
});
1345+
it('should return no error if no permission rule is found', function (done) {
1346+
var acl = new ACL({
1347+
ldp: ldp,
1348+
origin: 'https://example.com',
1349+
session: {
1350+
userId: user1,
1351+
identified: true
1352+
},
1353+
uri: address
1354+
});
12871355

1288-
describe('allowOrigin', function () {
1356+
write(
1357+
'',
1358+
'.acl');
12891359

1360+
acl.findACL('Control', '/', user1, function (err) {
1361+
rm('.acl');
1362+
assert.notOk(err);
1363+
done();
1364+
});
1365+
});
12901366
});
12911367

12921368
describe('fetchDocument', function () {
1293-
1369+
// TODO missing tests
12941370
});
12951371

12961372
describe('getUserId', function () {

0 commit comments

Comments
 (0)