Skip to content

Commit 383b849

Browse files
committed
Set no quota if the predicate isn't there
1 parent 3383003 commit 383b849

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

lib/utils.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ function routeResolvedFile (router, path, file, appendFileName = true) {
250250

251251
function getQuota (root, serverUri) {
252252
const filename = path.join(root, 'settings/serverSide.ttl')
253+
var quota = Infinity
253254
var prefs
254255
try {
255256
prefs = fs.readFileSync(filename, 'utf8')
@@ -261,19 +262,21 @@ function getQuota (root, serverUri) {
261262
const storageUri = serverUri + '/'
262263
$rdf.parse(prefs, graph, storageUri, 'text/turtle')
263264
const lit = graph.each($rdf.sym(storageUri), ns.solid('storageQuota'), undefined)[0]
264-
var quota = lit.value
265-
const unitUri = 'http://www.w3.invalid/ns#'
266-
// The following should be encoded in the ontology
267-
switch (lit.datatype.value) {
268-
case unitUri + 'kilobyte':
269-
quota *= 1000
270-
break
271-
case unitUri + 'megabyte':
272-
quota *= 1000000
273-
break
274-
case unitUri + 'gigabyte':
275-
quota *= 1000000000
276-
break
265+
if (lit) {
266+
quota = lit.value
267+
const unitUri = 'http://www.w3.invalid/ns#'
268+
// The following should be encoded in the ontology
269+
switch (lit.datatype.value) {
270+
case unitUri + 'kilobyte':
271+
quota *= 1000
272+
break
273+
case unitUri + 'megabyte':
274+
quota *= 1000000
275+
break
276+
case unitUri + 'gigabyte':
277+
quota *= 1000000000
278+
break
279+
}
277280
}
278281
return quota
279282
}

test/integration/quota-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const read = require('../utils').read
55
const root = 'accounts-acl/config/templates/new-account/'
66
// const $rdf = require('rdflib')
77

8-
describe('Quota', function () {
8+
describe('Get Quota', function () {
99
var prefs = read(path.join(root, 'settings/serverSide.ttl'))
1010
it('Check that the file is readable and has predicate', function () {
1111
expect(prefs).to.be.a('string')
@@ -17,4 +17,7 @@ describe('Quota', function () {
1717
it('Get the quota with non-existant file', function () {
1818
expect(getQuota(path.join('nowhere/', root), 'https://localhost')).to.equal(Infinity)
1919
})
20+
it('Get the quota when the predicate is not present', function () {
21+
expect(getQuota('test/resources/accounts-acl/quota', 'https://localhost')).to.equal(Infinity)
22+
})
2023
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@prefix dct: <http://purl.org/dc/terms/>.
2+
@prefix pim: <http://www.w3.org/ns/pim/space#>.
3+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
4+
@prefix unit: <http://www.w3.invalid/ns#>.
5+
6+
<>
7+
a pim:ConfigurationFile;
8+
9+
dct:description "Administrative settings for the server that are only readable to the user." .
10+
11+
# Nothing here...

0 commit comments

Comments
 (0)