Skip to content

Commit eee84c0

Browse files
authored
Merge pull request #984 from rubensworks/fix/missing-root-acl
Fix/missing root acl
2 parents 21a41b3 + 2b4250d commit eee84c0

File tree

16 files changed

+84
-23
lines changed

16 files changed

+84
-23
lines changed

default-templates/server/.acl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Root ACL resource for the root
2+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
5+
<#public>
6+
a acl:Authorization;
7+
acl:agentClass foaf:Agent; # everyone
8+
acl:accessTo </>;
9+
acl:default </common/>;
10+
acl:mode acl:Read.

lib/handlers/get.js

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ async function handler (req, res, next) {
2424
const path = res.locals.path || req.path
2525
const requestedType = negotiator.mediaType()
2626
let possibleRDFType = negotiator.mediaType(RDFs)
27-
// Fallback to text/turtle if content type is unknown
28-
possibleRDFType = (!possibleRDFType) ? 'text/turtle' : possibleRDFType
2927

3028
res.header('MS-Author-Via', 'SPARQL')
3129

lib/server-config.js

+14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ async function ensureWelcomePage (argv) {
5555
serverVersion: packageData.version
5656
})
5757
}
58+
59+
// Ensure that the root .acl file exists,
60+
// because this was not mandatory in before 5.0.0
61+
const existingRootAcl = path.join(serverRootDir, '.acl')
62+
if (!fs.existsSync(existingRootAcl)) {
63+
await fsUtils.copyTemplateDir(path.join(templates.server, '.acl'), existingRootAcl)
64+
}
5865
}
5966

6067
/**
@@ -118,6 +125,13 @@ function initTemplateDirs (configPath) {
118125
path.join(configPath, 'templates', 'server')
119126
)
120127

128+
// Ensure that the root .acl file exists,
129+
// because this was not mandatory in before 5.0.0
130+
ensureDirCopyExists(
131+
path.join(__dirname, '../default-templates/server/.acl'),
132+
path.join(configPath, 'templates', 'server', '.acl')
133+
)
134+
121135
return {
122136
account: accountTemplatePath,
123137
email: emailTemplatesPath,

test/integration/account-creation-oidc-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ describe('Single User signup page', () => {
250250
fs.removeSync(rootDir)
251251
})
252252

253-
it('should return a 401 unauthorized without accept text/html', done => {
253+
it('should return a 406 not acceptable without accept text/html', done => {
254254
server.get('/')
255255
.set('accept', 'text/plain')
256-
.expect(401)
256+
.expect(406)
257257
.end(done)
258258
})
259259
})

test/integration/acl-tls-test.js

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('ACL with WebID+TLS', function () {
8989

9090
describe('no ACL', function () {
9191
it('should return 500 for any resource', function (done) {
92+
rm('.acl')
9293
var options = createOptions('/acl-tls/no-acl/', 'user1')
9394
request(options, function (error, response, body) {
9495
assert.equal(error, null)
@@ -98,6 +99,7 @@ describe('ACL with WebID+TLS', function () {
9899
})
99100

100101
it('should have `User` set in the Response Header', function (done) {
102+
rm('.acl')
101103
var options = createOptions('/acl-tls/no-acl/', 'user1')
102104
request(options, function (error, response, body) {
103105
assert.equal(error, null)
@@ -107,6 +109,7 @@ describe('ACL with WebID+TLS', function () {
107109
})
108110

109111
it.skip('should return a 401 and WWW-Authenticate header without credentials', (done) => {
112+
rm('.acl')
110113
let options = {
111114
url: address + '/acl-tls/no-acl/',
112115
headers: { accept: 'text/turtle' }

test/integration/authentication-oidc-test.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const localStorage = require('localstorage-memory')
1010
const URL = require('whatwg-url').URL
1111
global.URL = URL
1212
global.URLSearchParams = require('whatwg-url').URLSearchParams
13-
const { cleanDir } = require('../utils')
13+
const { cleanDir, cp } = require('../utils')
1414

1515
const supertest = require('supertest')
1616
const chai = require('chai')
@@ -68,14 +68,16 @@ describe('Authentication API (OIDC)', () => {
6868
})
6969
}
7070

71-
before(() => {
72-
return Promise.all([
71+
before(async () => {
72+
await Promise.all([
7373
startServer(alicePod, 7000),
7474
startServer(bobPod, 7001)
7575
]).then(() => {
7676
alice = supertest(aliceServerUri)
7777
bob = supertest(bobServerUri)
7878
})
79+
cp(path.join('accounts-scenario/alice', '.acl-override'), path.join('accounts-scenario/alice', '.acl'))
80+
cp(path.join('accounts-scenario/bob', '.acl-override'), path.join('accounts-scenario/bob', '.acl'))
7981
})
8082

8183
after(() => {
@@ -147,7 +149,7 @@ describe('Authentication API (OIDC)', () => {
147149
describe('without that cookie', () => {
148150
let response
149151
before(done => {
150-
alice.get('/')
152+
alice.get('/private-for-alice.txt')
151153
.end((err, res) => {
152154
response = res
153155
done(err)
@@ -197,7 +199,7 @@ describe('Authentication API (OIDC)', () => {
197199
let response
198200
before(done => {
199201
var malcookie = cookie.replace(/connect\.sid=(\S+)/, 'connect.sid=l33th4x0rzp0wn4g3;')
200-
alice.get('/')
202+
alice.get('/private-for-alice.txt')
201203
.set('Cookie', malcookie)
202204
.end((err, res) => {
203205
response = res
@@ -267,7 +269,7 @@ describe('Authentication API (OIDC)', () => {
267269
describe('without that cookie but with globally configured origin', () => {
268270
let response
269271
before(done => {
270-
alice.get('/')
272+
alice.get('/private-for-alice.txt')
271273
.set('Origin', 'https://apps.solid.invalid')
272274
.end((err, res) => {
273275
response = res
@@ -285,7 +287,7 @@ describe('Authentication API (OIDC)', () => {
285287
let response
286288
before(done => {
287289
var malcookie = cookie.replace(/connect\.sid=(\S+)/, 'connect.sid=l33th4x0rzp0wn4g3;')
288-
alice.get('/')
290+
alice.get('/private-for-alice.txt')
289291
.set('Cookie', malcookie)
290292
.set('Origin', 'https://apps.solid.invalid')
291293
.end((err, res) => {

test/integration/errors-oidc-test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const supertest = require('supertest')
22
const ldnode = require('../../index')
33
const path = require('path')
4-
const { cleanDir } = require('../utils')
4+
const { cleanDir, cp } = require('../utils')
55
const expect = require('chai').expect
66

77
describe('OIDC error handling', function () {
@@ -25,7 +25,10 @@ describe('OIDC error handling', function () {
2525
})
2626

2727
before(function (done) {
28-
ldpHttpsServer = ldp.listen(3457, done)
28+
ldpHttpsServer = ldp.listen(3457, () => {
29+
cp(path.join('accounts/errortests', '.acl-override'), path.join('accounts/errortests', '.acl'))
30+
done()
31+
})
2932
})
3033

3134
after(function () {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Root ACL resource for the root
2+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
5+
<#public>
6+
a acl:Authorization;
7+
acl:agentClass foaf:Agent; # everyone
8+
acl:accessTo </>;
9+
acl:default </common/>;
10+
acl:mode acl:Read.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Root ACL resource for the root
2+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
5+
<#public>
6+
a acl:Authorization;
7+
acl:agentClass foaf:Agent; # everyone
8+
acl:accessTo </>;
9+
acl:default </common/>;
10+
acl:mode acl:Read.

test/resources/accounts/localhost/.acl

-10
This file was deleted.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Root ACL resource for the root
2+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
5+
<#public>
6+
a acl:Authorization;
7+
acl:agentClass foaf:Agent; # everyone
8+
acl:accessTo <./>;
9+
acl:default <./>;
10+
acl:mode acl:Read.

test/resources/headers/.acl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Root ACL resource for the root
2+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
3+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
4+
5+
<#public>
6+
a acl:Authorization;
7+
acl:agentClass foaf:Agent; # everyone
8+
acl:accessTo </>;
9+
acl:default </common/>;
10+
acl:mode acl:Read.

test/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports.rm = function (file) {
1414

1515
exports.cleanDir = function (dirPath) {
1616
fs.removeSync(path.join(dirPath, '.well-known/.acl'))
17+
fs.removeSync(path.join(dirPath, '.acl'))
1718
fs.removeSync(path.join(dirPath, 'favicon.ico'))
1819
fs.removeSync(path.join(dirPath, 'favicon.ico.acl'))
1920
fs.removeSync(path.join(dirPath, 'index.html'))

0 commit comments

Comments
 (0)