Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup hosts for TLS tests
run: |
echo "127.0.0.1 tim.localhost" | sudo tee -a /etc/hosts
echo "127.0.0.1 nicola.localhost" | sudo tee -a /etc/hosts
- run: npm ci
# test code
- run: npm run lint
Expand Down
17 changes: 10 additions & 7 deletions lib/handlers/get.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ export default async function handler (req, res, next) {
let contentRange
let chunksize

if (ret) {
stream = ret.stream
contentType = ret.contentType
container = ret.container
contentRange = ret.contentRange
chunksize = ret.chunksize
}
if (ret) {
stream = ret.stream
contentType = ret.contentType
container = ret.container
contentRange = ret.contentRange
chunksize = ret.chunksize
if (ret.modified) {
res.header('Last-Modified', ret.modified.toUTCString())
}
}

// Till here it must exist
if (!includeBody) {
Expand Down
6 changes: 3 additions & 3 deletions lib/ldp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class LDP {
}

if (!options.includeBody) {
return { stream: stats, contentType, container: stats.isDirectory() }
return { stream: stats, contentType, container: stats.isDirectory(), modified: stats.mtime }
}

if (stats.isDirectory()) {
Expand All @@ -465,7 +465,7 @@ class LDP {
throw err
}
const stream = stringToStream(data)
return { stream, contentType, container: true }
return { stream, contentType, container: true, modified: stats.mtime }
} else {
let chunksize, contentRange, start, end
if (options.range) {
Expand All @@ -487,7 +487,7 @@ class LDP {
})
.on('open', function () {
debug.handlers(`GET -- Reading ${pathLocal}`)
return resolve({ stream, contentType, container: false, contentRange, chunksize })
return resolve({ stream, contentType, container: false, contentRange, chunksize, modified: stats.mtime })
})
}))
}
Expand Down
10 changes: 5 additions & 5 deletions test/integration/acl-tls-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const userCredentials = {
// a webid-tls client certificate can still use their certificate (and not a
// username/password pair or other login method) to "bridge" from webid-tls to
// webid-oidc.
describe.skip('ACL with WebID+TLS', function () {
describe('ACL with WebID+TLS', function () {
let ldpHttpsServer
const serverConfig = {
root: rootPath,
Expand Down Expand Up @@ -131,7 +131,7 @@ describe.skip('ACL with WebID+TLS', function () {
})
})

it.skip('should return a 401 and WWW-Authenticate header without credentials', (done) => {
it('should return a 401 and WWW-Authenticate header without credentials', (done) => {
rm('.acl')
const options = {
url: address + '/acl-tls/no-acl/',
Expand Down Expand Up @@ -568,7 +568,7 @@ describe.skip('ACL with WebID+TLS', function () {
})
})

describe.skip('Glob', function () {
describe('Glob', function () {
it('user2 should be able to send glob request', function (done) {
const options = createOptions(globFile, 'user2')
request.get(options, function (error, response, body) {
Expand Down Expand Up @@ -613,7 +613,7 @@ describe.skip('ACL with WebID+TLS', function () {
done()
})
})
it.skip('user1 should be able to PATCH a resource', function (done) {
it('user1 should be able to PATCH a resource', function (done) {
const options = createOptions('/acl-tls/append-inherited/test.ttl', 'user1')
options.headers = {
'content-type': 'application/sparql-update'
Expand Down Expand Up @@ -943,7 +943,7 @@ describe.skip('ACL with WebID+TLS', function () {
// })
})

describe.skip('Cleanup', function () {
describe('Cleanup', function () {
it('should remove all files and dirs created', function (done) {
try {
// must remove the ACLs in sync
Expand Down
86 changes: 57 additions & 29 deletions test/integration/http-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { assert, expect } from 'chai'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const suffixAcl = '.acl'
const suffixMeta = '.meta'
const server = setupSupertestServer({
const suffixAcl = '.acl'
const suffixMeta = '.meta'
const server = setupSupertestServer({
live: true,
dataBrowserPath: 'default',
root: path.join(__dirname, '../resources'),
Expand Down Expand Up @@ -253,13 +253,20 @@ describe('HTTP APIs', function () {
.expect('content-type', /text\/turtle/)
.expect('Access-Control-Allow-Origin', 'http://example.com')
.expect(200, done)
})
it('should have set Link as resource', function (done) {
server.get('/sampleContainer2/example1.ttl')
.expect('content-type', /text\/turtle/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Resource>; rel="type"/)
.expect(200, done)
})
})
it('should have set Link as resource', function (done) {
server.get('/sampleContainer2/example1.ttl')
.expect('content-type', /text\/turtle/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Resource>; rel="type"/)
.expect(200, done)
})
it('should have set Last-Modified for resource', function (done) {
const modified = fs.statSync(path.join(__dirname,
'../resources/sampleContainer2/example1.ttl')).mtime.toUTCString()
server.get('/sampleContainer2/example1.ttl')
.expect('Last-Modified', modified)
.expect(200, done)
})
it('should have set Updates-Via to use WebSockets', function (done) {
server.get('/sampleContainer2/example1.ttl')
.expect('updates-via', /wss?:\/\//)
Expand All @@ -273,13 +280,20 @@ describe('HTTP APIs', function () {
.expect(hasHeader('describedBy', 'example1.ttl' + suffixMeta))
.end(done)
})
it('should have set Link as Container/BasicContainer', function (done) {
server.get('/sampleContainer2/')
.expect('content-type', /text\/turtle/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#BasicContainer>; rel="type"/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
.expect(200, done)
})
it('should have set Link as Container/BasicContainer', function (done) {
server.get('/sampleContainer2/')
.expect('content-type', /text\/turtle/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#BasicContainer>; rel="type"/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
.expect(200, done)
})
it('should have set Last-Modified for container', function (done) {
const modified = fs.statSync(path.join(__dirname,
'../resources/sampleContainer2')).mtime.toUTCString()
server.get('/sampleContainer2/')
.expect('Last-Modified', modified)
.expect(200, done)
})
it('should load skin (mashlib) if resource was requested as text/html', function (done) {
server.get('/sampleContainer2/example1.ttl')
.set('Accept', 'text/html')
Expand Down Expand Up @@ -505,11 +519,18 @@ describe('HTTP APIs', function () {
.expect('updates-via', /wss?:\/\//)
.expect(200, done)
})
it('should have set Link as Resource', function (done) {
server.head('/sampleContainer2/example1.ttl')
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Resource>; rel="type"/)
.expect(200, done)
})
it('should have set Link as Resource', function (done) {
server.head('/sampleContainer2/example1.ttl')
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Resource>; rel="type"/)
.expect(200, done)
})
it('should have set Last-Modified for resource', function (done) {
const modified = fs.statSync(path.join(__dirname,
'../resources/sampleContainer2/example1.ttl')).mtime.toUTCString()
server.head('/sampleContainer2/example1.ttl')
.expect('Last-Modified', modified)
.expect(200, done)
})
it('should have set acl and describedBy Links for resource',
function (done) {
server.head('/sampleContainer2/example1.ttl')
Expand All @@ -523,13 +544,20 @@ describe('HTTP APIs', function () {
.expect('Content-Type', /text\/turtle/)
.expect(200, done)
})
it('should have set Link as Container/BasicContainer',
function (done) {
server.head('/sampleContainer2/')
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#BasicContainer>; rel="type"/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
.expect(200, done)
})
it('should have set Link as Container/BasicContainer',
function (done) {
server.head('/sampleContainer2/')
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#BasicContainer>; rel="type"/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
.expect(200, done)
})
it('should have set Last-Modified for container', function (done) {
const modified = fs.statSync(path.join(__dirname,
'../resources/sampleContainer2')).mtime.toUTCString()
server.head('/sampleContainer2/')
.expect('Last-Modified', modified)
.expect(200, done)
})
it('should have set acl and describedBy Links for container',
function (done) {
server.head('/sampleContainer2/')
Expand Down