Skip to content

Commit 9acda7d

Browse files
committed
cleaning
1 parent 3784e55 commit 9acda7d

File tree

5 files changed

+33
-43
lines changed

5 files changed

+33
-43
lines changed

lib/acl-checker.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const { dirname } = require('path')
55
const rdf = require('rdflib')
66
const debug = require('./debug').ACL
77
// const debugCache = require('./debug').cache
8-
// const debugAccounts = require('./debug').accounts
98
const HTTPError = require('./http-error')
109
const aclCheck = require('@solid/acl-check')
1110
const { URL } = require('url')
@@ -56,6 +55,7 @@ class ACLChecker {
5655
}
5756
this.messagesCached[cacheKey] = this.messagesCached[cacheKey] || []
5857

58+
// for method DELETE nearestACL and ACL from parent resource
5959
const acl = await this.getNearestACL(method).catch(err => {
6060
this.messagesCached[cacheKey].push(new HTTPError(err.status || 500, err.message || err))
6161
})
@@ -95,56 +95,56 @@ class ACLChecker {
9595
// FIXME: https://github.com/solid/acl-check/issues/23
9696
// console.error(e.message)
9797
}
98+
9899
function resourceAccessDenied (modes) {
99-
accessDenied = aclCheck.accessDenied(aclGraph, resource, directory, aclFile, agent, modes, agentOrigin, trustedOrigins, originTrustedModes)
100+
return aclCheck.accessDenied(aclGraph, resource, directory, aclFile, agent, modes, agentOrigin, trustedOrigins, originTrustedModes)
100101
}
101-
102102
function accessDeniedForAccessTo (modes) {
103103
const accessDeniedAccessTo = aclCheck.accessDenied(aclGraph, directory, null, aclFile, agent, modes, agentOrigin, trustedOrigins, originTrustedModes)
104104
const accessResult = !accessDenied && !accessDeniedAccessTo
105-
accessDenied = accessResult ? false : accessDenied || accessDeniedAccessTo
106-
// debugCache('accessDenied result ' + accessDenied)
105+
return accessResult ? false : accessDenied || accessDeniedAccessTo
107106
}
108107
async function accessdeniedFromParent (modes) {
109108
const parentAclDirectory = ACLChecker.getDirectory(acl.parentAcl)
110109
const parentDirectory = parentResource === parentAclDirectory ? null : rdf.sym(parentAclDirectory)
111-
// if (acl.parentAcl.endWith('/.acl')) parentDirectory = rdf.sym(parentAclDirectory)
112110
const accessDeniedParent = aclCheck.accessDenied(acl.parentGraph, parentResource, parentDirectory, rdf.sym(acl.parentAcl), agent, modes, agentOrigin, trustedOrigins, originTrustedModes)
113111
const accessResult = !accessDenied && !accessDeniedParent
114-
accessDenied = accessResult ? false : accessDenied || accessDeniedParent
115-
// debugCache('accessDenied result ' + accessDenied)
112+
return accessResult ? false : accessDenied || accessDeniedParent
116113
}
117114

118-
let accessDenied
119-
resourceAccessDenied(modes)
115+
let accessDenied = resourceAccessDenied(modes)
116+
// debugCache('accessDenied resource ' + accessDenied)
117+
120118
// For create and update HTTP methods
121119
if ((method === 'PUT' || method === 'PATCH' || method === 'COPY')) {
122120
// if resource and acl have same parent container,
123121
// and resource does not exist, then accessTo Append from parent is required
124122
if (directory && directory.value === dirname(aclFile.value) + '/' && !resourceExists) {
125-
accessDeniedForAccessTo([ACL('Append')])
123+
accessDenied = accessDeniedForAccessTo([ACL('Append')])
126124
}
125+
// debugCache('accessDenied PUT/PATCH ' + accessDenied)
127126
}
128127

129128
// For delete HTTP method
130129
if ((method === 'DELETE')) {
131130
if (resourceExists) {
132131
// deleting a Container
133132
// without Read, the response code will reveal whether a Container is empty or not
134-
if (directory && this.resource.endsWith('/')) resourceAccessDenied([ACL('Read'), ACL('Write')])
133+
if (directory && this.resource.endsWith('/')) accessDenied = resourceAccessDenied([ACL('Read'), ACL('Write')])
135134
// if resource and acl have same parent container,
136135
// then both Read and Write on parent is required
137-
else if (!directory && aclFile.value.endsWith(`/${this.suffix}`)) await accessdeniedFromParent([ACL('Read'), ACL('Write')])
136+
else if (!directory && aclFile.value.endsWith(`/${this.suffix}`)) accessDenied = await accessdeniedFromParent([ACL('Read'), ACL('Write')])
138137

139138
// deleting a Document
140139
else if (directory && directory.value === dirname(aclFile.value) + '/') {
141-
accessDeniedForAccessTo([ACL('Write')])
140+
accessDenied = accessDeniedForAccessTo([ACL('Write')])
142141
} else {
143-
await accessdeniedFromParent([ACL('Write')])
142+
accessDenied = await accessdeniedFromParent([ACL('Write')])
144143
}
145144

146145
// https://github.com/solid/specification/issues/14#issuecomment-1712773516
147146
} else { accessDenied = true }
147+
// debugCache('accessDenied DELETE ' + accessDenied)
148148
}
149149

150150
if (accessDenied && user) {
@@ -184,7 +184,6 @@ class ACLChecker {
184184
let parentGraph = null
185185
let docAcl = null
186186
let docGraph = null
187-
// while (possibleACLs.length > 0 && !returnParentAcl) {
188187
while (possibleACLs.length > 0 && !returnParentAcl) {
189188
const acl = possibleACLs.shift()
190189
let graph
@@ -193,7 +192,7 @@ class ACLChecker {
193192
graph = await this.requests[acl]
194193
} catch (err) {
195194
if (err && (err.code === 'ENOENT' || err.status === 404)) {
196-
// only set isContainer before docAcl // alain
195+
// only set isContainer before docAcl
197196
if (!docAcl) isContainer = true
198197
continue
199198
}
@@ -205,7 +204,7 @@ class ACLChecker {
205204
if (!docAcl) {
206205
docAcl = acl
207206
docGraph = graph
208-
// parentAcl is only needed for DELETE // alain
207+
// parentAcl is only needed for DELETE
209208
if (method !== 'DELETE') returnParentAcl = true
210209
} else {
211210
parentAcl = acl

lib/create-app.js

-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const { routeResolvedFile } = require('./utils')
2727
const ResourceMapper = require('./resource-mapper')
2828
const aclCheck = require('@solid/acl-check')
2929
const { version } = require('../package.json')
30-
// const preconditions = require('express-preconditions')
3130

3231
const corsSettings = cors({
3332
methods: [
@@ -115,14 +114,6 @@ function createApp (argv = {}) {
115114
authProxy(app, argv.authProxy)
116115
}
117116

118-
// redirect http to https
119-
app.use(function (req, res, next) {
120-
if (req.protocol === 'http:') {
121-
return res.redirect('https://' + req.headers.host + req.url)
122-
}
123-
next()
124-
})
125-
126117
// Attach the LDP middleware
127118
app.use('/', LdpMiddleware(corsSettings))
128119

test/integration/acl-oidc-test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
138138
done()
139139
})
140140
})
141-
it('user1 as solid:owner should let edit the .acl', function (done) { // alain
141+
it('user1 as solid:owner should let edit the .acl', function (done) {
142142
const options = createOptions('/empty-acl/.acl', 'user1', 'text/turtle')
143143
options.body = ''
144144
request.put(options, function (error, response, body) {
@@ -209,7 +209,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
209209
done()
210210
})
211211
})
212-
it('Should not create empty acl file', function (done) { // alain
212+
it('Should not create empty acl file', function (done) {
213213
const options = createOptions('/write-acl/empty-acl/another-empty-folder/.acl', 'user1', 'text/turtle')
214214
options.body = ''
215215
request.put(options, function (error, response, body) {
@@ -273,7 +273,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
273273
})
274274

275275
describe('no-control', function () {
276-
it('user1 as owner should edit acl file', function (done) { // alain
276+
it('user1 as owner should edit acl file', function (done) {
277277
const options = createOptions('/no-control/.acl', 'user1', 'text/turtle')
278278
options.body = '<#0>' +
279279
'\n a <http://www.w3.org/ns/auth/acl#Authorization>;' +
@@ -551,7 +551,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
551551
done()
552552
})
553553
})
554-
it('user1 should be able to PATCH (which CREATEs) a nonexistent resource', function (done) {
554+
it('user1 should be able to PATCH a nonexistent resource (which CREATEs)', function (done) {
555555
const options = createOptions('/append-inherited/test.ttl', 'user1')
556556
options.body = 'INSERT DATA { :test :hello 456 .}'
557557
options.headers['content-type'] = 'application/sparql-update'
@@ -571,7 +571,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
571571
done()
572572
})
573573
})
574-
it('user1 should be able to PUT (which CREATEs) (non existent resource)', function (done) {
574+
it('user1 should be able to PUT to non existent resource (which CREATEs)', function (done) {
575575
const options = createOptions('/append-inherited/test1.ttl', 'user1')
576576
options.body = '<a> <b> <c> .\n'
577577
options.headers['content-type'] = 'text/turtle'
@@ -610,7 +610,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
610610
done()
611611
})
612612
})
613-
it('user2 should be able to PATCH INSERT to (which CREATEs) a nonexistent resource', function (done) {
613+
it('user2 should be able to PATCH INSERT to a nonexistent resource (which CREATEs)', function (done) {
614614
const options = createOptions('/append-inherited/new.ttl', 'user2')
615615
options.body = 'INSERT DATA { :test :hello 789 .}'
616616
options.headers['content-type'] = 'application/sparql-update'
@@ -620,7 +620,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
620620
done()
621621
})
622622
})
623-
it('user2 should be able to PUT to (which CREATEs) a non existent resource', function (done) { // alain
623+
it('user2 should be able to PUT to a non existent resource (which CREATEs)', function (done) {
624624
const options = createOptions('/append-inherited/new1.ttl', 'user1')
625625
options.body = '<a> <b> <c> .\n'
626626
options.headers['content-type'] = 'text/turtle'

test/integration/http-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ describe('HTTP APIs', function () {
472472
})
473473
it('should have set acl and describedBy Links for resource',
474474
function (done) {
475-
server.head('/sampleContainer2/example1.ttl') // get
475+
server.head('/sampleContainer2/example1.ttl')
476476
.expect(hasHeader('acl', 'example1.ttl' + suffixAcl))
477477
.expect(hasHeader('describedBy', 'example1.ttl' + suffixMeta))
478478
.end(done)

test/unit/resource-mapper-test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe('ResourceMapper', () => {
282282
],
283283
{
284284
path: `${rootPath}space/`,
285-
contentType: 'text/turtle' // 'application/octet-stream'
285+
contentType: 'text/turtle'
286286
})
287287

288288
itMapsUrl(mapper, 'a URL ending with a slash when index$.html is available',
@@ -295,7 +295,7 @@ describe('ResourceMapper', () => {
295295
],
296296
{
297297
path: `${rootPath}space/`,
298-
contentType: 'text/turtle' // 'application/octet-stream'
298+
contentType: 'text/turtle'
299299
})
300300

301301
itMapsUrl(mapper, 'a URL ending with a slash when index$.ttl is available',
@@ -307,7 +307,7 @@ describe('ResourceMapper', () => {
307307
],
308308
{
309309
path: `${rootPath}space/`,
310-
contentType: 'text/turtle' // 'application/octet-stream'
310+
contentType: 'text/turtle'
311311
})
312312

313313
itMapsUrl(mapper, 'a URL ending with a slash to a folder when index.html is available but index is skipped',
@@ -321,7 +321,7 @@ describe('ResourceMapper', () => {
321321
],
322322
{
323323
path: `${rootPath}space/`,
324-
contentType: 'text/turtle' // 'application/octet-stream'
324+
contentType: 'text/turtle'
325325
})
326326

327327
itMapsUrl(mapper, 'a URL ending with a slash to a folder when no index is available',
@@ -330,7 +330,7 @@ describe('ResourceMapper', () => {
330330
},
331331
{
332332
path: `${rootPath}space/`,
333-
contentType: 'text/turtle' // 'application/octet-stream'
333+
contentType: 'text/turtle'
334334
})
335335

336336
itMapsUrl(mapper, 'a URL of that has an accompanying acl file, but no actual file',
@@ -342,7 +342,7 @@ describe('ResourceMapper', () => {
342342
],
343343
{
344344
path: `${rootPath}space/`,
345-
contentType: 'text/turtle' // 'application/octet-stream'
345+
contentType: 'text/turtle'
346346
})
347347

348348
itMapsUrl(mapper, 'a URL ending with a slash for text/html when index.html is not available',
@@ -373,13 +373,13 @@ describe('ResourceMapper', () => {
373373
itMapsUrl(mapper, 'a URL ending with a slash to a folder when index is skipped',
374374
{
375375
url: 'http://localhost/space/',
376-
contentType: 'text/turtle', // 'application/octet-stream',
376+
contentType: 'text/turtle',
377377
createIfNotExists: true,
378378
searchIndex: false
379379
},
380380
{
381381
path: `${rootPath}space/`,
382-
contentType: 'text/turtle' // 'application/octet-stream'
382+
contentType: 'text/turtle'
383383
})
384384

385385
itMapsUrl(mapper, 'a URL ending with a slash for text/turtle',

0 commit comments

Comments
 (0)