Skip to content

Commit e1648c9

Browse files
committed
fixing the first 13 tests
1 parent 314f31e commit e1648c9

5 files changed

Lines changed: 47 additions & 22 deletions

File tree

lib/acl.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ var ACL = require('solid-acl');
2020
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
2121

2222
function match (graph, s, p, o) {
23-
var matches = graph.statementsMatching(s ? $rdf.sym(s) : undefined, $rdf.sym(p), $rdf.sym(o));
23+
var matches = graph.statementsMatching(
24+
s ? $rdf.sym(s) : undefined,
25+
p ? $rdf.sym(p) : undefined,
26+
o ? $rdf.sym(o) : undefined);
2427
return matches
2528
}
2629

@@ -171,7 +174,7 @@ ACL.prototype.findRule = function (graph, user, mode, resource, accessType, acl,
171174
if (!self.isAcl(resource) || accessType === 'defaultForNew') {
172175
debug('Checking for accessType:' + accessType)
173176
var accesses = self.matchAccessType(graph, statementSubject, accessType, resource)
174-
if (accesses) {
177+
if (!accesses) {
175178
debug('Cannot find accessType ' + accessType)
176179
return done(false)
177180
}
@@ -217,10 +220,11 @@ ACL.prototype.matchAccessType = function matchAccessType (graph, rule, accessTyp
217220
graph,
218221
rule,
219222
'http://www.w3.org/ns/auth/acl#' + accessType,
220-
uri)
223+
undefined)
221224

225+
console.log("matches", matches, rule, accessType, uri)
222226
return matches.some(function(match) {
223-
return S(uri).beginsWith(match)
227+
return S(uri).startsWith(match.object.uri);
224228
})
225229

226230
}

lib/ldp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ LDP.prototype.put = function (filePath, contents, callback) {
328328
mkdirp(path.dirname(filePath), function (err) {
329329
if (err) {
330330
debug.handlers("PUT -- Error creating directory: " + err);
331-
return callback(new HTTPError({
331+
return callback(new HttpError({
332332
status: err.code === 'ENOENT' ? 404 : 500,
333333
message: err.message
334334
}));
335335
}
336336
return fs.writeFile(filePath, contents, function() {
337337
if (err) {
338338
debug.handlers("PUT -- Error writing file: " + err);
339-
return callback(new HTTPError({
339+
return callback(new HttpError({
340340
status: err.code === 'ENOENT' ? 404 : 500,
341341
message: err.message
342342
}));

test/acl.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,32 @@ describe('ACL HTTP', function() {
135135
});
136136
})
137137
describe("with defaultForNew in parent path", function () {
138+
it("should fail to create a container", function(done) {
139+
var options = createOptions('/acl/write-acl/empty-acl/test-folder/', 'user1');
140+
options.body = "";
141+
request.put(options, function(error, response, body) {
142+
assert.equal(response.statusCode, 409);
143+
done();
144+
});
145+
});
138146
it("should allow creation of new files", function(done) {
139-
var options = createOptions('/acl/write-acl/empty-acl/test-folder', 'user1');
147+
var options = createOptions('/acl/write-acl/empty-acl/test-file', 'user1');
148+
options.body = "";
149+
request.put(options, function(error, response, body) {
150+
assert.equal(response.statusCode, 201);
151+
done();
152+
});
153+
});
154+
it("should allow creation of new files in deeper paths", function(done) {
155+
var options = createOptions('/acl/write-acl/empty-acl/test-folder/test-file', 'user1');
140156
options.body = "";
141157
request.put(options, function(error, response, body) {
142158
assert.equal(response.statusCode, 201);
143159
done();
144160
});
145161
});
146162
it("Should create empty acl file", function(done) {
147-
var options = createOptions(testDirAclFile, 'user1');
163+
var options = createOptions('/acl/write-acl/empty-acl/another-empty-folder/test-file.acl', 'user1');
148164
options.headers = {
149165
'content-type': 'text/turtle'
150166
};
@@ -156,7 +172,7 @@ describe('ACL HTTP', function() {
156172
});
157173
});
158174
it("Should return text/turtle for the acl file", function(done) {
159-
var options = createOptions(testDirAclFile, 'user1');
175+
var options = createOptions('/acl/write-acl/.acl', 'user1');
160176
options.headers = {
161177
accept: 'text/turtle'
162178
};
@@ -168,7 +184,7 @@ describe('ACL HTTP', function() {
168184
});
169185
});
170186
it("Should create test file", function(done) {
171-
var options = createOptions(abcFile, 'user1');
187+
var options = createOptions('/acl/write-acl/test-file', 'user1');
172188
options.headers = {
173189
'content-type': 'text/turtle'
174190
};
@@ -180,7 +196,7 @@ describe('ACL HTTP', function() {
180196
});
181197
});
182198
it("Should create test file's acl file", function(done) {
183-
var options = createOptions(abcAclFile, 'user1');
199+
var options = createOptions('/acl/write-acl/test-file.acl', 'user1');
184200
options.headers = {
185201
'content-type': 'text/turtle'
186202
};
@@ -192,7 +208,7 @@ describe('ACL HTTP', function() {
192208
});
193209
});
194210
it("Should access test file's acl file", function(done) {
195-
var options = createOptions(abcAclFile, 'user1');
211+
var options = createOptions('/acl/write-acl/test-file.acl', 'user1');
196212
options.headers = {
197213
accept: 'text/turtle'
198214
};
@@ -208,20 +224,21 @@ describe('ACL HTTP', function() {
208224

209225
describe("Origin", function() {
210226
it("Should PUT new ACL file", function(done) {
211-
var options = createOptions(testDirAclFile, 'user1');
227+
var options = createOptions('/acl/origin/test-folder/.acl', 'user1');
212228
options.headers = {
213229
'content-type': 'text/turtle'
214230
};
215231
options.body = "<#Owner>\n" +
216-
" <http://www.w3.org/ns/auth/acl#accessTo> <" + address + testDir + "/" + ">, <" + address + testDirAclFile + ">;\n" +
232+
" <http://www.w3.org/ns/auth/acl#accessTo> <" + address + "acl/origin/test-folder/" + ">;\n" +
217233
" <http://www.w3.org/ns/auth/acl#agent> <" + user1 + ">;\n" +
218234
" <http://www.w3.org/ns/auth/acl#origin> <" + origin1 + ">;\n" +
219235
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write> .\n" +
220236
"<#Public>\n" +
221-
" <http://www.w3.org/ns/auth/acl#accessTo> <" + address + testDir + "/" + ">;\n" +
237+
" <http://www.w3.org/ns/auth/acl#accessTo> <" + address + "acl/origin/test-folder/" + ">;\n" +
222238
" <http://www.w3.org/ns/auth/acl#agentClass> <http://xmlns.com/foaf/0.1/Agent>;\n" +
223239
" <http://www.w3.org/ns/auth/acl#origin> <" + origin1 + ">;\n" +
224240
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n";
241+
console.log(options.body)
225242
request.put(options, function(error, response, body) {
226243
assert.equal(error, null);
227244
assert.equal(response.statusCode, 201);
@@ -231,7 +248,7 @@ describe('ACL HTTP', function() {
231248
});
232249
});
233250
it("user1 should be able to access test directory", function(done) {
234-
var options = createOptions(testDir + '/', 'user1');
251+
var options = createOptions('/acl/origin/test-folder/', 'user1');
235252
request.head(options, function(error, response, body) {
236253
assert.equal(error, null);
237254
assert.equal(response.statusCode, 200);
@@ -240,7 +257,7 @@ describe('ACL HTTP', function() {
240257
});
241258
it("user1 should be able to access to test directory when origin is valid",
242259
function(done) {
243-
var options = createOptions(testDir, 'user1');
260+
var options = createOptions('/acl/origin/test-folder/', 'user1');
244261
options.headers = {
245262
origin: origin1
246263
};
@@ -252,7 +269,7 @@ describe('ACL HTTP', function() {
252269
});
253270
it("user1 should be denied access to test directory when origin is invalid",
254271
function(done) {
255-
var options = createOptions(testDir, 'user1');
272+
var options = createOptions('/acl/origin/test-folder/', 'user1');
256273
options.headers = {
257274
origin: origin2
258275
};
@@ -263,7 +280,7 @@ describe('ACL HTTP', function() {
263280
});
264281
});
265282
it("agent should be able to access test directory", function(done) {
266-
var options = createOptions(testDir);
283+
var options = createOptions('/acl/origin/test-folder/');
267284
request.head(options, function(error, response, body) {
268285
assert.equal(error, null);
269286
assert.equal(response.statusCode, 200);
@@ -272,7 +289,7 @@ describe('ACL HTTP', function() {
272289
});
273290
it("agent should be able to access to test directory when origin is valid",
274291
function(done) {
275-
var options = createOptions(testDir, 'user1');
292+
var options = createOptions('/acl/origin/test-folder/', 'user1');
276293
options.headers = {
277294
origin: origin1
278295
};
@@ -284,7 +301,7 @@ describe('ACL HTTP', function() {
284301
});
285302
it("agent should be denied access to test directory when origin is invalid",
286303
function(done) {
287-
var options = createOptions(testDir);
304+
var options = createOptions('/acl/origin/test-folder/');
288305
options.headers = {
289306
origin: origin2
290307
};

test/resources/acl/origin/.acl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<#0>
2+
<http://www.w3.org/ns/auth/acl#defaultForNew> <./> ;
3+
<http://www.w3.org/ns/auth/acl#agent> <https://user1.databox.me/profile/card#me> ;
4+
<http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control>.

test/resources/acl/write-acl/.acl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<#0>
22
<http://www.w3.org/ns/auth/acl#defaultForNew> <./> ;
33
<http://www.w3.org/ns/auth/acl#agent> <https://user1.databox.me/profile/card#me> ;
4-
<http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Write> .
4+
<http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Write>, <http://www.w3.org/ns/auth/acl#Control>.

0 commit comments

Comments
 (0)