Repository navigation
Simple RDF validation for ACL files - #937
Conversation
| 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')) |
There was a problem hiding this comment.
Wouldn't be a 405 - Method not allowed be more appropriate then?
| } | ||
|
|
||
| mimetypeIsRdf (mimeType) { | ||
| return RDF_MIME_TYPES.indexOf(mimeType) !== -1 |
There was a problem hiding this comment.
Assuming RDF_MIME_TYPES is an Array you can use Array.prototype.includes I guess.
There was a problem hiding this comment.
Better, make RDF_MIME_TYPES a Set.
There was a problem hiding this comment.
Assuming
RDF_MIME_TYPESis 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'), |
There was a problem hiding this comment.
Well, if you want to go cross-platform, path.join(__dirname, '..', 'resources') would make Windows users happy.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') |
| 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')) |
| } | ||
|
|
||
| mimetypeIsRdf (mimeType) { | ||
| return RDF_MIME_TYPES.indexOf(mimeType) !== -1 |
There was a problem hiding this comment.
Better, make RDF_MIME_TYPES a Set.
| var { checkDnsSettings } = require('../utils') | ||
|
|
||
| var ldnode = require('../../index') | ||
| var { checkDnsSettings, setupSupertestServer } = require('../utils') |
| try { | ||
| fs.writeFileSync(filePath, text) | ||
| } catch (err) { | ||
| return callback(error(500, err.message)) |
There was a problem hiding this comment.
You might want to delete whatever was written do disk.
There was a problem hiding this comment.
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?
| putText (host, resourcePath, text, callback) { | ||
| this._put(host, resourcePath, callback, (filePath) => { | ||
| try { | ||
| fs.writeFileSync(filePath, text) |
There was a problem hiding this comment.
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.
|
@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. |
| 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')) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Maybe @RubenVerborgh or @kjetilk can answer this?
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
I'd have split it to path.join(__dirname, '..', 'resources'), but if it works everywhere …
|
I consider the |
But it has been fixed now, hasn't it? Or am I missing something? |
9d51f01 to
d9039a4
Compare
|
I think I've handled all feedback that's been given on this. Anyone up for approving this PR? @kjetilk @RubenVerborgh (or maybe @rubensworks)? |
|
Same rebasing issue here as in #953. Also, should this be targeted to the release branch? |
And make old tests pass
But no actual implementation in patch handler yet
And make old tests pass
But no actual implementation in patch handler yet
And make old tests pass
But no actual implementation in patch handler yet
And make old tests pass
But no actual implementation in patch handler yet
fa84a62 to
d939f7c
Compare
|
I've rebased this branch on |
|
Ok, I'll have a look. |
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.