Skip to content

Simple RDF validation for ACL files - #937

Merged
kjetilk merged 23 commits into
release/v5.0.0from
feature/simple-validation
Nov 28, 2018
Merged

kjetilk merged 23 commits into
release/v5.0.0from
feature/simple-validation

Conversation

@megoth

@megoth megoth commented Nov 15, 2018

Copy link
Copy Markdown
Contributor

This is PR based on the discussions at #882.

Simply explained, when putting ACL files it will parse the files to make the syntax is valid.

I also extracted a couple of utility-functions for integration-tests that I think make the tests a little bit easier to read.

@ghost ghost assigned megoth Nov 15, 2018
@ghost ghost added the in progress label Nov 15, 2018
Comment thread lib/ldp.js Outdated
if (filePath.endsWith('/')) {
return callback(error(409,
'PUT not supported on containers, use POST instead'))
return callback(error(409, 'PUT not supported on containers, use POST instead'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be a 405 - Method not allowed be more appropriate then?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely 405.

Comment thread lib/ldp.js Outdated
}

mimetypeIsRdf (mimeType) {
return RDF_MIME_TYPES.indexOf(mimeType) !== -1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming RDF_MIME_TYPES is an Array you can use Array.prototype.includes I guess.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better, make RDF_MIME_TYPES a Set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming RDF_MIME_TYPES is an Array you can use Array.prototype.includes I guess.

I actually did this initially when I wrote the code, but it failed for me, and I automatically reverted to Array.prototype.indexOf without much more research. My bad.

But yeah, will try making it a Set.

describe('CORS Proxy', () => {
var ldp = ldnode({
var server = setupSupertestServer({
root: path.join(__dirname, '../resources'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you want to go cross-platform, path.join(__dirname, '..', 'resources') would make Windows users happy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you want to go cross-platform, path.join(__dirname, '..', 'resources') would make Windows users happy.

Is it necessary though? It seems like path.join will normalize it nevertheless.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, you made me look at the source code of path.join.

The call to win32.normalize does some … things. So it could be possible that it would normalise it on its own.

var { checkDnsSettings } = require('../utils')

var ldnode = require('../../index')
var { checkDnsSettings, setupSupertestServer } = require('../utils')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a var instead of a const?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency.

Comment thread lib/ldp.js Outdated
if (filePath.endsWith('/')) {
return callback(error(409,
'PUT not supported on containers, use POST instead'))
return callback(error(409, 'PUT not supported on containers, use POST instead'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely 405.

Comment thread lib/ldp.js Outdated
}

mimetypeIsRdf (mimeType) {
return RDF_MIME_TYPES.indexOf(mimeType) !== -1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better, make RDF_MIME_TYPES a Set.

var { checkDnsSettings } = require('../utils')

var ldnode = require('../../index')
var { checkDnsSettings, setupSupertestServer } = require('../utils')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency.

Comment thread lib/ldp.js Outdated
try {
fs.writeFileSync(filePath, text)
} catch (err) {
return callback(error(500, err.message))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to delete whatever was written do disk.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the file existed from before, and we need to recover that file?

If it exists from before, maybe I should do a backup of the content, and roll back if the write failed? Otherwise, I should delete whatever was written to disk?

Comment thread lib/ldp.js Outdated
putText (host, resourcePath, text, callback) {
this._put(host, resourcePath, callback, (filePath) => {
try {
fs.writeFileSync(filePath, text)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async?

@megoth megoth Nov 15, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about the difference of fs.writeFileSync and await util.promisify(fs.writeFile) in general. It seems that there's no difference in blocking IO, and it seems that it doesn't affect the main thread as filesystem operations are handled in worker threads.

It doesn't seem to be that much of a difference, so in this case I think I prefer fs.writeFileSync. But at some point we might want to have a convention on this, so that we stay consistent throughout the code.

@megoth

megoth commented Nov 15, 2018

Copy link
Copy Markdown
Contributor Author

@Ryuno-Ki @RubenVerborgh I've pushed a commit with some changes based on your feedback. I've left out a couple of them, which I've commented.

Comment thread lib/ldp.js Outdated
if (filePath.endsWith('/')) {
return callback(error(409,
'PUT not supported on containers, use POST instead'))
return callback(error(405, 'PUT not supported on containers, use POST instead'))

@Ryuno-Ki Ryuno-Ki Nov 16, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I haven't checked, what error is doing, but from https://tools.ietf.org/html/rfc7231#section-6.5.5 you can read that

The origin server MUST generate an Allow header field in a 405 response containing a list of the target resource's currently supported methods.

So it would be Allow: PUT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @RubenVerborgh or @kjetilk can answer this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into that part of the code, but it sounds reasonable that we need to distinguish between containers and other resources. So far Allow seems to have been added fairly indiscriminatory, but I haven't seen all the code, so I don't know. But it is a different issue, isn't it?

const server = setupSupertestServer({
live: true,
dataBrowserPath: 'default',
root: path.join(__dirname, '../resources'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have split it to path.join(__dirname, '..', 'resources'), but if it works everywhere …

@Ryuno-Ki

Copy link
Copy Markdown

I consider the 405 comment necessary to deal with, but I don't have any roles here ;-)

@megoth

megoth commented Nov 20, 2018 •

Copy link
Copy Markdown
Contributor Author

I consider the 405 comment necessary to deal with, but I don't have any roles here ;-)

But it has been fixed now, hasn't it? Or am I missing something?

@megoth
megoth force-pushed the feature/simple-validation branch from 9d51f01 to d9039a4 Compare November 20, 2018 14:57
@megoth

megoth commented Nov 24, 2018

Copy link
Copy Markdown
Contributor Author

I think I've handled all feedback that's been given on this. Anyone up for approving this PR? @kjetilk @RubenVerborgh (or maybe @rubensworks)?

@megoth
megoth requested a review from rubensworks November 24, 2018 15:56
@rubensworks

Copy link
Copy Markdown
Contributor

Same rebasing issue here as in #953.

Also, should this be targeted to the release branch?

@megoth
megoth force-pushed the feature/simple-validation branch from fa84a62 to d939f7c Compare November 28, 2018 12:29
@megoth
megoth changed the base branch from master to release/v5.0.0 November 28, 2018 12:29
@megoth

megoth commented Nov 28, 2018

Copy link
Copy Markdown
Contributor Author

I've rebased this branch on release/v5.0.0 and think it's ready to be merged. Maybe @rubensworks, @RubenVerborgh or @kjetilk wants to give it a last review to verify that it looks good?

@rubensworks

Copy link
Copy Markdown
Contributor

Ok, I'll have a look.

@rubensworks rubensworks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@kjetilk
kjetilk merged commit 21a41b3 into release/v5.0.0 Nov 28, 2018
@ghost ghost removed the in progress label Nov 28, 2018
@kjetilk
kjetilk deleted the feature/simple-validation branch November 28, 2018 21:37
@megoth megoth mentioned this pull request Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants