Skip to content

fix 1120 1256 from NSS5.1.6 ressource-mapper - #1280

Closed
bourgeoa wants to merge 8 commits into
nodeSolidServer:masterfrom
bourgeoa:master
Closed

fix 1120 1256 from NSS5.1.6 ressource-mapper#1280
bourgeoa wants to merge 8 commits into
nodeSolidServer:masterfrom
bourgeoa:master

Conversation

@bourgeoa

@bourgeoa bourgeoa commented Aug 2, 2019

Copy link
Copy Markdown
Member

@RubenVerborgh @jaxoncreed
fix issues #1120 #1256 from NSS5.1.6 ressource-mapper (should replace PR #1260 )

  • ressource-mapper function mapUrlToFile :
    ( it seems that for some reason using searchIndex = true in function definition mapUrlToFile causes problem. searchIndex is not updated when calling directly mapUrlToFile - but updated if called through an other function like ldp.get or get.js )
    -- createIfNotExists = true : replace isIndex by isFolder (I suppose not needed use of searchIndex = true)
    -- createIfNotExists = false : reorganization of tests around isFolder and isIndex in lieu of searchIndex and isIndex
  • get.js modified along PR Resource-mapper now considers content type when inserting index.html #1260 (use case not clear to me)
  • ldp.js modified to avoid double extension when using slug with extension

Tested on a pod (created with docker) and solid-Ide.

There is a remaining problem : Pod connexion to root needs login (?? something with allow.js)

@RubenVerborgh RubenVerborgh 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.

Thanks, the main idea of the fix looks good (distinguishing between isFolder and searchIndex).
Still needs unit tests though on the ResourceMapper side.

Comment thread lib/resource-mapper.js Outdated
/*
* A ResourceMapper maintains the mapping between HTTP URLs and server filenames,
* following the principles of the “sweet spot discussed in
* following the principles of the “sweet spot discussed in

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.

encoding issue

Comment thread lib/resource-mapper.js Outdated
throw new Error('Disallowed /.. segment in URL')
}
let isIndex = searchIndex && filePath.endsWith('/')
let isFolder = filePath.endsWith('/')

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.

Is this actually an assumption we can make? Or should it be passed in explicitly as a parameter?

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.

const?

Comment thread lib/resource-mapper.js Outdated
if (match === undefined) {throw new HTTPError(404, `Resource not found: ${pathname}`)}

// Check if the index file exists
} else if (isIndex && files.includes(this._indexFilename)) {

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.

isIndex should be searchIndex here

Comment thread lib/resource-mapper.js Outdated
}
let isIndex = searchIndex && filePath.endsWith('/')
let isFolder = filePath.endsWith('/')
let isIndex = searchIndex && isFolder

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.

I think this variable can be dropped (as per my comment below).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not being a coder. I need help.

  • L127 OK searchIndex and drop of isIndex in L95

  • L94 do you want to replace isFolder by filePath.endsWith('/') everywhere it's used or to use an other variable name or to pass a parameter (this test was already used)
    (The code allready used the endsWith('/') I would like to avoid at this stage to add a new parameter and push a test on all mapUrlToFile calls)

  • I suppose I have to modify the tests that errored N°5 and 6 in travis due to my modifications. It may relates to explicitely set searchIndex value to true.

How can I send my modifications : as a new PR or something else (I have never done it)
Sorry for my deeply need of help

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.

Not being a coder.

This is good stuff though 👍

L94, okay, leave as is.

How can I send my modifications

You just push another commit to the branch you have created. So just keep pushing to your own master branch, and they will end up here. Don't hesitate to ask if you're uncertain, happy to explain!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ressource-mapper tests
I have a problem with that test :

itMapsUrl(mapper, 'a URL ending with a slash to a folder when index is skipped',
  {
    url: 'http://localhost/space/',
    contentType: 'application/octet-stream',
    createIfNotExists: true,
    searchIndex: false
  },
  {
    path: `${rootPath}space/`,
    contentType: 'application/octet-stream'
  })

Is it a use case ?
It creates a folder with contentType.
In all tests cases it is the only case where a folder is created. I missed this behaviour.
If yes I need to slightly modify my code and I did not found where it is used (PUT, PATCH, POST)

Can you confirm.

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.

Is tthere no code calling it with createIfNotExists: true and searchIndex: false? Because this code might be used to create a folder.

@bourgeoa

bourgeoa commented Aug 3, 2019

Copy link
Copy Markdown
Member Author

fix finally Ok and tested on pod with docker and in using solid-ide.

The tests cases where a bit complex to elaborate. I tried to make them clean enough to understand. I reintroduced isIndex to make it clearer. I can suppress it if you prefer as it is only used once

  • all ressource-mapper tests passed.
  • And finally podroot opens normally on podroot/index.html as expected
    Do I have to do something for the other integration tests that failed ?

nota : I checked with notepad++ and I confirm that there is no code calling createIfNotExists : true and searchIndex: false

@bourgeoa
bourgeoa marked this pull request as ready for review August 3, 2019 20:54

@RubenVerborgh RubenVerborgh 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.

Minor comments; tests are still failing though, seems like test changes were not incorporated.

Comment thread lib/resource-mapper.js Outdated
// create a new folder
if (!searchIndex && isFolder) {
// else create a new file
} else {

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.

if statement with empty body is to be avoided

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I shall replace with

if ((!searchIndex && isFolder) === false) {

What shall I do with the tests ? Are the errors related to the fix ?

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.

Or just if (searchIndex !! !isFolder).

Tests are indeed related; some behavior is changed, so should be updated. I think the behavior is correct though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I suppose you meant if (searchIndex || !isFolder) which do not cover searchIndex: false and isFolder: false which would allow to create a file without contentType control or read without check it exists.

I think there are missing tests that should cover the case :

 itMapsUrl(mapper, "a URL with a bogus extension that doesn't match the content type",
  {
    url: 'http://localhost/space/foo.ttl',
    contentType: 'text/html',
    createIfNotExists: true,
    searchIndex: false
  },
  {
    path: `${rootPath}space/foo.ttl$.html`,
    contentType: 'text/html'
  })

and cases without createIfNotExists.

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.

I suppose you meant if (searchIndex || !isFolder)

No, I meant that if ((!searchIndex && isFolder) === false) { is written more simply as if (searchIndex || !isFolder).

Case looks good.

Comment thread lib/resource-mapper.js Outdated
@bourgeoa

bourgeoa commented Aug 4, 2019

Copy link
Copy Markdown
Member Author

requested changes made.
fails tests relates to ACL timeout, all other tests passed on node 8.

@RubenVerborgh

Copy link
Copy Markdown
Contributor

But are the timeouts causes by the changes, or where they present before?

@bourgeoa

bourgeoa commented Aug 5, 2019

Copy link
Copy Markdown
Member Author

I close the pull request to begin a new one to check travis at every step
I think I bugged something

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.

2 participants